pyk 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +8 -8
  2. data/app/assets/javascripts/lib/chardinjs.min.js +2 -0
  3. data/app/assets/javascripts/lib/crossfilter.js +1383 -1
  4. data/app/assets/javascripts/lib/{d3.js → d3.v3.js} +0 -0
  5. data/app/assets/javascripts/lib/dc.js +3492 -757
  6. data/app/assets/javascripts/lib/jquery.gridster.js +2 -3621
  7. data/app/assets/javascripts/lib/markermanager.js +2 -980
  8. data/app/assets/javascripts/lib/underscore.js +1276 -0
  9. data/app/assets/javascripts/nvd3/lib/colorbrewer.js +302 -0
  10. data/app/assets/javascripts/nvd3/lib/crossfilter.js +1180 -0
  11. data/app/assets/javascripts/nvd3/lib/crossfilter.min.js +1 -0
  12. data/app/assets/javascripts/nvd3/lib/d3.v2.js +7033 -0
  13. data/app/assets/javascripts/nvd3/lib/d3.v2.min.js +4 -0
  14. data/app/assets/javascripts/nvd3/lib/d3.v3.js +8436 -0
  15. data/app/assets/javascripts/nvd3/lib/fisheye.js +86 -0
  16. data/app/assets/javascripts/nvd3/lib/hive.js +80 -0
  17. data/app/assets/javascripts/nvd3/lib/horizon.js +192 -0
  18. data/app/assets/javascripts/nvd3/lib/sankey.js +292 -0
  19. data/app/assets/javascripts/nvd3/nv.d3.js +14312 -0
  20. data/app/assets/javascripts/nvd3/nv.d3.min.js +6 -0
  21. data/app/assets/javascripts/nvd3/src/core.js +122 -0
  22. data/app/assets/javascripts/nvd3/src/interactiveLayer.js +251 -0
  23. data/app/assets/javascripts/nvd3/src/models/axis.js +405 -0
  24. data/app/assets/javascripts/nvd3/src/models/backup/bullet.js +250 -0
  25. data/app/assets/javascripts/nvd3/src/models/backup/bulletChart.js +349 -0
  26. data/app/assets/javascripts/nvd3/src/models/boilerplate.js +104 -0
  27. data/app/assets/javascripts/nvd3/src/models/bullet.js +385 -0
  28. data/app/assets/javascripts/nvd3/src/models/bulletChart.js +343 -0
  29. data/app/assets/javascripts/nvd3/src/models/cumulativeLineChart.js +782 -0
  30. data/app/assets/javascripts/nvd3/src/models/discreteBar.js +349 -0
  31. data/app/assets/javascripts/nvd3/src/models/discreteBarChart.js +333 -0
  32. data/app/assets/javascripts/nvd3/src/models/distribution.js +148 -0
  33. data/app/assets/javascripts/nvd3/src/models/historicalBar.js +331 -0
  34. data/app/assets/javascripts/nvd3/src/models/historicalBarChart.js +419 -0
  35. data/app/assets/javascripts/nvd3/src/models/indentedTree.js +337 -0
  36. data/app/assets/javascripts/nvd3/src/models/legend.js +270 -0
  37. data/app/assets/javascripts/nvd3/src/models/line.js +284 -0
  38. data/app/assets/javascripts/nvd3/src/models/lineChart.js +465 -0
  39. data/app/assets/javascripts/nvd3/src/models/linePlusBarChart.js +433 -0
  40. data/app/assets/javascripts/nvd3/src/models/linePlusBarWithFocusChart.js +658 -0
  41. data/app/assets/javascripts/nvd3/src/models/lineWithFisheye.js +200 -0
  42. data/app/assets/javascripts/nvd3/src/models/lineWithFisheyeChart.js +297 -0
  43. data/app/assets/javascripts/nvd3/src/models/lineWithFocusChart.js +574 -0
  44. data/app/assets/javascripts/nvd3/src/models/multiBar.js +461 -0
  45. data/app/assets/javascripts/nvd3/src/models/multiBarChart.js +524 -0
  46. data/app/assets/javascripts/nvd3/src/models/multiBarHorizontal.js +424 -0
  47. data/app/assets/javascripts/nvd3/src/models/multiBarHorizontalChart.js +434 -0
  48. data/app/assets/javascripts/nvd3/src/models/multiBarTimeSeries.js +384 -0
  49. data/app/assets/javascripts/nvd3/src/models/multiBarTimeSeriesChart.js +405 -0
  50. data/app/assets/javascripts/nvd3/src/models/multiChart.js +452 -0
  51. data/app/assets/javascripts/nvd3/src/models/ohlcBar.js +380 -0
  52. data/app/assets/javascripts/nvd3/src/models/parallelCoordinates.js +239 -0
  53. data/app/assets/javascripts/nvd3/src/models/pie.js +398 -0
  54. data/app/assets/javascripts/nvd3/src/models/pieChart.js +292 -0
  55. data/app/assets/javascripts/nvd3/src/models/scatter.js +674 -0
  56. data/app/assets/javascripts/nvd3/src/models/scatterChart.js +628 -0
  57. data/app/assets/javascripts/nvd3/src/models/scatterPlusLineChart.js +620 -0
  58. data/app/assets/javascripts/nvd3/src/models/sparkline.js +194 -0
  59. data/app/assets/javascripts/nvd3/src/models/sparklinePlus.js +295 -0
  60. data/app/assets/javascripts/nvd3/src/models/stackedArea.js +368 -0
  61. data/app/assets/javascripts/nvd3/src/models/stackedAreaChart.js +629 -0
  62. data/app/assets/javascripts/nvd3/src/tooltip.js +490 -0
  63. data/app/assets/javascripts/nvd3/src/utils.js +152 -0
  64. data/app/assets/javascripts/pyk.js +1 -0
  65. data/app/assets/stylesheets/lib/chardinjs.css +82 -0
  66. data/app/assets/stylesheets/nvd3/nv.d3.css +769 -0
  67. data/app/assets/stylesheets/pyk.css.scss +1 -0
  68. metadata +61 -2
@@ -0,0 +1,384 @@
1
+ nv.models.multiBarTimeSeries = function() {
2
+ "use strict";
3
+ //============================================================
4
+ // Public Variables with Default Settings
5
+ //------------------------------------------------------------
6
+
7
+ var margin = {top: 0, right: 0, bottom: 0, left: 0}
8
+ , width = 960
9
+ , height = 500
10
+ , x = d3.time.scale()
11
+ , y = d3.scale.linear()
12
+ , id = Math.floor(Math.random() * 10000) //Create semi-unique ID in case user doesn't select one
13
+ , getX = function(d) { return d.x }
14
+ , getY = function(d) { return d.y }
15
+ , forceY = [0] // 0 is forced by default.. this makes sense for the majority of bar graphs... user can always do chart.forceY([]) to remove
16
+ , clipEdge = true
17
+ , stacked = false
18
+ , color = nv.utils.defaultColor()
19
+ , delay = 1200
20
+ , xDomain
21
+ , yDomain
22
+ , xRange
23
+ , yRange
24
+ , dispatch = d3.dispatch('chartClick', 'elementClick', 'elementDblClick', 'elementMouseover', 'elementMouseout')
25
+ ;
26
+
27
+ //============================================================
28
+
29
+
30
+ //============================================================
31
+ // Private Variables
32
+ //------------------------------------------------------------
33
+
34
+ var x0, y0 //used to store previous scales
35
+ ;
36
+
37
+ //============================================================
38
+
39
+
40
+ function chart(selection) {
41
+ selection.each(function(data) {
42
+ var availableWidth = width - margin.left - margin.right,
43
+ availableHeight = height - margin.top - margin.bottom,
44
+ container = d3.select(this);
45
+
46
+ if (stacked)
47
+ data = d3.layout.stack()
48
+ .offset('zero')
49
+ .values(function(d){ return d.values })
50
+ .y(getY)
51
+ (data);
52
+
53
+
54
+ //add series index to each data point for reference
55
+ data.forEach(function(series, i) {
56
+ series.values.forEach(function(point) {
57
+ point.series = i;
58
+ });
59
+ });
60
+
61
+ //------------------------------------------------------------
62
+ // Setup Scales
63
+
64
+ // remap and flatten the data for use in calculating the scales' domains
65
+ var seriesData = (xDomain && yDomain) ? [] : // if we know xDomain and yDomain, no need to calculate
66
+ data.map(function(d) {
67
+ return d.values.map(function(d,i) {
68
+ return { x: getX(d,i), y: getY(d,i), y0: d.y0 }
69
+ })
70
+ });
71
+
72
+ x .domain(xDomain || d3.extent(d3.merge(seriesData).map(function(d) { return d.x })))
73
+ .range(xRange || [0, availableWidth]);
74
+
75
+ y .domain(yDomain || d3.extent(d3.merge(seriesData).map(function(d) { return d.y + (stacked ? d.y0 : 0) }).concat(forceY)))
76
+ .range(yRange || [availableHeight, 0]);
77
+
78
+
79
+ // If scale's domain don't have a range, slightly adjust to make one... so a chart can show a single data point
80
+ if (x.domain()[0] === x.domain()[1])
81
+ x.domain()[0] ?
82
+ x.domain([x.domain()[0] - x.domain()[0] * 0.01, x.domain()[1] + x.domain()[1] * 0.01])
83
+ : x.domain([-1,1]);
84
+
85
+ if (y.domain()[0] === y.domain()[1])
86
+ y.domain()[0] ?
87
+ y.domain([y.domain()[0] + y.domain()[0] * 0.01, y.domain()[1] - y.domain()[1] * 0.01])
88
+ : y.domain([-1,1]);
89
+
90
+
91
+ x0 = x0 || x;
92
+ y0 = y0 || y;
93
+
94
+ //------------------------------------------------------------
95
+
96
+
97
+ //------------------------------------------------------------
98
+ // Setup containers and skeleton of chart
99
+
100
+ var wrap = container.selectAll('g.nv-wrap.nv-multibar').data([data]);
101
+ var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-multibar');
102
+ var defsEnter = wrapEnter.append('defs');
103
+ var gEnter = wrapEnter.append('g');
104
+ var g = wrap.select('g')
105
+
106
+ gEnter.append('g').attr('class', 'nv-groups');
107
+
108
+ wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
109
+
110
+ //------------------------------------------------------------
111
+
112
+
113
+
114
+ defsEnter.append('clipPath')
115
+ .attr('id', 'nv-edge-clip-' + id)
116
+ .append('rect');
117
+ wrap.select('#nv-edge-clip-' + id + ' rect')
118
+ .attr('width', availableWidth)
119
+ .attr('height', availableHeight);
120
+
121
+ g .attr('clip-path', clipEdge ? 'url(#nv-edge-clip-' + id + ')' : '');
122
+
123
+
124
+
125
+ var groups = wrap.select('.nv-groups').selectAll('.nv-group')
126
+ .data(function(d) { return d }, function(d) { return d.key });
127
+ groups.enter().append('g')
128
+ .style('stroke-opacity', 1e-6)
129
+ .style('fill-opacity', 1e-6);
130
+ d3.transition(groups.exit())
131
+ //.style('stroke-opacity', 1e-6)
132
+ //.style('fill-opacity', 1e-6)
133
+ .selectAll('rect.nv-bar')
134
+ .delay(function(d,i) { return i * delay/ data[0].values.length })
135
+ .attr('y', function(d) { return stacked ? y0(d.y0) : y0(0) })
136
+ .attr('height', 0)
137
+ .remove();
138
+ groups
139
+ .attr('class', function(d,i) { return 'nv-group nv-series-' + i })
140
+ .classed('hover', function(d) { return d.hover })
141
+ .style('fill', function(d,i){ return color(d, i) })
142
+ .style('stroke', function(d,i){ return color(d, i) });
143
+ d3.transition(groups)
144
+ .style('stroke-opacity', 1)
145
+ .style('fill-opacity', .75);
146
+
147
+
148
+ var bars = groups.selectAll('rect.nv-bar')
149
+ .data(function(d) { return d.values });
150
+
151
+ bars.exit().remove();
152
+
153
+ var maxElements = 0;
154
+ for(var ei=0; ei<seriesData.length; ei+=1) {
155
+ maxElements = Math.max(seriesData[ei].length, maxElements);
156
+ }
157
+
158
+ var bandWidth = (availableWidth / maxElements)-0.1;
159
+ var barWidth = bandWidth / data.length;
160
+
161
+ var barsEnter = bars.enter().append('rect')
162
+ .attr('class', function(d,i) { return getY(d,i) < 0 ? 'nv-bar negative' : 'nv-bar positive'})
163
+ .attr('x', function(d,i,j) {
164
+ return stacked ? 0 : (i * bandWidth) + ( j * barWidth )
165
+ })
166
+ .attr('y', function(d) { return y0(stacked ? d.y0 : 0) })
167
+ .attr('height', 0)
168
+ .attr('width', stacked ? bandWidth : barWidth );
169
+ bars
170
+ .on('mouseover', function(d,i) { //TODO: figure out why j works above, but not here
171
+ d3.select(this).classed('hover', true);
172
+ dispatch.elementMouseover({
173
+ value: getY(d,i),
174
+ point: d,
175
+ series: data[d.series],
176
+ pos: [x(getX(d,i)) + (barWidth * (stacked ? data.length / 2 : d.series + .5) / data.length), y(getY(d,i) + (stacked ? d.y0 : 0))], // TODO: Figure out why the value appears to be shifted
177
+ pointIndex: i,
178
+ seriesIndex: d.series,
179
+ e: d3.event
180
+ });
181
+ })
182
+ .on('mouseout', function(d,i) {
183
+ d3.select(this).classed('hover', false);
184
+ dispatch.elementMouseout({
185
+ value: getY(d,i),
186
+ point: d,
187
+ series: data[d.series],
188
+ pointIndex: i,
189
+ seriesIndex: d.series,
190
+ e: d3.event
191
+ });
192
+ })
193
+ .on('click', function(d,i) {
194
+ dispatch.elementClick({
195
+ value: getY(d,i),
196
+ point: d,
197
+ series: data[d.series],
198
+ pos: [x(getX(d,i)) + (barWidth * (stacked ? data.length / 2 : d.series + .5) / data.length), y(getY(d,i) + (stacked ? d.y0 : 0))], // TODO: Figure out why the value appears to be shifted
199
+ pointIndex: i,
200
+ seriesIndex: d.series,
201
+ e: d3.event
202
+ });
203
+ d3.event.stopPropagation();
204
+ })
205
+ .on('dblclick', function(d,i) {
206
+ dispatch.elementDblClick({
207
+ value: getY(d,i),
208
+ point: d,
209
+ series: data[d.series],
210
+ pos: [x(getX(d,i)) + (barWidth * (stacked ? data.length / 2 : d.series + .5) / data.length), y(getY(d,i) + (stacked ? d.y0 : 0))], // TODO: Figure out why the value appears to be shifted
211
+ pointIndex: i,
212
+ seriesIndex: d.series,
213
+ e: d3.event
214
+ });
215
+ d3.event.stopPropagation();
216
+ });
217
+ bars
218
+ .attr('class', function(d,i) { return getY(d,i) < 0 ? 'nv-bar negative' : 'nv-bar positive'})
219
+ .attr('transform', function(d,i) { return 'translate(' + x(getX(d,i)) + ',0)'; })
220
+ if (stacked)
221
+ d3.transition(bars)
222
+ .delay(function(d,i) { return i * delay / data[0].values.length })
223
+ .attr('y', function(d,i) {
224
+ return y(getY(d,i) + (stacked ? d.y0 : 0));
225
+ })
226
+ .attr('height', function(d,i) {
227
+ return Math.abs(y(d.y + (stacked ? d.y0 : 0)) - y((stacked ? d.y0 : 0)))
228
+ })
229
+ .each('end', function() {
230
+ d3.transition(d3.select(this))
231
+ .attr('x', function(d,i) {
232
+ return stacked ? 0 : (i * bandWidth) + ( j * barWidth )
233
+ })
234
+ .attr('width', stacked ? bandWidth : barWidth );
235
+ })
236
+ else
237
+ d3.transition(bars)
238
+ .delay(function(d,i) { return i * delay/ data[0].values.length })
239
+ .attr('x', function(d,i) {
240
+ return d.series * barWidth
241
+ })
242
+ .attr('width', barWidth)
243
+ .each('end', function() {
244
+ d3.transition(d3.select(this))
245
+ .attr('y', function(d,i) {
246
+ return getY(d,i) < 0 ?
247
+ y(0) :
248
+ y(getY(d,i))
249
+ })
250
+ .attr('height', function(d,i) {
251
+ return Math.abs(y(getY(d,i)) - y(0))
252
+ });
253
+ })
254
+
255
+
256
+ //store old scales for use in transitions on update
257
+ x0 = x.copy();
258
+ y0 = y.copy();
259
+
260
+ });
261
+
262
+ return chart;
263
+ }
264
+
265
+
266
+ //============================================================
267
+ // Expose Public Variables
268
+ //------------------------------------------------------------
269
+
270
+ chart.dispatch = dispatch;
271
+
272
+ chart.options = nv.utils.optionsFunc.bind(chart);
273
+
274
+ chart.x = function(_) {
275
+ if (!arguments.length) return getX;
276
+ getX = _;
277
+ return chart;
278
+ };
279
+
280
+ chart.y = function(_) {
281
+ if (!arguments.length) return getY;
282
+ getY = _;
283
+ return chart;
284
+ };
285
+
286
+ chart.margin = function(_) {
287
+ if (!arguments.length) return margin;
288
+ margin.top = typeof _.top != 'undefined' ? _.top : margin.top;
289
+ margin.right = typeof _.right != 'undefined' ? _.right : margin.right;
290
+ margin.bottom = typeof _.bottom != 'undefined' ? _.bottom : margin.bottom;
291
+ margin.left = typeof _.left != 'undefined' ? _.left : margin.left;
292
+ return chart;
293
+ };
294
+
295
+ chart.width = function(_) {
296
+ if (!arguments.length) return width;
297
+ width = _;
298
+ return chart;
299
+ };
300
+
301
+ chart.height = function(_) {
302
+ if (!arguments.length) return height;
303
+ height = _;
304
+ return chart;
305
+ };
306
+
307
+ chart.xScale = function(_) {
308
+ if (!arguments.length) return x;
309
+ x = _;
310
+ return chart;
311
+ };
312
+
313
+ chart.yScale = function(_) {
314
+ if (!arguments.length) return y;
315
+ y = _;
316
+ return chart;
317
+ };
318
+
319
+ chart.xDomain = function(_) {
320
+ if (!arguments.length) return xDomain;
321
+ xDomain = _;
322
+ return chart;
323
+ };
324
+
325
+ chart.yDomain = function(_) {
326
+ if (!arguments.length) return yDomain;
327
+ yDomain = _;
328
+ return chart;
329
+ };
330
+
331
+ chart.xRange = function(_) {
332
+ if (!arguments.length) return xRange;
333
+ xRange = _;
334
+ return chart;
335
+ };
336
+
337
+ chart.yRange = function(_) {
338
+ if (!arguments.length) return yRange;
339
+ yRange = _;
340
+ return chart;
341
+ };
342
+
343
+ chart.forceY = function(_) {
344
+ if (!arguments.length) return forceY;
345
+ forceY = _;
346
+ return chart;
347
+ };
348
+
349
+ chart.stacked = function(_) {
350
+ if (!arguments.length) return stacked;
351
+ stacked = _;
352
+ return chart;
353
+ };
354
+
355
+ chart.clipEdge = function(_) {
356
+ if (!arguments.length) return clipEdge;
357
+ clipEdge = _;
358
+ return chart;
359
+ };
360
+
361
+ chart.color = function(_) {
362
+ if (!arguments.length) return color;
363
+ color = nv.utils.getColor(_);
364
+ return chart;
365
+ };
366
+
367
+ chart.id = function(_) {
368
+ if (!arguments.length) return id;
369
+ id = _;
370
+ return chart;
371
+ };
372
+
373
+ chart.delay = function(_) {
374
+ if (!arguments.length) return delay;
375
+ delay = _;
376
+ return chart;
377
+ };
378
+
379
+ //============================================================
380
+
381
+
382
+ return chart;
383
+ }
384
+
@@ -0,0 +1,405 @@
1
+ nv.models.multiBarTimeSeriesChart = function() {
2
+ "use strict";
3
+ //============================================================
4
+ // Public Variables with Default Settings
5
+ //------------------------------------------------------------
6
+
7
+ var multibar = nv.models.multiBarTimeSeries()
8
+ , xAxis = nv.models.axis()
9
+ , yAxis = nv.models.axis()
10
+ , legend = nv.models.legend()
11
+ , controls = nv.models.legend()
12
+ ;
13
+
14
+ var margin = {top: 30, right: 20, bottom: 50, left: 60}
15
+ , width = null
16
+ , height = null
17
+ , color = nv.utils.defaultColor()
18
+ , showControls = true
19
+ , showLegend = true
20
+ , reduceXTicks = true // if false a tick will show for every data point
21
+ , rotateLabels = 0
22
+ , tooltips = true
23
+ , tooltip = function(key, x, y, e, graph) {
24
+ return '<h3>' + key + '</h3>' +
25
+ '<p>' + y + ' on ' + x + '</p>'
26
+ }
27
+ , x //can be accessed via chart.xScale()
28
+ , y //can be accessed via chart.yScale()
29
+ , noData = "No Data Available."
30
+ , dispatch = d3.dispatch('tooltipShow', 'tooltipHide')
31
+ ;
32
+
33
+ multibar
34
+ .stacked(false)
35
+ ;
36
+ xAxis
37
+ .orient('bottom')
38
+ .tickPadding(7)
39
+ .highlightZero(false)
40
+ .showMaxMin(false)
41
+ ;
42
+ yAxis
43
+ .orient('left')
44
+ .tickFormat(d3.format(',.1f'))
45
+ ;
46
+
47
+ //============================================================
48
+
49
+
50
+ //============================================================
51
+ // Private Variables
52
+ //------------------------------------------------------------
53
+
54
+ var showTooltip = function(e, offsetElement) {
55
+ var left = e.pos[0] + ( offsetElement.offsetLeft || 0 ),
56
+ top = e.pos[1] + ( offsetElement.offsetTop || 0),
57
+ x = xAxis.tickFormat()(multibar.x()(e.point, e.pointIndex)),
58
+ y = yAxis.tickFormat()(multibar.y()(e.point, e.pointIndex)),
59
+ content = tooltip(e.series.key, x, y, e, chart);
60
+
61
+ nv.tooltip.show([left, top], content, e.value < 0 ? 'n' : 's', null, offsetElement);
62
+ };
63
+
64
+ //============================================================
65
+
66
+
67
+ function chart(selection) {
68
+ selection.each(function(data) {
69
+ var container = d3.select(this),
70
+ that = this;
71
+
72
+ var availableWidth = (width || parseInt(container.style('width')) || 960)
73
+ - margin.left - margin.right,
74
+ availableHeight = (height || parseInt(container.style('height')) || 400)
75
+ - margin.top - margin.bottom;
76
+
77
+ chart.update = function() { selection.transition().call(chart) };
78
+ chart.container = this;
79
+
80
+
81
+ //------------------------------------------------------------
82
+ // Display noData message if there's nothing to show.
83
+
84
+ if (!data || !data.length || !data.filter(function(d) { return d.values.length }).length) {
85
+ var noDataText = container.selectAll('.nv-noData').data([noData]);
86
+
87
+ noDataText.enter().append('text')
88
+ .attr('class', 'nvd3 nv-noData')
89
+ .attr('dy', '-.7em')
90
+ .style('text-anchor', 'middle');
91
+
92
+ noDataText
93
+ .attr('x', margin.left + availableWidth / 2)
94
+ .attr('y', margin.top + availableHeight / 2)
95
+ .text(function(d) { return d });
96
+
97
+ return chart;
98
+ } else {
99
+ container.selectAll('.nv-noData').remove();
100
+ }
101
+
102
+ //------------------------------------------------------------
103
+
104
+
105
+ //------------------------------------------------------------
106
+ // Setup Scales
107
+
108
+ x = multibar.xScale();
109
+ y = multibar.yScale();
110
+
111
+ //------------------------------------------------------------
112
+
113
+
114
+ //------------------------------------------------------------
115
+ // Setup containers and skeleton of chart
116
+
117
+ var wrap = container.selectAll('g.nv-wrap.nv-multiBarWithLegend').data([data]);
118
+ var gEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-multiBarWithLegend').append('g');
119
+ var g = wrap.select('g');
120
+
121
+ gEnter.append('g').attr('class', 'nv-x nv-axis');
122
+ gEnter.append('g').attr('class', 'nv-y nv-axis');
123
+ gEnter.append('g').attr('class', 'nv-barsWrap');
124
+ gEnter.append('g').attr('class', 'nv-legendWrap');
125
+ gEnter.append('g').attr('class', 'nv-controlsWrap');
126
+
127
+ //------------------------------------------------------------
128
+
129
+
130
+ //------------------------------------------------------------
131
+ // Legend
132
+
133
+ if (showLegend) {
134
+ legend.width(availableWidth / 2);
135
+
136
+ g.select('.nv-legendWrap')
137
+ .datum(data)
138
+ .call(legend);
139
+
140
+ if ( margin.top != legend.height()) {
141
+ margin.top = legend.height();
142
+ availableHeight = (height || parseInt(container.style('height')) || 400)
143
+ - margin.top - margin.bottom;
144
+ }
145
+
146
+ g.select('.nv-legendWrap')
147
+ .attr('transform', 'translate(' + (availableWidth / 2) + ',' + (-margin.top) +')');
148
+ }
149
+
150
+ //------------------------------------------------------------
151
+
152
+
153
+ //------------------------------------------------------------
154
+ // Controls
155
+
156
+ if (showControls) {
157
+ var controlsData = [
158
+ { key: 'Grouped', disabled: multibar.stacked() },
159
+ { key: 'Stacked', disabled: !multibar.stacked() }
160
+ ];
161
+
162
+ controls.width(180).color(['#444', '#444', '#444']);
163
+ g.select('.nv-controlsWrap')
164
+ .datum(controlsData)
165
+ .attr('transform', 'translate(0,' + (-margin.top) +')')
166
+ .call(controls);
167
+ }
168
+
169
+ //------------------------------------------------------------
170
+
171
+
172
+ wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
173
+
174
+
175
+ //------------------------------------------------------------
176
+ // Main Chart Component(s)
177
+
178
+ multibar
179
+ .width(availableWidth)
180
+ .height(availableHeight)
181
+ .color(data.map(function(d,i) {
182
+ return d.color || color(d, i);
183
+ }).filter(function(d,i) { return !data[i].disabled }))
184
+
185
+
186
+ var barsWrap = g.select('.nv-barsWrap')
187
+ .datum(data.filter(function(d) { return !d.disabled }))
188
+
189
+ d3.transition(barsWrap).call(multibar);
190
+
191
+ //------------------------------------------------------------
192
+
193
+
194
+ //------------------------------------------------------------
195
+ // Setup Axes
196
+
197
+ xAxis
198
+ .scale(x)
199
+ .ticks(availableWidth / 100)
200
+ .tickSize(-availableHeight, 0);
201
+
202
+ g.select('.nv-x.nv-axis')
203
+ .attr('transform', 'translate(0,' + y.range()[0] + ')');
204
+ d3.transition(g.select('.nv-x.nv-axis'))
205
+ .call(xAxis);
206
+
207
+ var xTicks = g.select('.nv-x.nv-axis > g').selectAll('g');
208
+
209
+ xTicks
210
+ .selectAll('line, text')
211
+ .style('opacity', 1)
212
+
213
+ if (reduceXTicks)
214
+ xTicks
215
+ .filter(function(d,i) {
216
+ return i % Math.ceil(data[0].values.length / (availableWidth / 100)) !== 0;
217
+ })
218
+ .selectAll('text, line')
219
+ .style('opacity', 0);
220
+
221
+ if(rotateLabels)
222
+ xTicks
223
+ .selectAll('text')
224
+ .attr('transform', function(d,i,j) { return 'rotate('+rotateLabels+' 0,0)' })
225
+ .attr('text-transform', rotateLabels > 0 ? 'start' : 'end');
226
+
227
+ yAxis
228
+ .scale(y)
229
+ .ticks( availableHeight / 36 )
230
+ .tickSize( -availableWidth, 0);
231
+
232
+ d3.transition(g.select('.nv-y.nv-axis'))
233
+ .call(yAxis);
234
+
235
+ //------------------------------------------------------------
236
+
237
+
238
+
239
+ //============================================================
240
+ // Event Handling/Dispatching (in chart's scope)
241
+ //------------------------------------------------------------
242
+
243
+ legend.dispatch.on('legendClick', function(d,i) {
244
+ d.disabled = !d.disabled;
245
+
246
+ if (!data.filter(function(d) { return !d.disabled }).length) {
247
+ data.map(function(d) {
248
+ d.disabled = false;
249
+ wrap.selectAll('.nv-series').classed('disabled', false);
250
+ return d;
251
+ });
252
+ }
253
+
254
+ selection.transition().call(chart);
255
+ });
256
+
257
+ controls.dispatch.on('legendClick', function(d,i) {
258
+ if (!d.disabled) return;
259
+ controlsData = controlsData.map(function(s) {
260
+ s.disabled = true;
261
+ return s;
262
+ });
263
+ d.disabled = false;
264
+
265
+ switch (d.key) {
266
+ case 'Grouped':
267
+ multibar.stacked(false);
268
+ break;
269
+ case 'Stacked':
270
+ multibar.stacked(true);
271
+ break;
272
+ }
273
+
274
+ selection.transition().call(chart);
275
+ });
276
+
277
+ dispatch.on('tooltipShow', function(e) {
278
+ if (tooltips) showTooltip(e, that.parentNode)
279
+ });
280
+
281
+ //============================================================
282
+
283
+
284
+ });
285
+
286
+ return chart;
287
+ }
288
+
289
+
290
+ //============================================================
291
+ // Event Handling/Dispatching (out of chart's scope)
292
+ //------------------------------------------------------------
293
+
294
+ multibar.dispatch.on('elementMouseover.tooltip', function(e) {
295
+ e.pos = [e.pos[0] + margin.left, e.pos[1] + margin.top];
296
+ dispatch.tooltipShow(e);
297
+ });
298
+
299
+ multibar.dispatch.on('elementMouseout.tooltip', function(e) {
300
+ dispatch.tooltipHide(e);
301
+ });
302
+ dispatch.on('tooltipHide', function() {
303
+ if (tooltips) nv.tooltip.cleanup();
304
+ });
305
+
306
+ //============================================================
307
+
308
+
309
+ //============================================================
310
+ // Expose Public Variables
311
+ //------------------------------------------------------------
312
+
313
+ // expose chart's sub-components
314
+ chart.dispatch = dispatch;
315
+ chart.multibar = multibar;
316
+ chart.legend = legend;
317
+ chart.xAxis = xAxis;
318
+ chart.yAxis = yAxis;
319
+
320
+ d3.rebind(chart, multibar, 'x', 'y', 'xDomain', 'yDomain', 'xRange', 'yRange', 'forceX', 'forceY', 'clipEdge', 'id', 'stacked', 'delay');
321
+
322
+ chart.options = nv.utils.optionsFunc.bind(chart);
323
+
324
+ chart.margin = function(_) {
325
+ if (!arguments.length) return margin;
326
+ margin.top = typeof _.top != 'undefined' ? _.top : margin.top;
327
+ margin.right = typeof _.right != 'undefined' ? _.right : margin.right;
328
+ margin.bottom = typeof _.bottom != 'undefined' ? _.bottom : margin.bottom;
329
+ margin.left = typeof _.left != 'undefined' ? _.left : margin.left;
330
+ return chart;
331
+ };
332
+
333
+ chart.width = function(_) {
334
+ if (!arguments.length) return width;
335
+ width = _;
336
+ return chart;
337
+ };
338
+
339
+ chart.height = function(_) {
340
+ if (!arguments.length) return height;
341
+ height = _;
342
+ return chart;
343
+ };
344
+
345
+ chart.color = function(_) {
346
+ if (!arguments.length) return color;
347
+ color = nv.utils.getColor(_);
348
+ legend.color(color);
349
+ return chart;
350
+ };
351
+
352
+ chart.showControls = function(_) {
353
+ if (!arguments.length) return showControls;
354
+ showControls = _;
355
+ return chart;
356
+ };
357
+
358
+ chart.showLegend = function(_) {
359
+ if (!arguments.length) return showLegend;
360
+ showLegend = _;
361
+ return chart;
362
+ };
363
+
364
+ chart.reduceXTicks= function(_) {
365
+ if (!arguments.length) return reduceXTicks;
366
+ reduceXTicks = _;
367
+ return chart;
368
+ };
369
+
370
+ chart.rotateLabels = function(_) {
371
+ if (!arguments.length) return rotateLabels;
372
+ rotateLabels = _;
373
+ return chart;
374
+ }
375
+
376
+ chart.tooltip = function(_) {
377
+ if (!arguments.length) return tooltip;
378
+ tooltip = _;
379
+ return chart;
380
+ };
381
+
382
+ chart.tooltips = function(_) {
383
+ if (!arguments.length) return tooltips;
384
+ tooltips = _;
385
+ return chart;
386
+ };
387
+
388
+ chart.tooltipContent = function(_) {
389
+ if (!arguments.length) return tooltip;
390
+ tooltip = _;
391
+ return chart;
392
+ };
393
+
394
+ chart.noData = function(_) {
395
+ if (!arguments.length) return noData;
396
+ noData = _;
397
+ return chart;
398
+ };
399
+
400
+ //============================================================
401
+
402
+
403
+ return chart;
404
+ }
405
+