pyk 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/app/assets/javascripts/lib/chardinjs.min.js +2 -0
- data/app/assets/javascripts/lib/crossfilter.js +1383 -1
- data/app/assets/javascripts/lib/{d3.js → d3.v3.js} +0 -0
- data/app/assets/javascripts/lib/dc.js +3492 -757
- data/app/assets/javascripts/lib/jquery.gridster.js +2 -3621
- data/app/assets/javascripts/lib/markermanager.js +2 -980
- data/app/assets/javascripts/lib/underscore.js +1276 -0
- data/app/assets/javascripts/nvd3/lib/colorbrewer.js +302 -0
- data/app/assets/javascripts/nvd3/lib/crossfilter.js +1180 -0
- data/app/assets/javascripts/nvd3/lib/crossfilter.min.js +1 -0
- data/app/assets/javascripts/nvd3/lib/d3.v2.js +7033 -0
- data/app/assets/javascripts/nvd3/lib/d3.v2.min.js +4 -0
- data/app/assets/javascripts/nvd3/lib/d3.v3.js +8436 -0
- data/app/assets/javascripts/nvd3/lib/fisheye.js +86 -0
- data/app/assets/javascripts/nvd3/lib/hive.js +80 -0
- data/app/assets/javascripts/nvd3/lib/horizon.js +192 -0
- data/app/assets/javascripts/nvd3/lib/sankey.js +292 -0
- data/app/assets/javascripts/nvd3/nv.d3.js +14312 -0
- data/app/assets/javascripts/nvd3/nv.d3.min.js +6 -0
- data/app/assets/javascripts/nvd3/src/core.js +122 -0
- data/app/assets/javascripts/nvd3/src/interactiveLayer.js +251 -0
- data/app/assets/javascripts/nvd3/src/models/axis.js +405 -0
- data/app/assets/javascripts/nvd3/src/models/backup/bullet.js +250 -0
- data/app/assets/javascripts/nvd3/src/models/backup/bulletChart.js +349 -0
- data/app/assets/javascripts/nvd3/src/models/boilerplate.js +104 -0
- data/app/assets/javascripts/nvd3/src/models/bullet.js +385 -0
- data/app/assets/javascripts/nvd3/src/models/bulletChart.js +343 -0
- data/app/assets/javascripts/nvd3/src/models/cumulativeLineChart.js +782 -0
- data/app/assets/javascripts/nvd3/src/models/discreteBar.js +349 -0
- data/app/assets/javascripts/nvd3/src/models/discreteBarChart.js +333 -0
- data/app/assets/javascripts/nvd3/src/models/distribution.js +148 -0
- data/app/assets/javascripts/nvd3/src/models/historicalBar.js +331 -0
- data/app/assets/javascripts/nvd3/src/models/historicalBarChart.js +419 -0
- data/app/assets/javascripts/nvd3/src/models/indentedTree.js +337 -0
- data/app/assets/javascripts/nvd3/src/models/legend.js +270 -0
- data/app/assets/javascripts/nvd3/src/models/line.js +284 -0
- data/app/assets/javascripts/nvd3/src/models/lineChart.js +465 -0
- data/app/assets/javascripts/nvd3/src/models/linePlusBarChart.js +433 -0
- data/app/assets/javascripts/nvd3/src/models/linePlusBarWithFocusChart.js +658 -0
- data/app/assets/javascripts/nvd3/src/models/lineWithFisheye.js +200 -0
- data/app/assets/javascripts/nvd3/src/models/lineWithFisheyeChart.js +297 -0
- data/app/assets/javascripts/nvd3/src/models/lineWithFocusChart.js +574 -0
- data/app/assets/javascripts/nvd3/src/models/multiBar.js +461 -0
- data/app/assets/javascripts/nvd3/src/models/multiBarChart.js +524 -0
- data/app/assets/javascripts/nvd3/src/models/multiBarHorizontal.js +424 -0
- data/app/assets/javascripts/nvd3/src/models/multiBarHorizontalChart.js +434 -0
- data/app/assets/javascripts/nvd3/src/models/multiBarTimeSeries.js +384 -0
- data/app/assets/javascripts/nvd3/src/models/multiBarTimeSeriesChart.js +405 -0
- data/app/assets/javascripts/nvd3/src/models/multiChart.js +452 -0
- data/app/assets/javascripts/nvd3/src/models/ohlcBar.js +380 -0
- data/app/assets/javascripts/nvd3/src/models/parallelCoordinates.js +239 -0
- data/app/assets/javascripts/nvd3/src/models/pie.js +398 -0
- data/app/assets/javascripts/nvd3/src/models/pieChart.js +292 -0
- data/app/assets/javascripts/nvd3/src/models/scatter.js +674 -0
- data/app/assets/javascripts/nvd3/src/models/scatterChart.js +628 -0
- data/app/assets/javascripts/nvd3/src/models/scatterPlusLineChart.js +620 -0
- data/app/assets/javascripts/nvd3/src/models/sparkline.js +194 -0
- data/app/assets/javascripts/nvd3/src/models/sparklinePlus.js +295 -0
- data/app/assets/javascripts/nvd3/src/models/stackedArea.js +368 -0
- data/app/assets/javascripts/nvd3/src/models/stackedAreaChart.js +629 -0
- data/app/assets/javascripts/nvd3/src/tooltip.js +490 -0
- data/app/assets/javascripts/nvd3/src/utils.js +152 -0
- data/app/assets/javascripts/pyk.js +1 -0
- data/app/assets/stylesheets/lib/chardinjs.css +82 -0
- data/app/assets/stylesheets/nvd3/nv.d3.css +769 -0
- data/app/assets/stylesheets/pyk.css.scss +1 -0
- metadata +61 -2
@@ -0,0 +1,250 @@
|
|
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
|
+
|
@@ -0,0 +1,349 @@
|
|
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
|
+
|