nvd3-rails 0.0.1 → 0.0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +3 -0
- data/README.md +7 -71
- data/lib/nvd3/rails/version.rb +1 -1
- data/nvd3-rails.gemspec +3 -3
- metadata +8 -111
- data/vendor/assets/javascripts/nvd3/.git.sample/HEAD +0 -1
- data/vendor/assets/javascripts/nvd3/.git.sample/config +0 -13
- data/vendor/assets/javascripts/nvd3/.git.sample/description +0 -1
- data/vendor/assets/javascripts/nvd3/.git.sample/hooks/applypatch-msg.sample +0 -15
- data/vendor/assets/javascripts/nvd3/.git.sample/hooks/commit-msg.sample +0 -24
- data/vendor/assets/javascripts/nvd3/.git.sample/hooks/post-update.sample +0 -8
- data/vendor/assets/javascripts/nvd3/.git.sample/hooks/pre-applypatch.sample +0 -14
- data/vendor/assets/javascripts/nvd3/.git.sample/hooks/pre-commit.sample +0 -50
- data/vendor/assets/javascripts/nvd3/.git.sample/hooks/pre-push.sample +0 -53
- data/vendor/assets/javascripts/nvd3/.git.sample/hooks/pre-rebase.sample +0 -169
- data/vendor/assets/javascripts/nvd3/.git.sample/hooks/prepare-commit-msg.sample +0 -36
- data/vendor/assets/javascripts/nvd3/.git.sample/hooks/update.sample +0 -128
- data/vendor/assets/javascripts/nvd3/.git.sample/index +0 -0
- data/vendor/assets/javascripts/nvd3/.git.sample/info/exclude +0 -6
- data/vendor/assets/javascripts/nvd3/.git.sample/logs/HEAD +0 -1
- data/vendor/assets/javascripts/nvd3/.git.sample/logs/refs/heads/master +0 -1
- data/vendor/assets/javascripts/nvd3/.git.sample/logs/refs/remotes/origin/HEAD +0 -1
- data/vendor/assets/javascripts/nvd3/.git.sample/objects/pack/pack-babbb312d58dd7f03870b530a1b9a84c80918be3.idx +0 -0
- data/vendor/assets/javascripts/nvd3/.git.sample/objects/pack/pack-babbb312d58dd7f03870b530a1b9a84c80918be3.pack +0 -0
- data/vendor/assets/javascripts/nvd3/.git.sample/packed-refs +0 -5
- data/vendor/assets/javascripts/nvd3/.git.sample/refs/heads/master +0 -1
- data/vendor/assets/javascripts/nvd3/.git.sample/refs/remotes/origin/HEAD +0 -1
- data/vendor/assets/javascripts/nvd3/build.bat +0 -6
- data/vendor/assets/javascripts/nvd3/deprecated/bar.html +0 -198
- data/vendor/assets/javascripts/nvd3/deprecated/bar.js +0 -250
- data/vendor/assets/javascripts/nvd3/deprecated/charts/cumulativeLineChart.js +0 -174
- data/vendor/assets/javascripts/nvd3/deprecated/charts/discreteBarChart.js +0 -157
- data/vendor/assets/javascripts/nvd3/deprecated/charts/lineChart.js +0 -159
- data/vendor/assets/javascripts/nvd3/deprecated/charts/lineChartDaily.js +0 -168
- data/vendor/assets/javascripts/nvd3/deprecated/charts/stackedAreaChart.js +0 -177
- data/vendor/assets/javascripts/nvd3/deprecated/cumulativeLine.html +0 -171
- data/vendor/assets/javascripts/nvd3/deprecated/cumulativeLine.js +0 -334
- data/vendor/assets/javascripts/nvd3/deprecated/discreteBarChartWithEnabledTooltip.html +0 -129
- data/vendor/assets/javascripts/nvd3/deprecated/discreteBarChartWithEnabledTooltip.js +0 -222
- data/vendor/assets/javascripts/nvd3/deprecated/discreteBarWithAxes.html +0 -172
- data/vendor/assets/javascripts/nvd3/deprecated/discreteBarWithAxes.js +0 -152
- data/vendor/assets/javascripts/nvd3/deprecated/lineChart-old.html +0 -83
- data/vendor/assets/javascripts/nvd3/deprecated/lineChartDaily.html +0 -109
- data/vendor/assets/javascripts/nvd3/deprecated/linePlusBar.html +0 -173
- data/vendor/assets/javascripts/nvd3/deprecated/linePlusBar.js +0 -250
- data/vendor/assets/javascripts/nvd3/deprecated/lineWithFocus.html +0 -137
- data/vendor/assets/javascripts/nvd3/deprecated/lineWithFocus.js +0 -354
- data/vendor/assets/javascripts/nvd3/deprecated/lineWithFourAxes.html +0 -144
- data/vendor/assets/javascripts/nvd3/deprecated/lineWithFourAxes.js +0 -218
- data/vendor/assets/javascripts/nvd3/deprecated/lineWithLegend.html +0 -142
- data/vendor/assets/javascripts/nvd3/deprecated/lineWithLegend.js +0 -176
- data/vendor/assets/javascripts/nvd3/deprecated/monthendAxis.html +0 -99
- data/vendor/assets/javascripts/nvd3/deprecated/multiBarHorizontalWithLegend.html +0 -258
- data/vendor/assets/javascripts/nvd3/deprecated/multiBarHorizontalWithLegend.js +0 -226
- data/vendor/assets/javascripts/nvd3/deprecated/multiBarWithLegend.html +0 -162
- data/vendor/assets/javascripts/nvd3/deprecated/multiBarWithLegend.js +0 -249
- data/vendor/assets/javascripts/nvd3/deprecated/pie.js +0 -263
- data/vendor/assets/javascripts/nvd3/deprecated/scatterChart.html +0 -110
- data/vendor/assets/javascripts/nvd3/deprecated/scatterChart.js +0 -294
- data/vendor/assets/javascripts/nvd3/deprecated/scatterFisheyeChart.js +0 -418
- data/vendor/assets/javascripts/nvd3/deprecated/scatterWithLegend.html +0 -167
- data/vendor/assets/javascripts/nvd3/deprecated/scatterWithLegend.js +0 -261
- data/vendor/assets/javascripts/nvd3/deprecated/stackedArea.js +0 -286
- data/vendor/assets/javascripts/nvd3/deprecated/stackedAreaChart.html +0 -183
- data/vendor/assets/javascripts/nvd3/deprecated/stackedAreaChart_old.html +0 -137
- data/vendor/assets/javascripts/nvd3/deprecated/stackedAreaWithLegend.html +0 -222
- data/vendor/assets/javascripts/nvd3/deprecated/stackedAreaWithLegend.js +0 -297
- data/vendor/assets/javascripts/nvd3/examples/bullet.html +0 -96
- data/vendor/assets/javascripts/nvd3/examples/bulletChart.html +0 -94
- data/vendor/assets/javascripts/nvd3/examples/crossfilter.html +0 -167
- data/vendor/assets/javascripts/nvd3/examples/crossfilterWithDimentions.html +0 -180
- data/vendor/assets/javascripts/nvd3/examples/crossfilterWithTables.html +0 -288
- data/vendor/assets/javascripts/nvd3/examples/cumulativeLineChart.html +0 -155
- data/vendor/assets/javascripts/nvd3/examples/discreteBarChart.html +0 -116
- data/vendor/assets/javascripts/nvd3/examples/dynamicTimeSeries.html +0 -148
- data/vendor/assets/javascripts/nvd3/examples/historicalBar.html +0 -157
- data/vendor/assets/javascripts/nvd3/examples/horizon.html +0 -163
- data/vendor/assets/javascripts/nvd3/examples/images/grey-minus.png +0 -0
- data/vendor/assets/javascripts/nvd3/examples/images/grey-plus.png +0 -0
- data/vendor/assets/javascripts/nvd3/examples/indentedtree.html +0 -126
- data/vendor/assets/javascripts/nvd3/examples/legend.html +0 -75
- data/vendor/assets/javascripts/nvd3/examples/line.html +0 -95
- data/vendor/assets/javascripts/nvd3/examples/lineChart.html +0 -112
- data/vendor/assets/javascripts/nvd3/examples/lineChartSVGResize.html +0 -151
- data/vendor/assets/javascripts/nvd3/examples/linePlusBarChart.html +0 -114
- data/vendor/assets/javascripts/nvd3/examples/linePlusBarWithFocusChart.html +0 -128
- data/vendor/assets/javascripts/nvd3/examples/lineTimeSeries.html +0 -142
- data/vendor/assets/javascripts/nvd3/examples/lineWithFisheyeChart.html +0 -101
- data/vendor/assets/javascripts/nvd3/examples/lineWithFocusChart.html +0 -87
- data/vendor/assets/javascripts/nvd3/examples/multiBar.html +0 -92
- data/vendor/assets/javascripts/nvd3/examples/multiBarChart.html +0 -93
- data/vendor/assets/javascripts/nvd3/examples/multiBarHorizontalChart.html +0 -388
- data/vendor/assets/javascripts/nvd3/examples/multiChart.html +0 -93
- data/vendor/assets/javascripts/nvd3/examples/nations.json +0 -1
- data/vendor/assets/javascripts/nvd3/examples/pie.html +0 -93
- data/vendor/assets/javascripts/nvd3/examples/pieChart.html +0 -114
- data/vendor/assets/javascripts/nvd3/examples/scatter.html +0 -95
- data/vendor/assets/javascripts/nvd3/examples/scatterChart.html +0 -115
- data/vendor/assets/javascripts/nvd3/examples/scatterPlusLineChart.html +0 -116
- data/vendor/assets/javascripts/nvd3/examples/sparkline.html +0 -62
- data/vendor/assets/javascripts/nvd3/examples/sparklinePlus.html +0 -67
- data/vendor/assets/javascripts/nvd3/examples/stackedArea.html +0 -155
- data/vendor/assets/javascripts/nvd3/examples/stackedAreaChart.html +0 -245
- data/vendor/assets/javascripts/nvd3/examples/stream_layers.js +0 -35
- data/vendor/assets/javascripts/nvd3/src/models/backup/bullet.js +0 -250
- data/vendor/assets/javascripts/nvd3/src/models/backup/bulletChart.js +0 -349
@@ -1,35 +0,0 @@
|
|
1
|
-
|
2
|
-
/* Inspired by Lee Byron's test data generator. */
|
3
|
-
function stream_layers(n, m, o) {
|
4
|
-
if (arguments.length < 3) o = 0;
|
5
|
-
function bump(a) {
|
6
|
-
var x = 1 / (.1 + Math.random()),
|
7
|
-
y = 2 * Math.random() - .5,
|
8
|
-
z = 10 / (.1 + Math.random());
|
9
|
-
for (var i = 0; i < m; i++) {
|
10
|
-
var w = (i / m - y) * z;
|
11
|
-
a[i] += x * Math.exp(-w * w);
|
12
|
-
}
|
13
|
-
}
|
14
|
-
return d3.range(n).map(function() {
|
15
|
-
var a = [], i;
|
16
|
-
for (i = 0; i < m; i++) a[i] = o + o * Math.random();
|
17
|
-
for (i = 0; i < 5; i++) bump(a);
|
18
|
-
return a.map(stream_index);
|
19
|
-
});
|
20
|
-
}
|
21
|
-
|
22
|
-
/* Another layer generator using gamma distributions. */
|
23
|
-
function stream_waves(n, m) {
|
24
|
-
return d3.range(n).map(function(i) {
|
25
|
-
return d3.range(m).map(function(j) {
|
26
|
-
var x = 20 * j / m - i / 3;
|
27
|
-
return 2 * x * Math.exp(-.5 * x);
|
28
|
-
}).map(stream_index);
|
29
|
-
});
|
30
|
-
}
|
31
|
-
|
32
|
-
function stream_index(d, i) {
|
33
|
-
return {x: i, y: Math.max(0, d)};
|
34
|
-
}
|
35
|
-
|
@@ -1,250 +0,0 @@
|
|
1
|
-
|
2
|
-
// Chart design based on the recommendations of Stephen Few. Implementation
|
3
|
-
// based on the work of Clint Ivy, Jamie Love, and Jason Davies.
|
4
|
-
// http://projects.instantcognition.com/protovis/bulletchart/
|
5
|
-
|
6
|
-
nv.models.bullet = function() {
|
7
|
-
|
8
|
-
//============================================================
|
9
|
-
// Public Variables with Default Settings
|
10
|
-
//------------------------------------------------------------
|
11
|
-
|
12
|
-
var margin = {top: 0, right: 0, bottom: 0, left: 0}
|
13
|
-
, orient = 'left' // TODO top & bottom
|
14
|
-
, reverse = false
|
15
|
-
, ranges = function(d) { return d.ranges }
|
16
|
-
, markers = function(d) { return d.markers }
|
17
|
-
, measures = function(d) { return d.measures }
|
18
|
-
, forceX = [0] // List of numbers to Force into the X scale (ie. 0, or a max / min, etc.)
|
19
|
-
, width = 380
|
20
|
-
, height = 30
|
21
|
-
, tickFormat = null
|
22
|
-
, dispatch = d3.dispatch('elementMouseover', 'elementMouseout')
|
23
|
-
;
|
24
|
-
|
25
|
-
//============================================================
|
26
|
-
|
27
|
-
|
28
|
-
function chart(selection) {
|
29
|
-
selection.each(function(d, i) {
|
30
|
-
var availableWidth = width - margin.left - margin.right,
|
31
|
-
availableHeight = height - margin.top - margin.bottom,
|
32
|
-
container = d3.select(this),
|
33
|
-
mainGroup = nv.log(this.parentNode.parentNode).getAttribute('transform'),
|
34
|
-
heightFromTop = nv.log(parseInt(mainGroup.replace(/.*,(\d+)\)/,"$1"))); //TODO: There should be a smarter way to get this value
|
35
|
-
|
36
|
-
var rangez = ranges.call(this, d, i).slice().sort(d3.descending),
|
37
|
-
markerz = markers.call(this, d, i).slice().sort(d3.descending),
|
38
|
-
measurez = measures.call(this, d, i).slice().sort(d3.descending);
|
39
|
-
|
40
|
-
|
41
|
-
//------------------------------------------------------------
|
42
|
-
// Setup Scales
|
43
|
-
|
44
|
-
// Compute the new x-scale.
|
45
|
-
var MaxX = Math.max(rangez[0] ? rangez[0]:0 , markerz[0] ? markerz[0] : 0 , measurez[0] ? measurez[0] : 0)
|
46
|
-
var x1 = d3.scale.linear()
|
47
|
-
.domain([0, MaxX]).nice() // TODO: need to allow forceX and forceY, and xDomain, yDomain
|
48
|
-
.range(reverse ? [availableWidth, 0] : [0, availableWidth]);
|
49
|
-
|
50
|
-
// Retrieve the old x-scale, if this is an update.
|
51
|
-
var x0 = this.__chart__ || d3.scale.linear()
|
52
|
-
.domain([0, Infinity])
|
53
|
-
.range(x1.range());
|
54
|
-
|
55
|
-
// Stash the new scale.
|
56
|
-
this.__chart__ = x1;
|
57
|
-
|
58
|
-
//------------------------------------------------------------
|
59
|
-
|
60
|
-
|
61
|
-
//------------------------------------------------------------
|
62
|
-
// Setup containers and skeleton of chart
|
63
|
-
|
64
|
-
var wrap = container.selectAll('g.nv-wrap.nv-bullet').data([d]);
|
65
|
-
var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-bullet');
|
66
|
-
var gEnter = wrapEnter.append('g');
|
67
|
-
var g = wrap.select('g');
|
68
|
-
|
69
|
-
wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
|
70
|
-
|
71
|
-
//------------------------------------------------------------
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
var w0 = function(d) { return Math.abs(x0(d) - x0(0)) }, // TODO: could optimize by precalculating x0(0) and x1(0)
|
76
|
-
w1 = function(d) { return Math.abs(x1(d) - x1(0)) };
|
77
|
-
|
78
|
-
|
79
|
-
// Update the range rects.
|
80
|
-
var range = g.selectAll('rect.nv-range')
|
81
|
-
.data(rangez);
|
82
|
-
|
83
|
-
range.enter().append('rect')
|
84
|
-
.attr('class', function(d, i) { return 'nv-range nv-s' + i; })
|
85
|
-
.attr('width', w0)
|
86
|
-
.attr('height', availableHeight)
|
87
|
-
.attr('x', reverse ? x0 : 0)
|
88
|
-
.on('mouseover', function(d,i) {
|
89
|
-
dispatch.elementMouseover({
|
90
|
-
value: d,
|
91
|
-
label: (i <= 0) ? 'Maximum' : (i > 1) ? 'Minimum' : 'Mean', //TODO: make these labels a variable
|
92
|
-
pos: [x1(d), heightFromTop]
|
93
|
-
})
|
94
|
-
})
|
95
|
-
.on('mouseout', function(d,i) {
|
96
|
-
dispatch.elementMouseout({
|
97
|
-
value: d,
|
98
|
-
label: (i <= 0) ? 'Minimum' : (i >=1) ? 'Maximum' : 'Mean' //TODO: make these labels a variable
|
99
|
-
})
|
100
|
-
})
|
101
|
-
|
102
|
-
d3.transition(range)
|
103
|
-
.attr('x', reverse ? x1 : 0)
|
104
|
-
.attr('width', w1)
|
105
|
-
.attr('height', availableHeight);
|
106
|
-
|
107
|
-
|
108
|
-
// Update the measure rects.
|
109
|
-
var measure = g.selectAll('rect.nv-measure')
|
110
|
-
.data(measurez);
|
111
|
-
|
112
|
-
measure.enter().append('rect')
|
113
|
-
.attr('class', function(d, i) { return 'nv-measure nv-s' + i; })
|
114
|
-
.attr('width', w0)
|
115
|
-
.attr('height', availableHeight / 3)
|
116
|
-
.attr('x', reverse ? x0 : 0)
|
117
|
-
.attr('y', availableHeight / 3)
|
118
|
-
.on('mouseover', function(d) {
|
119
|
-
dispatch.elementMouseover({
|
120
|
-
value: d,
|
121
|
-
label: 'Current', //TODO: make these labels a variable
|
122
|
-
pos: [x1(d), heightFromTop]
|
123
|
-
})
|
124
|
-
})
|
125
|
-
.on('mouseout', function(d) {
|
126
|
-
dispatch.elementMouseout({
|
127
|
-
value: d,
|
128
|
-
label: 'Current' //TODO: make these labels a variable
|
129
|
-
})
|
130
|
-
})
|
131
|
-
|
132
|
-
d3.transition(measure)
|
133
|
-
.attr('width', w1)
|
134
|
-
.attr('height', availableHeight / 3)
|
135
|
-
.attr('x', reverse ? x1 : 0)
|
136
|
-
.attr('y', availableHeight / 3);
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
// Update the marker lines.
|
141
|
-
var marker = g.selectAll('path.nv-markerTriangle')
|
142
|
-
.data(markerz);
|
143
|
-
|
144
|
-
var h3 = availableHeight / 6;
|
145
|
-
marker.enter().append('path')
|
146
|
-
.attr('class', 'nv-markerTriangle')
|
147
|
-
.attr('transform', function(d) { return 'translate(' + x0(d) + ',' + (availableHeight / 2) + ')' })
|
148
|
-
.attr('d', 'M0,' + h3 + 'L' + h3 + ',' + (-h3) + ' ' + (-h3) + ',' + (-h3) + 'Z')
|
149
|
-
.on('mouseover', function(d,i) {
|
150
|
-
dispatch.elementMouseover({
|
151
|
-
value: d,
|
152
|
-
label: 'Previous',
|
153
|
-
pos: [x1(d), heightFromTop]
|
154
|
-
})
|
155
|
-
})
|
156
|
-
.on('mouseout', function(d,i) {
|
157
|
-
dispatch.elementMouseout({
|
158
|
-
value: d,
|
159
|
-
label: 'Previous'
|
160
|
-
})
|
161
|
-
});
|
162
|
-
|
163
|
-
d3.transition(marker)
|
164
|
-
.attr('transform', function(d) { return 'translate(' + x1(d) + ',' + (availableHeight / 2) + ')' });
|
165
|
-
|
166
|
-
marker.exit().remove();
|
167
|
-
|
168
|
-
});
|
169
|
-
|
170
|
-
d3.timer.flush();
|
171
|
-
|
172
|
-
return chart;
|
173
|
-
}
|
174
|
-
|
175
|
-
|
176
|
-
//============================================================
|
177
|
-
// Expose Public Variables
|
178
|
-
//------------------------------------------------------------
|
179
|
-
|
180
|
-
chart.dispatch = dispatch;
|
181
|
-
|
182
|
-
// left, right, top, bottom
|
183
|
-
chart.orient = function(_) {
|
184
|
-
if (!arguments.length) return orient;
|
185
|
-
orient = _;
|
186
|
-
reverse = orient == 'right' || orient == 'bottom';
|
187
|
-
return chart;
|
188
|
-
};
|
189
|
-
|
190
|
-
// ranges (bad, satisfactory, good)
|
191
|
-
chart.ranges = function(_) {
|
192
|
-
if (!arguments.length) return ranges;
|
193
|
-
ranges = _;
|
194
|
-
return chart;
|
195
|
-
};
|
196
|
-
|
197
|
-
// markers (previous, goal)
|
198
|
-
chart.markers = function(_) {
|
199
|
-
if (!arguments.length) return markers;
|
200
|
-
markers = _;
|
201
|
-
return chart;
|
202
|
-
};
|
203
|
-
|
204
|
-
// measures (actual, forecast)
|
205
|
-
chart.measures = function(_) {
|
206
|
-
if (!arguments.length) return measures;
|
207
|
-
measures = _;
|
208
|
-
return chart;
|
209
|
-
};
|
210
|
-
|
211
|
-
chart.forceX = function(_) {
|
212
|
-
if (!arguments.length) return forceX;
|
213
|
-
forceX = _;
|
214
|
-
return chart;
|
215
|
-
};
|
216
|
-
|
217
|
-
chart.width = function(_) {
|
218
|
-
if (!arguments.length) return width;
|
219
|
-
width = _;
|
220
|
-
return chart;
|
221
|
-
};
|
222
|
-
|
223
|
-
chart.height = function(_) {
|
224
|
-
if (!arguments.length) return height;
|
225
|
-
height = _;
|
226
|
-
return chart;
|
227
|
-
};
|
228
|
-
|
229
|
-
chart.margin = function(_) {
|
230
|
-
if (!arguments.length) return margin;
|
231
|
-
margin.top = typeof _.top != 'undefined' ? _.top : margin.top;
|
232
|
-
margin.right = typeof _.right != 'undefined' ? _.right : margin.right;
|
233
|
-
margin.bottom = typeof _.bottom != 'undefined' ? _.bottom : margin.bottom;
|
234
|
-
margin.left = typeof _.left != 'undefined' ? _.left : margin.left;
|
235
|
-
return chart;
|
236
|
-
};
|
237
|
-
|
238
|
-
chart.tickFormat = function(_) {
|
239
|
-
if (!arguments.length) return tickFormat;
|
240
|
-
tickFormat = _;
|
241
|
-
return chart;
|
242
|
-
};
|
243
|
-
|
244
|
-
//============================================================
|
245
|
-
|
246
|
-
|
247
|
-
return chart;
|
248
|
-
};
|
249
|
-
|
250
|
-
|
@@ -1,349 +0,0 @@
|
|
1
|
-
|
2
|
-
// Chart design based on the recommendations of Stephen Few. Implementation
|
3
|
-
// based on the work of Clint Ivy, Jamie Love, and Jason Davies.
|
4
|
-
// http://projects.instantcognition.com/protovis/bulletchart/
|
5
|
-
nv.models.bulletChart = function() {
|
6
|
-
|
7
|
-
//============================================================
|
8
|
-
// Public Variables with Default Settings
|
9
|
-
//------------------------------------------------------------
|
10
|
-
|
11
|
-
var bullet = nv.models.bullet()
|
12
|
-
;
|
13
|
-
|
14
|
-
var orient = 'left' // TODO top & bottom
|
15
|
-
, reverse = false
|
16
|
-
, margin = {top: 5, right: 40, bottom: 20, left: 120}
|
17
|
-
, ranges = function(d) { return d.ranges }
|
18
|
-
, markers = function(d) { return d.markers }
|
19
|
-
, measures = function(d) { return d.measures }
|
20
|
-
, width = null
|
21
|
-
, height = 55
|
22
|
-
, tickFormat = null
|
23
|
-
, tooltips = true
|
24
|
-
, tooltip = function(key, x, y, e, graph) {
|
25
|
-
return '<h3>' + e.label + '</h3>' +
|
26
|
-
'<p>' + e.value + '</p>'
|
27
|
-
}
|
28
|
-
, noData = "No Data Available."
|
29
|
-
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide')
|
30
|
-
;
|
31
|
-
|
32
|
-
//============================================================
|
33
|
-
|
34
|
-
|
35
|
-
//============================================================
|
36
|
-
// Private Variables
|
37
|
-
//------------------------------------------------------------
|
38
|
-
|
39
|
-
var showTooltip = function(e, parentElement) {
|
40
|
-
var offsetElement = parentElement.parentNode.parentNode,
|
41
|
-
left = e.pos[0] + offsetElement.offsetLeft + margin.left,
|
42
|
-
top = e.pos[1] + offsetElement.offsetTop + margin.top;
|
43
|
-
|
44
|
-
var content = '<h3>' + e.label + '</h3>' +
|
45
|
-
'<p>' + e.value + '</p>';
|
46
|
-
|
47
|
-
nv.tooltip.show([left, top], content, e.value < 0 ? 'e' : 'w', null, offsetElement.parentNode);
|
48
|
-
};
|
49
|
-
|
50
|
-
//============================================================
|
51
|
-
|
52
|
-
|
53
|
-
function chart(selection) {
|
54
|
-
selection.each(function(d, i) {
|
55
|
-
var container = d3.select(this);
|
56
|
-
|
57
|
-
var availableWidth = (width || parseInt(container.style('width')) || 960)
|
58
|
-
- margin.left - margin.right,
|
59
|
-
availableHeight = height - margin.top - margin.bottom,
|
60
|
-
that = this;
|
61
|
-
|
62
|
-
|
63
|
-
chart.update = function() { chart(selection) };
|
64
|
-
chart.container = this;
|
65
|
-
|
66
|
-
//------------------------------------------------------------
|
67
|
-
// Display No Data message if there's nothing to show.
|
68
|
-
|
69
|
-
/*
|
70
|
-
// Disabled until I figure out a better way to check for no data with the bullet chart
|
71
|
-
if (!data || !data.length || !data.filter(function(d) { return d.values.length }).length) {
|
72
|
-
var noDataText = container.selectAll('.nv-noData').data([noData]);
|
73
|
-
|
74
|
-
noDataText.enter().append('text')
|
75
|
-
.attr('class', 'nvd3 nv-noData')
|
76
|
-
.attr('dy', '-.7em')
|
77
|
-
.style('text-anchor', 'middle');
|
78
|
-
|
79
|
-
noDataText
|
80
|
-
.attr('x', margin.left + availableWidth / 2)
|
81
|
-
.attr('y', margin.top + availableHeight / 2)
|
82
|
-
.text(function(d) { return d });
|
83
|
-
|
84
|
-
return chart;
|
85
|
-
} else {
|
86
|
-
container.selectAll('.nv-noData').remove();
|
87
|
-
}
|
88
|
-
*/
|
89
|
-
|
90
|
-
//------------------------------------------------------------
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
var rangez = ranges.call(this, d, i).slice().sort(d3.descending),
|
95
|
-
markerz = markers.call(this, d, i).slice().sort(d3.descending),
|
96
|
-
measurez = measures.call(this, d, i).slice().sort(d3.descending);
|
97
|
-
|
98
|
-
|
99
|
-
//------------------------------------------------------------
|
100
|
-
// Setup containers and skeleton of chart
|
101
|
-
|
102
|
-
var wrap = container.selectAll('g.nv-wrap.nv-bulletChart').data([d]);
|
103
|
-
var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-bulletChart');
|
104
|
-
var gEnter = wrapEnter.append('g');
|
105
|
-
var g = wrap.select('g');
|
106
|
-
|
107
|
-
gEnter.append('g').attr('class', 'nv-bulletWrap');
|
108
|
-
gEnter.append('g').attr('class', 'nv-titles');
|
109
|
-
|
110
|
-
wrap.attr('transform', 'translate(' + margin.left + ',' + ( margin.top + i*height )+ ')');
|
111
|
-
|
112
|
-
//------------------------------------------------------------
|
113
|
-
|
114
|
-
|
115
|
-
// Compute the new x-scale.
|
116
|
-
var MaxX = Math.max(rangez[0] ? rangez[0]:0 , markerz[0] ? markerz[0] : 0 , measurez[0] ? measurez[0] : 0)
|
117
|
-
var x1 = d3.scale.linear()
|
118
|
-
.domain([0, MaxX]).nice() // TODO: need to allow forceX and forceY, and xDomain, yDomain
|
119
|
-
.range(reverse ? [availableWidth, 0] : [0, availableWidth]);
|
120
|
-
|
121
|
-
// Retrieve the old x-scale, if this is an update.
|
122
|
-
var x0 = this.__chart__ || d3.scale.linear()
|
123
|
-
.domain([0, Infinity])
|
124
|
-
.range(x1.range());
|
125
|
-
|
126
|
-
// Stash the new scale.
|
127
|
-
this.__chart__ = x1;
|
128
|
-
|
129
|
-
/*
|
130
|
-
// Derive width-scales from the x-scales.
|
131
|
-
var w0 = bulletWidth(x0),
|
132
|
-
w1 = bulletWidth(x1);
|
133
|
-
|
134
|
-
function bulletWidth(x) {
|
135
|
-
var x0 = x(0);
|
136
|
-
return function(d) {
|
137
|
-
return Math.abs(x(d) - x(0));
|
138
|
-
};
|
139
|
-
}
|
140
|
-
|
141
|
-
function bulletTranslate(x) {
|
142
|
-
return function(d) {
|
143
|
-
return 'translate(' + x(d) + ',0)';
|
144
|
-
};
|
145
|
-
}
|
146
|
-
*/
|
147
|
-
|
148
|
-
var w0 = function(d) { return Math.abs(x0(d) - x0(0)) }, // TODO: could optimize by precalculating x0(0) and x1(0)
|
149
|
-
w1 = function(d) { return Math.abs(x1(d) - x1(0)) };
|
150
|
-
|
151
|
-
|
152
|
-
var title = gEnter.select('.nv-titles').append("g")
|
153
|
-
.attr("text-anchor", "end")
|
154
|
-
.attr("transform", "translate(-6," + (height - margin.top - margin.bottom) / 2 + ")");
|
155
|
-
title.append("text")
|
156
|
-
.attr("class", "nv-title")
|
157
|
-
.text(function(d) { return d.title; });
|
158
|
-
|
159
|
-
title.append("text")
|
160
|
-
.attr("class", "nv-subtitle")
|
161
|
-
.attr("dy", "1em")
|
162
|
-
.text(function(d) { return d.subtitle; });
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
bullet
|
167
|
-
.width(availableWidth)
|
168
|
-
.height(availableHeight)
|
169
|
-
|
170
|
-
var bulletWrap = g.select('.nv-bulletWrap');
|
171
|
-
|
172
|
-
d3.transition(bulletWrap).call(bullet);
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
// Compute the tick format.
|
177
|
-
var format = tickFormat || x1.tickFormat(8);
|
178
|
-
|
179
|
-
// Update the tick groups.
|
180
|
-
var tick = g.selectAll('g.nv-tick')
|
181
|
-
.data(x1.ticks(8), function(d) {
|
182
|
-
return this.textContent || format(d);
|
183
|
-
});
|
184
|
-
|
185
|
-
// Initialize the ticks with the old scale, x0.
|
186
|
-
var tickEnter = tick.enter().append('g')
|
187
|
-
.attr('class', 'nv-tick')
|
188
|
-
.attr('transform', function(d) { return 'translate(' + x0(d) + ',0)' })
|
189
|
-
.style('opacity', 1e-6);
|
190
|
-
|
191
|
-
tickEnter.append('line')
|
192
|
-
.attr('y1', availableHeight)
|
193
|
-
.attr('y2', availableHeight * 7 / 6);
|
194
|
-
|
195
|
-
tickEnter.append('text')
|
196
|
-
.attr('text-anchor', 'middle')
|
197
|
-
.attr('dy', '1em')
|
198
|
-
.attr('y', availableHeight * 7 / 6)
|
199
|
-
.text(format);
|
200
|
-
|
201
|
-
// Transition the entering ticks to the new scale, x1.
|
202
|
-
d3.transition(tickEnter)
|
203
|
-
.attr('transform', function(d) { return 'translate(' + x1(d) + ',0)' })
|
204
|
-
.style('opacity', 1);
|
205
|
-
|
206
|
-
// Transition the updating ticks to the new scale, x1.
|
207
|
-
var tickUpdate = d3.transition(tick)
|
208
|
-
.attr('transform', function(d) { return 'translate(' + x1(d) + ',0)' })
|
209
|
-
.style('opacity', 1);
|
210
|
-
|
211
|
-
tickUpdate.select('line')
|
212
|
-
.attr('y1', availableHeight)
|
213
|
-
.attr('y2', availableHeight * 7 / 6);
|
214
|
-
|
215
|
-
tickUpdate.select('text')
|
216
|
-
.attr('y', availableHeight * 7 / 6);
|
217
|
-
|
218
|
-
// Transition the exiting ticks to the new scale, x1.
|
219
|
-
d3.transition(tick.exit())
|
220
|
-
.attr('transform', function(d) { return 'translate(' + x1(d) + ',0)' })
|
221
|
-
.style('opacity', 1e-6)
|
222
|
-
.remove();
|
223
|
-
|
224
|
-
|
225
|
-
//============================================================
|
226
|
-
// Event Handling/Dispatching (in chart's scope)
|
227
|
-
//------------------------------------------------------------
|
228
|
-
|
229
|
-
dispatch.on('tooltipShow', function(e) {
|
230
|
-
if (tooltips) showTooltip(e, that.parentNode);
|
231
|
-
});
|
232
|
-
|
233
|
-
//============================================================
|
234
|
-
|
235
|
-
});
|
236
|
-
|
237
|
-
d3.timer.flush();
|
238
|
-
|
239
|
-
return chart;
|
240
|
-
}
|
241
|
-
|
242
|
-
|
243
|
-
//============================================================
|
244
|
-
// Event Handling/Dispatching (out of chart's scope)
|
245
|
-
//------------------------------------------------------------
|
246
|
-
|
247
|
-
bullet.dispatch.on('elementMouseover.tooltip', function(e) {
|
248
|
-
dispatch.tooltipShow(e);
|
249
|
-
});
|
250
|
-
|
251
|
-
bullet.dispatch.on('elementMouseout.tooltip', function(e) {
|
252
|
-
dispatch.tooltipHide(e);
|
253
|
-
});
|
254
|
-
|
255
|
-
dispatch.on('tooltipHide', function() {
|
256
|
-
if (tooltips) nv.tooltip.cleanup();
|
257
|
-
});
|
258
|
-
|
259
|
-
//============================================================
|
260
|
-
|
261
|
-
|
262
|
-
//============================================================
|
263
|
-
// Expose Public Variables
|
264
|
-
//------------------------------------------------------------
|
265
|
-
|
266
|
-
chart.dispatch = dispatch;
|
267
|
-
chart.bullet = bullet;
|
268
|
-
|
269
|
-
// left, right, top, bottom
|
270
|
-
chart.orient = function(x) {
|
271
|
-
if (!arguments.length) return orient;
|
272
|
-
orient = x;
|
273
|
-
reverse = orient == 'right' || orient == 'bottom';
|
274
|
-
return chart;
|
275
|
-
};
|
276
|
-
|
277
|
-
// ranges (bad, satisfactory, good)
|
278
|
-
chart.ranges = function(x) {
|
279
|
-
if (!arguments.length) return ranges;
|
280
|
-
ranges = x;
|
281
|
-
return chart;
|
282
|
-
};
|
283
|
-
|
284
|
-
// markers (previous, goal)
|
285
|
-
chart.markers = function(x) {
|
286
|
-
if (!arguments.length) return markers;
|
287
|
-
markers = x;
|
288
|
-
return chart;
|
289
|
-
};
|
290
|
-
|
291
|
-
// measures (actual, forecast)
|
292
|
-
chart.measures = function(x) {
|
293
|
-
if (!arguments.length) return measures;
|
294
|
-
measures = x;
|
295
|
-
return chart;
|
296
|
-
};
|
297
|
-
|
298
|
-
chart.width = function(x) {
|
299
|
-
if (!arguments.length) return width;
|
300
|
-
width = x;
|
301
|
-
return chart;
|
302
|
-
};
|
303
|
-
|
304
|
-
chart.height = function(x) {
|
305
|
-
if (!arguments.length) return height;
|
306
|
-
height = x;
|
307
|
-
return chart;
|
308
|
-
};
|
309
|
-
|
310
|
-
chart.margin = function(_) {
|
311
|
-
if (!arguments.length) return margin;
|
312
|
-
margin.top = typeof _.top != 'undefined' ? _.top : margin.top;
|
313
|
-
margin.right = typeof _.right != 'undefined' ? _.right : margin.right;
|
314
|
-
margin.bottom = typeof _.bottom != 'undefined' ? _.bottom : margin.bottom;
|
315
|
-
margin.left = typeof _.left != 'undefined' ? _.left : margin.left;
|
316
|
-
return chart;
|
317
|
-
};
|
318
|
-
|
319
|
-
chart.tickFormat = function(x) {
|
320
|
-
if (!arguments.length) return tickFormat;
|
321
|
-
tickFormat = x;
|
322
|
-
return chart;
|
323
|
-
};
|
324
|
-
|
325
|
-
chart.tooltips = function(_) {
|
326
|
-
if (!arguments.length) return tooltips;
|
327
|
-
tooltips = _;
|
328
|
-
return chart;
|
329
|
-
};
|
330
|
-
|
331
|
-
chart.tooltipContent = function(_) {
|
332
|
-
if (!arguments.length) return tooltip;
|
333
|
-
tooltip = _;
|
334
|
-
return chart;
|
335
|
-
};
|
336
|
-
|
337
|
-
chart.noData = function(_) {
|
338
|
-
if (!arguments.length) return noData;
|
339
|
-
noData = _;
|
340
|
-
return chart;
|
341
|
-
};
|
342
|
-
|
343
|
-
//============================================================
|
344
|
-
|
345
|
-
|
346
|
-
return chart;
|
347
|
-
};
|
348
|
-
|
349
|
-
|