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,452 @@
1
+ nv.models.multiChart = function() {
2
+ "use strict";
3
+ //============================================================
4
+ // Public Variables with Default Settings
5
+ //------------------------------------------------------------
6
+
7
+ var margin = {top: 30, right: 20, bottom: 50, left: 60},
8
+ color = d3.scale.category20().range(),
9
+ width = null,
10
+ height = null,
11
+ showLegend = true,
12
+ tooltips = true,
13
+ tooltip = function(key, x, y, e, graph) {
14
+ return '<h3>' + key + '</h3>' +
15
+ '<p>' + y + ' at ' + x + '</p>'
16
+ },
17
+ x,
18
+ y,
19
+ yDomain1,
20
+ yDomain2
21
+ ; //can be accessed via chart.lines.[x/y]Scale()
22
+
23
+ //============================================================
24
+ // Private Variables
25
+ //------------------------------------------------------------
26
+
27
+ var x = d3.scale.linear(),
28
+ yScale1 = d3.scale.linear(),
29
+ yScale2 = d3.scale.linear(),
30
+
31
+ lines1 = nv.models.line().yScale(yScale1),
32
+ lines2 = nv.models.line().yScale(yScale2),
33
+
34
+ bars1 = nv.models.multiBar().stacked(false).yScale(yScale1),
35
+ bars2 = nv.models.multiBar().stacked(false).yScale(yScale2),
36
+
37
+ stack1 = nv.models.stackedArea().yScale(yScale1),
38
+ stack2 = nv.models.stackedArea().yScale(yScale2),
39
+
40
+ xAxis = nv.models.axis().scale(x).orient('bottom').tickPadding(5),
41
+ yAxis1 = nv.models.axis().scale(yScale1).orient('left'),
42
+ yAxis2 = nv.models.axis().scale(yScale2).orient('right'),
43
+
44
+ legend = nv.models.legend().height(30),
45
+ dispatch = d3.dispatch('tooltipShow', 'tooltipHide');
46
+
47
+ var showTooltip = function(e, offsetElement) {
48
+ var left = e.pos[0] + ( offsetElement.offsetLeft || 0 ),
49
+ top = e.pos[1] + ( offsetElement.offsetTop || 0),
50
+ x = xAxis.tickFormat()(lines1.x()(e.point, e.pointIndex)),
51
+ y = ((e.series.yAxis == 2) ? yAxis2 : yAxis1).tickFormat()(lines1.y()(e.point, e.pointIndex)),
52
+ content = tooltip(e.series.key, x, y, e, chart);
53
+
54
+ nv.tooltip.show([left, top], content, undefined, undefined, offsetElement.offsetParent);
55
+ };
56
+
57
+ function chart(selection) {
58
+ selection.each(function(data) {
59
+ var container = d3.select(this),
60
+ that = this;
61
+
62
+ chart.update = function() { container.transition().call(chart); };
63
+ chart.container = this;
64
+
65
+ var availableWidth = (width || parseInt(container.style('width')) || 960)
66
+ - margin.left - margin.right,
67
+ availableHeight = (height || parseInt(container.style('height')) || 400)
68
+ - margin.top - margin.bottom;
69
+
70
+ var dataLines1 = data.filter(function(d) {return !d.disabled && d.type == 'line' && d.yAxis == 1})
71
+ var dataLines2 = data.filter(function(d) {return !d.disabled && d.type == 'line' && d.yAxis == 2})
72
+ var dataBars1 = data.filter(function(d) {return !d.disabled && d.type == 'bar' && d.yAxis == 1})
73
+ var dataBars2 = data.filter(function(d) {return !d.disabled && d.type == 'bar' && d.yAxis == 2})
74
+ var dataStack1 = data.filter(function(d) {return !d.disabled && d.type == 'area' && d.yAxis == 1})
75
+ var dataStack2 = data.filter(function(d) {return !d.disabled && d.type == 'area' && d.yAxis == 2})
76
+
77
+ var series1 = data.filter(function(d) {return !d.disabled && d.yAxis == 1})
78
+ .map(function(d) {
79
+ return d.values.map(function(d,i) {
80
+ return { x: d.x, y: d.y }
81
+ })
82
+ })
83
+
84
+ var series2 = data.filter(function(d) {return !d.disabled && d.yAxis == 2})
85
+ .map(function(d) {
86
+ return d.values.map(function(d,i) {
87
+ return { x: d.x, y: d.y }
88
+ })
89
+ })
90
+
91
+ x .domain(d3.extent(d3.merge(series1.concat(series2)), function(d) { return d.x } ))
92
+ .range([0, availableWidth]);
93
+
94
+ var wrap = container.selectAll('g.wrap.multiChart').data([data]);
95
+ var gEnter = wrap.enter().append('g').attr('class', 'wrap nvd3 multiChart').append('g');
96
+
97
+ gEnter.append('g').attr('class', 'x axis');
98
+ gEnter.append('g').attr('class', 'y1 axis');
99
+ gEnter.append('g').attr('class', 'y2 axis');
100
+ gEnter.append('g').attr('class', 'lines1Wrap');
101
+ gEnter.append('g').attr('class', 'lines2Wrap');
102
+ gEnter.append('g').attr('class', 'bars1Wrap');
103
+ gEnter.append('g').attr('class', 'bars2Wrap');
104
+ gEnter.append('g').attr('class', 'stack1Wrap');
105
+ gEnter.append('g').attr('class', 'stack2Wrap');
106
+ gEnter.append('g').attr('class', 'legendWrap');
107
+
108
+ var g = wrap.select('g');
109
+
110
+ if (showLegend) {
111
+ legend.width( availableWidth / 2 );
112
+
113
+ g.select('.legendWrap')
114
+ .datum(data.map(function(series) {
115
+ series.originalKey = series.originalKey === undefined ? series.key : series.originalKey;
116
+ series.key = series.originalKey + (series.yAxis == 1 ? '' : ' (right axis)');
117
+ return series;
118
+ }))
119
+ .call(legend);
120
+
121
+ if ( margin.top != legend.height()) {
122
+ margin.top = legend.height();
123
+ availableHeight = (height || parseInt(container.style('height')) || 400)
124
+ - margin.top - margin.bottom;
125
+ }
126
+
127
+ g.select('.legendWrap')
128
+ .attr('transform', 'translate(' + ( availableWidth / 2 ) + ',' + (-margin.top) +')');
129
+ }
130
+
131
+
132
+ lines1
133
+ .width(availableWidth)
134
+ .height(availableHeight)
135
+ .interpolate("monotone")
136
+ .color(data.map(function(d,i) {
137
+ return d.color || color[i % color.length];
138
+ }).filter(function(d,i) { return !data[i].disabled && data[i].yAxis == 1 && data[i].type == 'line'}));
139
+
140
+ lines2
141
+ .width(availableWidth)
142
+ .height(availableHeight)
143
+ .interpolate("monotone")
144
+ .color(data.map(function(d,i) {
145
+ return d.color || color[i % color.length];
146
+ }).filter(function(d,i) { return !data[i].disabled && data[i].yAxis == 2 && data[i].type == 'line'}));
147
+
148
+ bars1
149
+ .width(availableWidth)
150
+ .height(availableHeight)
151
+ .color(data.map(function(d,i) {
152
+ return d.color || color[i % color.length];
153
+ }).filter(function(d,i) { return !data[i].disabled && data[i].yAxis == 1 && data[i].type == 'bar'}));
154
+
155
+ bars2
156
+ .width(availableWidth)
157
+ .height(availableHeight)
158
+ .color(data.map(function(d,i) {
159
+ return d.color || color[i % color.length];
160
+ }).filter(function(d,i) { return !data[i].disabled && data[i].yAxis == 2 && data[i].type == 'bar'}));
161
+
162
+ stack1
163
+ .width(availableWidth)
164
+ .height(availableHeight)
165
+ .color(data.map(function(d,i) {
166
+ return d.color || color[i % color.length];
167
+ }).filter(function(d,i) { return !data[i].disabled && data[i].yAxis == 1 && data[i].type == 'area'}));
168
+
169
+ stack2
170
+ .width(availableWidth)
171
+ .height(availableHeight)
172
+ .color(data.map(function(d,i) {
173
+ return d.color || color[i % color.length];
174
+ }).filter(function(d,i) { return !data[i].disabled && data[i].yAxis == 2 && data[i].type == 'area'}));
175
+
176
+ g.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
177
+
178
+
179
+ var lines1Wrap = g.select('.lines1Wrap')
180
+ .datum(dataLines1)
181
+ var bars1Wrap = g.select('.bars1Wrap')
182
+ .datum(dataBars1)
183
+ var stack1Wrap = g.select('.stack1Wrap')
184
+ .datum(dataStack1)
185
+
186
+ var lines2Wrap = g.select('.lines2Wrap')
187
+ .datum(dataLines2)
188
+ var bars2Wrap = g.select('.bars2Wrap')
189
+ .datum(dataBars2)
190
+ var stack2Wrap = g.select('.stack2Wrap')
191
+ .datum(dataStack2)
192
+
193
+ var extraValue1 = dataStack1.length ? dataStack1.map(function(a){return a.values}).reduce(function(a,b){
194
+ return a.map(function(aVal,i){return {x: aVal.x, y: aVal.y + b[i].y}})
195
+ }).concat([{x:0, y:0}]) : []
196
+ var extraValue2 = dataStack2.length ? dataStack2.map(function(a){return a.values}).reduce(function(a,b){
197
+ return a.map(function(aVal,i){return {x: aVal.x, y: aVal.y + b[i].y}})
198
+ }).concat([{x:0, y:0}]) : []
199
+
200
+ yScale1 .domain(yDomain1 || d3.extent(d3.merge(series1).concat(extraValue1), function(d) { return d.y } ))
201
+ .range([0, availableHeight])
202
+
203
+ yScale2 .domain(yDomain2 || d3.extent(d3.merge(series2).concat(extraValue2), function(d) { return d.y } ))
204
+ .range([0, availableHeight])
205
+
206
+ lines1.yDomain(yScale1.domain())
207
+ bars1.yDomain(yScale1.domain())
208
+ stack1.yDomain(yScale1.domain())
209
+
210
+ lines2.yDomain(yScale2.domain())
211
+ bars2.yDomain(yScale2.domain())
212
+ stack2.yDomain(yScale2.domain())
213
+
214
+ if(dataStack1.length){d3.transition(stack1Wrap).call(stack1);}
215
+ if(dataStack2.length){d3.transition(stack2Wrap).call(stack2);}
216
+
217
+ if(dataBars1.length){d3.transition(bars1Wrap).call(bars1);}
218
+ if(dataBars2.length){d3.transition(bars2Wrap).call(bars2);}
219
+
220
+ if(dataLines1.length){d3.transition(lines1Wrap).call(lines1);}
221
+ if(dataLines2.length){d3.transition(lines2Wrap).call(lines2);}
222
+
223
+
224
+
225
+ xAxis
226
+ .ticks( availableWidth / 100 )
227
+ .tickSize(-availableHeight, 0);
228
+
229
+ g.select('.x.axis')
230
+ .attr('transform', 'translate(0,' + availableHeight + ')');
231
+ d3.transition(g.select('.x.axis'))
232
+ .call(xAxis);
233
+
234
+ yAxis1
235
+ .ticks( availableHeight / 36 )
236
+ .tickSize( -availableWidth, 0);
237
+
238
+
239
+ d3.transition(g.select('.y1.axis'))
240
+ .call(yAxis1);
241
+
242
+ yAxis2
243
+ .ticks( availableHeight / 36 )
244
+ .tickSize( -availableWidth, 0);
245
+
246
+ d3.transition(g.select('.y2.axis'))
247
+ .call(yAxis2);
248
+
249
+ g.select('.y2.axis')
250
+ .style('opacity', series2.length ? 1 : 0)
251
+ .attr('transform', 'translate(' + x.range()[1] + ',0)');
252
+
253
+ legend.dispatch.on('stateChange', function(newState) {
254
+ chart.update();
255
+ });
256
+
257
+ dispatch.on('tooltipShow', function(e) {
258
+ if (tooltips) showTooltip(e, that.parentNode);
259
+ });
260
+
261
+ });
262
+
263
+ return chart;
264
+ }
265
+
266
+
267
+ //============================================================
268
+ // Event Handling/Dispatching (out of chart's scope)
269
+ //------------------------------------------------------------
270
+
271
+ lines1.dispatch.on('elementMouseover.tooltip', function(e) {
272
+ e.pos = [e.pos[0] + margin.left, e.pos[1] + margin.top];
273
+ dispatch.tooltipShow(e);
274
+ });
275
+
276
+ lines1.dispatch.on('elementMouseout.tooltip', function(e) {
277
+ dispatch.tooltipHide(e);
278
+ });
279
+
280
+ lines2.dispatch.on('elementMouseover.tooltip', function(e) {
281
+ e.pos = [e.pos[0] + margin.left, e.pos[1] + margin.top];
282
+ dispatch.tooltipShow(e);
283
+ });
284
+
285
+ lines2.dispatch.on('elementMouseout.tooltip', function(e) {
286
+ dispatch.tooltipHide(e);
287
+ });
288
+
289
+ bars1.dispatch.on('elementMouseover.tooltip', function(e) {
290
+ e.pos = [e.pos[0] + margin.left, e.pos[1] + margin.top];
291
+ dispatch.tooltipShow(e);
292
+ });
293
+
294
+ bars1.dispatch.on('elementMouseout.tooltip', function(e) {
295
+ dispatch.tooltipHide(e);
296
+ });
297
+
298
+ bars2.dispatch.on('elementMouseover.tooltip', function(e) {
299
+ e.pos = [e.pos[0] + margin.left, e.pos[1] + margin.top];
300
+ dispatch.tooltipShow(e);
301
+ });
302
+
303
+ bars2.dispatch.on('elementMouseout.tooltip', function(e) {
304
+ dispatch.tooltipHide(e);
305
+ });
306
+
307
+ stack1.dispatch.on('tooltipShow', function(e) {
308
+ //disable tooltips when value ~= 0
309
+ //// TODO: consider removing points from voronoi that have 0 value instead of this hack
310
+ if (!Math.round(stack1.y()(e.point) * 100)) { // 100 will not be good for very small numbers... will have to think about making this valu dynamic, based on data range
311
+ setTimeout(function() { d3.selectAll('.point.hover').classed('hover', false) }, 0);
312
+ return false;
313
+ }
314
+
315
+ e.pos = [e.pos[0] + margin.left, e.pos[1] + margin.top],
316
+ dispatch.tooltipShow(e);
317
+ });
318
+
319
+ stack1.dispatch.on('tooltipHide', function(e) {
320
+ dispatch.tooltipHide(e);
321
+ });
322
+
323
+ stack2.dispatch.on('tooltipShow', function(e) {
324
+ //disable tooltips when value ~= 0
325
+ //// TODO: consider removing points from voronoi that have 0 value instead of this hack
326
+ if (!Math.round(stack2.y()(e.point) * 100)) { // 100 will not be good for very small numbers... will have to think about making this valu dynamic, based on data range
327
+ setTimeout(function() { d3.selectAll('.point.hover').classed('hover', false) }, 0);
328
+ return false;
329
+ }
330
+
331
+ e.pos = [e.pos[0] + margin.left, e.pos[1] + margin.top],
332
+ dispatch.tooltipShow(e);
333
+ });
334
+
335
+ stack2.dispatch.on('tooltipHide', function(e) {
336
+ dispatch.tooltipHide(e);
337
+ });
338
+
339
+ lines1.dispatch.on('elementMouseover.tooltip', function(e) {
340
+ e.pos = [e.pos[0] + margin.left, e.pos[1] + margin.top];
341
+ dispatch.tooltipShow(e);
342
+ });
343
+
344
+ lines1.dispatch.on('elementMouseout.tooltip', function(e) {
345
+ dispatch.tooltipHide(e);
346
+ });
347
+
348
+ lines2.dispatch.on('elementMouseover.tooltip', function(e) {
349
+ e.pos = [e.pos[0] + margin.left, e.pos[1] + margin.top];
350
+ dispatch.tooltipShow(e);
351
+ });
352
+
353
+ lines2.dispatch.on('elementMouseout.tooltip', function(e) {
354
+ dispatch.tooltipHide(e);
355
+ });
356
+
357
+ dispatch.on('tooltipHide', function() {
358
+ if (tooltips) nv.tooltip.cleanup();
359
+ });
360
+
361
+
362
+
363
+ //============================================================
364
+ // Global getters and setters
365
+ //------------------------------------------------------------
366
+
367
+ chart.dispatch = dispatch;
368
+ chart.lines1 = lines1;
369
+ chart.lines2 = lines2;
370
+ chart.bars1 = bars1;
371
+ chart.bars2 = bars2;
372
+ chart.stack1 = stack1;
373
+ chart.stack2 = stack2;
374
+ chart.xAxis = xAxis;
375
+ chart.yAxis1 = yAxis1;
376
+ chart.yAxis2 = yAxis2;
377
+ chart.options = nv.utils.optionsFunc.bind(chart);
378
+
379
+ chart.x = function(_) {
380
+ if (!arguments.length) return getX;
381
+ getX = _;
382
+ lines1.x(_);
383
+ bars1.x(_);
384
+ return chart;
385
+ };
386
+
387
+ chart.y = function(_) {
388
+ if (!arguments.length) return getY;
389
+ getY = _;
390
+ lines1.y(_);
391
+ bars1.y(_);
392
+ return chart;
393
+ };
394
+
395
+ chart.yDomain1 = function(_) {
396
+ if (!arguments.length) return yDomain1;
397
+ yDomain1 = _;
398
+ return chart;
399
+ };
400
+
401
+ chart.yDomain2 = function(_) {
402
+ if (!arguments.length) return yDomain2;
403
+ yDomain2 = _;
404
+ return chart;
405
+ };
406
+
407
+ chart.margin = function(_) {
408
+ if (!arguments.length) return margin;
409
+ margin = _;
410
+ return chart;
411
+ };
412
+
413
+ chart.width = function(_) {
414
+ if (!arguments.length) return width;
415
+ width = _;
416
+ return chart;
417
+ };
418
+
419
+ chart.height = function(_) {
420
+ if (!arguments.length) return height;
421
+ height = _;
422
+ return chart;
423
+ };
424
+
425
+ chart.color = function(_) {
426
+ if (!arguments.length) return color;
427
+ color = _;
428
+ legend.color(_);
429
+ return chart;
430
+ };
431
+
432
+ chart.showLegend = function(_) {
433
+ if (!arguments.length) return showLegend;
434
+ showLegend = _;
435
+ return chart;
436
+ };
437
+
438
+ chart.tooltips = function(_) {
439
+ if (!arguments.length) return tooltips;
440
+ tooltips = _;
441
+ return chart;
442
+ };
443
+
444
+ chart.tooltipContent = function(_) {
445
+ if (!arguments.length) return tooltip;
446
+ tooltip = _;
447
+ return chart;
448
+ };
449
+
450
+ return chart;
451
+ }
452
+
@@ -0,0 +1,380 @@
1
+
2
+ nv.models.ohlcBar = function() {
3
+ "use strict";
4
+ //============================================================
5
+ // Public Variables with Default Settings
6
+ //------------------------------------------------------------
7
+
8
+ var margin = {top: 0, right: 0, bottom: 0, left: 0}
9
+ , width = 960
10
+ , height = 500
11
+ , id = Math.floor(Math.random() * 10000) //Create semi-unique ID in case user doesn't select one
12
+ , x = d3.scale.linear()
13
+ , y = d3.scale.linear()
14
+ , getX = function(d) { return d.x }
15
+ , getY = function(d) { return d.y }
16
+ , getOpen = function(d) { return d.open }
17
+ , getClose = function(d) { return d.close }
18
+ , getHigh = function(d) { return d.high }
19
+ , getLow = function(d) { return d.low }
20
+ , forceX = []
21
+ , forceY = []
22
+ , padData = false // If true, adds half a data points width to front and back, for lining up a line chart with a bar chart
23
+ , clipEdge = true
24
+ , color = nv.utils.defaultColor()
25
+ , xDomain
26
+ , yDomain
27
+ , xRange
28
+ , yRange
29
+ , dispatch = d3.dispatch('chartClick', 'elementClick', 'elementDblClick', 'elementMouseover', 'elementMouseout')
30
+ ;
31
+
32
+ //============================================================
33
+
34
+ //============================================================
35
+ // Private Variables
36
+ //------------------------------------------------------------
37
+
38
+ //TODO: store old scales for transitions
39
+
40
+ //============================================================
41
+
42
+
43
+ function chart(selection) {
44
+ selection.each(function(data) {
45
+ var availableWidth = width - margin.left - margin.right,
46
+ availableHeight = height - margin.top - margin.bottom,
47
+ container = d3.select(this);
48
+
49
+
50
+ //------------------------------------------------------------
51
+ // Setup Scales
52
+
53
+ x .domain(xDomain || d3.extent(data[0].values.map(getX).concat(forceX) ));
54
+
55
+ if (padData)
56
+ x.range(xRange || [availableWidth * .5 / data[0].values.length, availableWidth * (data[0].values.length - .5) / data[0].values.length ]);
57
+ else
58
+ x.range(xRange || [0, availableWidth]);
59
+
60
+ y .domain(yDomain || [
61
+ d3.min(data[0].values.map(getLow).concat(forceY)),
62
+ d3.max(data[0].values.map(getHigh).concat(forceY))
63
+ ])
64
+ .range(yRange || [availableHeight, 0]);
65
+
66
+ // If scale's domain don't have a range, slightly adjust to make one... so a chart can show a single data point
67
+ if (x.domain()[0] === x.domain()[1])
68
+ x.domain()[0] ?
69
+ x.domain([x.domain()[0] - x.domain()[0] * 0.01, x.domain()[1] + x.domain()[1] * 0.01])
70
+ : x.domain([-1,1]);
71
+
72
+ if (y.domain()[0] === y.domain()[1])
73
+ y.domain()[0] ?
74
+ y.domain([y.domain()[0] + y.domain()[0] * 0.01, y.domain()[1] - y.domain()[1] * 0.01])
75
+ : y.domain([-1,1]);
76
+
77
+ //------------------------------------------------------------
78
+
79
+
80
+ //------------------------------------------------------------
81
+ // Setup containers and skeleton of chart
82
+
83
+ var wrap = d3.select(this).selectAll('g.nv-wrap.nv-ohlcBar').data([data[0].values]);
84
+ var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-ohlcBar');
85
+ var defsEnter = wrapEnter.append('defs');
86
+ var gEnter = wrapEnter.append('g');
87
+ var g = wrap.select('g');
88
+
89
+ gEnter.append('g').attr('class', 'nv-ticks');
90
+
91
+ wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
92
+
93
+ //------------------------------------------------------------
94
+
95
+
96
+ container
97
+ .on('click', function(d,i) {
98
+ dispatch.chartClick({
99
+ data: d,
100
+ index: i,
101
+ pos: d3.event,
102
+ id: id
103
+ });
104
+ });
105
+
106
+
107
+ defsEnter.append('clipPath')
108
+ .attr('id', 'nv-chart-clip-path-' + id)
109
+ .append('rect');
110
+
111
+ wrap.select('#nv-chart-clip-path-' + id + ' rect')
112
+ .attr('width', availableWidth)
113
+ .attr('height', availableHeight);
114
+
115
+ g .attr('clip-path', clipEdge ? 'url(#nv-chart-clip-path-' + id + ')' : '');
116
+
117
+
118
+
119
+ var ticks = wrap.select('.nv-ticks').selectAll('.nv-tick')
120
+ .data(function(d) { return d });
121
+
122
+ ticks.exit().remove();
123
+
124
+
125
+ var ticksEnter = ticks.enter().append('path')
126
+ .attr('class', function(d,i,j) { return (getOpen(d,i) > getClose(d,i) ? 'nv-tick negative' : 'nv-tick positive') + ' nv-tick-' + j + '-' + i })
127
+ .attr('d', function(d,i) {
128
+ var w = (availableWidth / data[0].values.length) * .9;
129
+ return 'm0,0l0,'
130
+ + (y(getOpen(d,i))
131
+ - y(getHigh(d,i)))
132
+ + 'l'
133
+ + (-w/2)
134
+ + ',0l'
135
+ + (w/2)
136
+ + ',0l0,'
137
+ + (y(getLow(d,i)) - y(getOpen(d,i)))
138
+ + 'l0,'
139
+ + (y(getClose(d,i))
140
+ - y(getLow(d,i)))
141
+ + 'l'
142
+ + (w/2)
143
+ + ',0l'
144
+ + (-w/2)
145
+ + ',0z';
146
+ })
147
+ .attr('transform', function(d,i) { return 'translate(' + x(getX(d,i)) + ',' + y(getHigh(d,i)) + ')'; })
148
+ //.attr('fill', function(d,i) { return color[0]; })
149
+ //.attr('stroke', function(d,i) { return color[0]; })
150
+ //.attr('x', 0 )
151
+ //.attr('y', function(d,i) { return y(Math.max(0, getY(d,i))) })
152
+ //.attr('height', function(d,i) { return Math.abs(y(getY(d,i)) - y(0)) })
153
+ .on('mouseover', function(d,i) {
154
+ d3.select(this).classed('hover', true);
155
+ dispatch.elementMouseover({
156
+ point: d,
157
+ series: data[0],
158
+ pos: [x(getX(d,i)), y(getY(d,i))], // TODO: Figure out why the value appears to be shifted
159
+ pointIndex: i,
160
+ seriesIndex: 0,
161
+ e: d3.event
162
+ });
163
+
164
+ })
165
+ .on('mouseout', function(d,i) {
166
+ d3.select(this).classed('hover', false);
167
+ dispatch.elementMouseout({
168
+ point: d,
169
+ series: data[0],
170
+ pointIndex: i,
171
+ seriesIndex: 0,
172
+ e: d3.event
173
+ });
174
+ })
175
+ .on('click', function(d,i) {
176
+ dispatch.elementClick({
177
+ //label: d[label],
178
+ value: getY(d,i),
179
+ data: d,
180
+ index: i,
181
+ pos: [x(getX(d,i)), y(getY(d,i))],
182
+ e: d3.event,
183
+ id: id
184
+ });
185
+ d3.event.stopPropagation();
186
+ })
187
+ .on('dblclick', function(d,i) {
188
+ dispatch.elementDblClick({
189
+ //label: d[label],
190
+ value: getY(d,i),
191
+ data: d,
192
+ index: i,
193
+ pos: [x(getX(d,i)), y(getY(d,i))],
194
+ e: d3.event,
195
+ id: id
196
+ });
197
+ d3.event.stopPropagation();
198
+ });
199
+
200
+ ticks
201
+ .attr('class', function(d,i,j) { return (getOpen(d,i) > getClose(d,i) ? 'nv-tick negative' : 'nv-tick positive') + ' nv-tick-' + j + '-' + i })
202
+ d3.transition(ticks)
203
+ .attr('transform', function(d,i) { return 'translate(' + x(getX(d,i)) + ',' + y(getHigh(d,i)) + ')'; })
204
+ .attr('d', function(d,i) {
205
+ var w = (availableWidth / data[0].values.length) * .9;
206
+ return 'm0,0l0,'
207
+ + (y(getOpen(d,i))
208
+ - y(getHigh(d,i)))
209
+ + 'l'
210
+ + (-w/2)
211
+ + ',0l'
212
+ + (w/2)
213
+ + ',0l0,'
214
+ + (y(getLow(d,i))
215
+ - y(getOpen(d,i)))
216
+ + 'l0,'
217
+ + (y(getClose(d,i))
218
+ - y(getLow(d,i)))
219
+ + 'l'
220
+ + (w/2)
221
+ + ',0l'
222
+ + (-w/2)
223
+ + ',0z';
224
+ })
225
+ //.attr('width', (availableWidth / data[0].values.length) * .9 )
226
+
227
+
228
+ //d3.transition(ticks)
229
+ //.attr('y', function(d,i) { return y(Math.max(0, getY(d,i))) })
230
+ //.attr('height', function(d,i) { return Math.abs(y(getY(d,i)) - y(0)) });
231
+ //.order(); // not sure if this makes any sense for this model
232
+
233
+ });
234
+
235
+ return chart;
236
+ }
237
+
238
+
239
+ //============================================================
240
+ // Expose Public Variables
241
+ //------------------------------------------------------------
242
+
243
+ chart.dispatch = dispatch;
244
+
245
+ chart.options = nv.utils.optionsFunc.bind(chart);
246
+
247
+ chart.x = function(_) {
248
+ if (!arguments.length) return getX;
249
+ getX = _;
250
+ return chart;
251
+ };
252
+
253
+ chart.y = function(_) {
254
+ if (!arguments.length) return getY;
255
+ getY = _;
256
+ return chart;
257
+ };
258
+
259
+ chart.open = function(_) {
260
+ if (!arguments.length) return getOpen;
261
+ getOpen = _;
262
+ return chart;
263
+ };
264
+
265
+ chart.close = function(_) {
266
+ if (!arguments.length) return getClose;
267
+ getClose = _;
268
+ return chart;
269
+ };
270
+
271
+ chart.high = function(_) {
272
+ if (!arguments.length) return getHigh;
273
+ getHigh = _;
274
+ return chart;
275
+ };
276
+
277
+ chart.low = function(_) {
278
+ if (!arguments.length) return getLow;
279
+ getLow = _;
280
+ return chart;
281
+ };
282
+
283
+ chart.margin = function(_) {
284
+ if (!arguments.length) return margin;
285
+ margin.top = typeof _.top != 'undefined' ? _.top : margin.top;
286
+ margin.right = typeof _.right != 'undefined' ? _.right : margin.right;
287
+ margin.bottom = typeof _.bottom != 'undefined' ? _.bottom : margin.bottom;
288
+ margin.left = typeof _.left != 'undefined' ? _.left : margin.left;
289
+ return chart;
290
+ };
291
+
292
+ chart.width = function(_) {
293
+ if (!arguments.length) return width;
294
+ width = _;
295
+ return chart;
296
+ };
297
+
298
+ chart.height = function(_) {
299
+ if (!arguments.length) return height;
300
+ height = _;
301
+ return chart;
302
+ };
303
+
304
+ chart.xScale = function(_) {
305
+ if (!arguments.length) return x;
306
+ x = _;
307
+ return chart;
308
+ };
309
+
310
+ chart.yScale = function(_) {
311
+ if (!arguments.length) return y;
312
+ y = _;
313
+ return chart;
314
+ };
315
+
316
+ chart.xDomain = function(_) {
317
+ if (!arguments.length) return xDomain;
318
+ xDomain = _;
319
+ return chart;
320
+ };
321
+
322
+ chart.yDomain = function(_) {
323
+ if (!arguments.length) return yDomain;
324
+ yDomain = _;
325
+ return chart;
326
+ };
327
+
328
+ chart.xRange = function(_) {
329
+ if (!arguments.length) return xRange;
330
+ xRange = _;
331
+ return chart;
332
+ };
333
+
334
+ chart.yRange = function(_) {
335
+ if (!arguments.length) return yRange;
336
+ yRange = _;
337
+ return chart;
338
+ };
339
+
340
+ chart.forceX = function(_) {
341
+ if (!arguments.length) return forceX;
342
+ forceX = _;
343
+ return chart;
344
+ };
345
+
346
+ chart.forceY = function(_) {
347
+ if (!arguments.length) return forceY;
348
+ forceY = _;
349
+ return chart;
350
+ };
351
+
352
+ chart.padData = function(_) {
353
+ if (!arguments.length) return padData;
354
+ padData = _;
355
+ return chart;
356
+ };
357
+
358
+ chart.clipEdge = function(_) {
359
+ if (!arguments.length) return clipEdge;
360
+ clipEdge = _;
361
+ return chart;
362
+ };
363
+
364
+ chart.color = function(_) {
365
+ if (!arguments.length) return color;
366
+ color = nv.utils.getColor(_);
367
+ return chart;
368
+ };
369
+
370
+ chart.id = function(_) {
371
+ if (!arguments.length) return id;
372
+ id = _;
373
+ return chart;
374
+ };
375
+
376
+ //============================================================
377
+
378
+
379
+ return chart;
380
+ }