Commits

Simon Cross committed 4b63068

More plots.

Comments (0)

Files changed (1)

         };
     }
 
+    function add_labels(plot, content_func) {
+        d3.selectAll(".plot-text-label").remove();
+
+        var svg = plot.svg;
+        var chart = plot.chart;
+        var series = chart.series[0];
+        var x = chart.axes[0];
+        var y = chart.axes[1];
+        var total = 0.0;
+
+        series.shapes.each(function(d) {
+            var shape = d3.select(this);
+            var content = content_func(d);
+
+            // calculate y from first principles because
+            // shape.attr("y") and shape.attr("height") are screwed :)
+            var full_height = y._scale(0.0) - y._scale(1.0);
+            var height = d.yValue * full_height;
+            total = total + d.yValue;
+            var shape_y = y._scale(total);
+
+            var width = parseFloat(shape.attr("width"));
+
+            if (d.yValue <= 0.07) {
+                console.log("Skipping " + content);
+                return;
+            }
+
+            svg.append("text")
+                .attr("class", "plot-text-label")
+            // position centre
+                .attr("x", parseFloat(shape.attr("x")) + (width * 1.1))
+                .attr("y", shape_y + (height * 0.5))
+            // centre align
+                .style("text-anchor", "left")
+                .style("font-size", "1.5em")
+            // set the text
+                .text(content);
+        });
+    }
+
     exports.Plot = Plot;
+    exports.add_labels = add_labels;
     exports.all = all;
 
 })(distri.plots = {});
             ];
         },
         update_plot: function(plot) {
-            d3.selectAll(".fire-plot-text").remove();
-
-            var svg = plot.svg;
-            var chart = plot.chart;
-            var series = chart.series[0];
-            var x = chart.axes[0];
-            var y = chart.axes[1];
-            var total = 0.0;
-
-            series.shapes.each(function(d) {
-                var shape = d3.select(this);
-                var content = d.aggField[0];
-
-                // calculate y from first principles because
-                // shape.attr("y") and shape.attr("height") are screwed :)
-                var full_height = y._scale(0.0) - y._scale(1.0);
-                var height = d.yValue * full_height;
-                total = total + d.yValue;
-                var shape_y = y._scale(total);
-
-                var width = parseFloat(shape.attr("width"));
-
-                if (d.yValue <= 0.07) {
-                    console.log("Skipping " + content);
-                    return;
-                }
-
-                svg.append("text")
-                    .attr("class", "fire-plot-text")
-                    // position centre
-                    .attr("x", parseFloat(shape.attr("x")) + (width * 1.1))
-                    .attr("y", shape_y + (height * 0.5))
-                    // centre align
-                    .style("text-anchor", "left")
-                    .style("font-size", "1.5em")
-                    // set the text
-                    .text(content);
+            distri.plots.add_labels(plot, function(d) {
+                return d.aggField[0];
             });
         },
     });
+})();
+
+// plot: 80/20 plot
+
+(function() {
+    new distri.plots.Plot("eighty_twenty", {
+        title: "80 / 20",
+        footer: 'From personal scribblings.',
+        setup_chart: function(chart) {
+            var x = chart.addCategoryAxis("x", "team");
+            var y = chart.addMeasureAxis("y", "percent");
+            y.addOrderRule("stack");
+            y.overrideMax = 1.0;
+            y.overrideMin = 0.0;
+            var s = chart.addSeries(["name"], dimple.plot.bar);
+            s.barGap = 0.8;
+            s.addOrderRule("stack", true);
+
+            chart.assignColor("eighty", "#aaaaff", "#000000");
+            chart.assignColor("twenty", "#ffffff", "#000000");
+        },
+        setup_coeffs: function(plot) {
+        },
+        data: function(r, p, f) {
+            return [
+                {
+                    name: "eighty", percent: 0.8, team: "A-team",
+                    stack: 2,
+                },
+                {
+                    name: "twenty", percent: 0.2, team: "A-team",
+                    stack: 1,
+                },
+            ];
+        },
+        update_plot: function(plot) {
+            distri.plots.add_labels(plot, function(d) {
+                return d3.format(",.0f")(d.yValue * 100) + "%";
+            });
+        },
+    });
+})();
+
+
+// plot: task queue plot
+
+(function() {
+    new distri.plots.Plot("tasks", {
+        title: "Task queue",
+        footer: 'From personal scribblings.',
+        setup_chart: function(chart) {
+            var x = chart.addCategoryAxis("x", "time");
+            x.overrideMax = 10.0;
+            x.overrideMin = 0.0;
+            var y = chart.addMeasureAxis("y", "size");
+            y.overrideMax = 6.0;
+            y.overrideMin = 0.0;
+            var s = chart.addSeries(null, dimple.plot.bar);
+            s.barGap = 0;
+        },
+        setup_coeffs: function(plot) {
+        },
+        data: function(r, p, f) {
+            return [
+                {
+                    task: "task-1", time: 2, size: 2,
+                },
+                {
+                    task: "task-2", time: 5, size: 4,
+                },
+                {
+                    task: "task-3", time: 7, size: 1,
+                },
+            ];
+        },
+        update_plot: function(plot) {
+        },
+    });
 })();