Commits

Simon Cross  committed dc28a07

Add wonky plot_update for fires.

  • Participants
  • Parent commits d175549

Comments (0)

Files changed (1)

File lib/stats.js

             var plot = distri.plots.all[$select.val()];
             plot.init({
                 chart: chart,
+                svg: svg,
                 coeffs: opts.coeffs,
                 chart_title: opts.chart_title,
                 chart_footer: opts.chart_footer,
         var self = this;
 
         self.chart = null;
+        self.svg = null;
         self.$coeffs = null;
         self.coeffs = [];
 
         self.footer = opts.footer || "";
         self.setup_chart = opts.setup_chart;
         self.setup_coeffs = opts.setup_coeffs;
-        self.update_chart = opts.update_chart || _.noop;
+        self.update_plot = opts.update_plot || _.noop;
         self.data = opts.data;
 
         all[name] = self;
 
         self.init = function(opts) {
             self.chart = opts.chart;
+            self.svg = opts.svg;
             self.setup_chart_title(opts.chart_title);
             self.setup_chart_footer(opts.chart_footer);
             self.setup_chart(self.chart);
             var args = _.map(self.coeffs, self.update_coeff);
             self.chart.data = self.data.apply(self, args);
             self.chart.draw();
-            self.update_chart(self.chart);
+            self.update_plot(self);
         };
     }
 
                     stack: 4,
                 },
             ];
-        }
+        },
+        update_plot: function(plot) {
+            var svg = plot.svg;
+            var chart = plot.chart;
+            var series = chart.series[0];
+            var x = chart.axes[0];
+            var y = chart.axes[1];
+
+            series.shapes.each(function(d) {
+                var shape = d3.select(this);
+                var content = d.aggField[0];
+
+                var height = 100; //50; //50 - shape.attr("height");
+                var width = shape.attr("width");
+
+                console.log("H:" + height);
+                console.log("Y:" + shape.attr("y"));
+
+                if (height >= 8) {
+                    svg.append("text")
+                        // position centre
+                        .attr("x", parseFloat(shape.attr("x")) + width * 0.9)
+                        .attr("y", parseFloat(shape.attr("y")) - height)
+                        //.attr('transform', "translate(" + x + "," + y + ")")
+                        // centre align
+                        .style("text-anchor", "left")
+                        .style("font-size", "1.5em")
+                        // set the text
+                        .text(content);
+                }
+            });
+        },
     });
 })();