/
bubble.js
85 lines (72 loc) · 4.14 KB
/
bubble.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright: 2015 AlignAlytics
// License: "https://github.com/PMSI-AlignAlytics/dimple/blob/master/MIT-LICENSE.txt"
// Source: /src/objects/plot/bubble.js
dimple.plot.bubble = {
// By default the bubble values are not stacked
stacked: false,
// This is not a grouped plot meaning that one point is treated as one series value
grouped: false,
// The axis positions affecting the bubble series
supportedAxes: ["x", "y", "z", "c"],
// Draw the axis
draw: function (chart, series, duration) {
var chartData = series._positionData,
theseShapes = null,
classes = ["dimple-series-" + chart.series.indexOf(series), "dimple-bubble"],
entered,
updated,
removed;
if (chart._tooltipGroup) {
chart._tooltipGroup.remove();
}
if (!series.shapes) {
theseShapes = series._group.selectAll("." + classes.join(".")).data(chartData, function (d) { return d.key; });
} else {
theseShapes = series.shapes.data(chartData, function (d) { return d.key; });
}
// Add
entered = theseShapes
.enter()
.append("circle")
.attr("id", function (d) { return dimple._createClass([d.key]); })
.attr("class", function (d) {
var c = [];
c = c.concat(d.aggField);
c = c.concat(d.xField);
c = c.concat(d.yField);
c = c.concat(d.zField);
return classes.join(" ") + " " + dimple._createClass(c) + " " + chart.customClassList.bubbleSeries + " " + dimple._helpers.css(d, chart);
})
.attr("cx", function (d) { return (series.x._hasCategories() ? dimple._helpers.cx(d, chart, series) : series.x._previousOrigin); })
.attr("cy", function (d) { return (series.y._hasCategories() ? dimple._helpers.cy(d, chart, series) : series.y._previousOrigin); })
.attr("r", 0)
.on("mouseover", function (e) { dimple._showPointTooltip(e, this, chart, series); })
.on("mouseleave", function (e) { dimple._removeTooltip(e, this, chart, series); })
.call(function (context) {
if (!chart.noFormats) {
context.attr("opacity", function (d) { return dimple._helpers.opacity(d, chart, series); })
.style("fill", function (d) { return dimple._helpers.fill(d, chart, series); })
.style("stroke", function (d) { return dimple._helpers.stroke(d, chart, series); });
}
});
// Update
updated = chart._handleTransition(theseShapes.merge(entered), duration, chart, series)
.attr("cx", function (d) { return dimple._helpers.cx(d, chart, series); })
.attr("cy", function (d) { return dimple._helpers.cy(d, chart, series); })
.attr("r", function (d) { return dimple._helpers.r(d, chart, series); })
.call(function (context) {
if (!chart.noFormats) {
context.attr("fill", function (d) { return dimple._helpers.fill(d, chart, series); })
.attr("stroke", function (d) { return dimple._helpers.stroke(d, chart, series); });
}
});
// Remove
removed = chart._handleTransition(theseShapes.exit(), duration, chart, series)
.attr("r", 0)
.attr("cx", function (d) { return (series.x._hasCategories() ? dimple._helpers.cx(d, chart, series) : series.x._origin); })
.attr("cy", function (d) { return (series.y._hasCategories() ? dimple._helpers.cy(d, chart, series) : series.y._origin); });
dimple._postDrawHandling(series, updated, removed, duration);
// Save the shapes to the series array
series.shapes = series._group.selectAll("." + classes.join("."));
}
};