chartx 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. data/.gitignore +17 -0
  2. data/.gitmodules +3 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +145 -0
  6. data/Rakefile +1 -0
  7. data/chartx.gemspec +40 -0
  8. data/lib/chartx/engine.rb +11 -0
  9. data/lib/chartx/helper.rb +184 -0
  10. data/lib/chartx/version.rb +3 -0
  11. data/lib/chartx.rb +3 -0
  12. data/screenshots/barchart.png +0 -0
  13. data/screenshots/bulletchart.png +0 -0
  14. data/screenshots/horizontalbarchart.png +0 -0
  15. data/screenshots/linechart.png +0 -0
  16. data/screenshots/linewithfocuschart.png +0 -0
  17. data/screenshots/multibarchart2.png +0 -0
  18. data/screenshots/piechart.png +0 -0
  19. data/screenshots/scatterchart.png +0 -0
  20. data/screenshots/stackedareachart.png +0 -0
  21. data/screenshots/stackedareachart3.png +0 -0
  22. data/vendor/assets/javascripts/chartx-core.js +9 -0
  23. data/vendor/assets/javascripts/chartx-models.js +2 -0
  24. data/vendor/assets/javascripts/nvd3/.gitignore +27 -0
  25. data/vendor/assets/javascripts/nvd3/.jshintrc +3 -0
  26. data/vendor/assets/javascripts/nvd3/LICENSE.md +49 -0
  27. data/vendor/assets/javascripts/nvd3/README.md +1 -0
  28. data/vendor/assets/javascripts/nvd3/lib/cie.js +155 -0
  29. data/vendor/assets/javascripts/nvd3/lib/crossfilter.js +1180 -0
  30. data/vendor/assets/javascripts/nvd3/lib/crossfilter.min.js +1 -0
  31. data/vendor/assets/javascripts/nvd3/lib/d3.js +8798 -0
  32. data/vendor/assets/javascripts/nvd3/lib/d3.min.js +5 -0
  33. data/vendor/assets/javascripts/nvd3/lib/fisheye.js +86 -0
  34. data/vendor/assets/javascripts/nvd3/lib/hive.js +80 -0
  35. data/vendor/assets/javascripts/nvd3/lib/horizon.js +192 -0
  36. data/vendor/assets/javascripts/nvd3/lib/sankey.js +292 -0
  37. data/vendor/assets/javascripts/nvd3/nv.d3.js +13048 -0
  38. data/vendor/assets/javascripts/nvd3/nv.d3.min.js +6 -0
  39. data/vendor/assets/javascripts/nvd3/src/core.js +118 -0
  40. data/vendor/assets/javascripts/nvd3/src/intro.js +1 -0
  41. data/vendor/assets/javascripts/nvd3/src/models/axis.js +398 -0
  42. data/vendor/assets/javascripts/nvd3/src/models/boilerplate.js +102 -0
  43. data/vendor/assets/javascripts/nvd3/src/models/bullet.js +377 -0
  44. data/vendor/assets/javascripts/nvd3/src/models/bulletChart.js +341 -0
  45. data/vendor/assets/javascripts/nvd3/src/models/cumulativeLineChart.js +685 -0
  46. data/vendor/assets/javascripts/nvd3/src/models/discreteBar.js +327 -0
  47. data/vendor/assets/javascripts/nvd3/src/models/discreteBarChart.js +290 -0
  48. data/vendor/assets/javascripts/nvd3/src/models/distribution.js +146 -0
  49. data/vendor/assets/javascripts/nvd3/src/models/historicalBar.js +289 -0
  50. data/vendor/assets/javascripts/nvd3/src/models/historicalBarChart.js +421 -0
  51. data/vendor/assets/javascripts/nvd3/src/models/indentedTree.js +317 -0
  52. data/vendor/assets/javascripts/nvd3/src/models/legend.js +207 -0
  53. data/vendor/assets/javascripts/nvd3/src/models/line.js +284 -0
  54. data/vendor/assets/javascripts/nvd3/src/models/lineChart.js +421 -0
  55. data/vendor/assets/javascripts/nvd3/src/models/linePlusBarChart.js +455 -0
  56. data/vendor/assets/javascripts/nvd3/src/models/linePlusBarWithFocusChart.js +665 -0
  57. data/vendor/assets/javascripts/nvd3/src/models/lineWithFisheye.js +197 -0
  58. data/vendor/assets/javascripts/nvd3/src/models/lineWithFisheyeChart.js +319 -0
  59. data/vendor/assets/javascripts/nvd3/src/models/lineWithFocusChart.js +560 -0
  60. data/vendor/assets/javascripts/nvd3/src/models/multiBar.js +442 -0
  61. data/vendor/assets/javascripts/nvd3/src/models/multiBarChart.js +506 -0
  62. data/vendor/assets/javascripts/nvd3/src/models/multiBarHorizontal.js +420 -0
  63. data/vendor/assets/javascripts/nvd3/src/models/multiBarHorizontalChart.js +448 -0
  64. data/vendor/assets/javascripts/nvd3/src/models/multiBarTimeSeries.js +371 -0
  65. data/vendor/assets/javascripts/nvd3/src/models/multiBarTimeSeriesChart.js +403 -0
  66. data/vendor/assets/javascripts/nvd3/src/models/multiChart.js +444 -0
  67. data/vendor/assets/javascripts/nvd3/src/models/ohlcBar.js +365 -0
  68. data/vendor/assets/javascripts/nvd3/src/models/parallelCoordinates.js +238 -0
  69. data/vendor/assets/javascripts/nvd3/src/models/pie.js +386 -0
  70. data/vendor/assets/javascripts/nvd3/src/models/pieChart.js +302 -0
  71. data/vendor/assets/javascripts/nvd3/src/models/scatter.js +660 -0
  72. data/vendor/assets/javascripts/nvd3/src/models/scatterChart.js +614 -0
  73. data/vendor/assets/javascripts/nvd3/src/models/scatterPlusLineChart.js +610 -0
  74. data/vendor/assets/javascripts/nvd3/src/models/sparkline.js +179 -0
  75. data/vendor/assets/javascripts/nvd3/src/models/sparklinePlus.js +293 -0
  76. data/vendor/assets/javascripts/nvd3/src/models/stackedArea.js +336 -0
  77. data/vendor/assets/javascripts/nvd3/src/models/stackedAreaChart.js +490 -0
  78. data/vendor/assets/javascripts/nvd3/src/nv.d3.css +704 -0
  79. data/vendor/assets/javascripts/nvd3/src/outro.js +1 -0
  80. data/vendor/assets/javascripts/nvd3/src/tooltip.js +133 -0
  81. data/vendor/assets/javascripts/nvd3/src/utils.js +118 -0
  82. data/vendor/assets/javascripts/set-env.js.erb +1 -0
  83. data/vendor/assets/stylesheets/chartx.css +3 -0
  84. metadata +189 -0
@@ -0,0 +1,660 @@
1
+
2
+ nv.models.scatter = function() {
3
+
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
+ , color = nv.utils.defaultColor() // chooses color
12
+ , id = Math.floor(Math.random() * 100000) //Create semi-unique ID incase user doesn't select one
13
+ , x = d3.scale.linear()
14
+ , y = d3.scale.linear()
15
+ , z = d3.scale.linear() //linear because d3.svg.shape.size is treated as area
16
+ , getX = function(d) { return d.x } // accessor to get the x value
17
+ , getY = function(d) { return d.y } // accessor to get the y value
18
+ , getSize = function(d) { return d.size || 1} // accessor to get the point size
19
+ , getShape = function(d) { return d.shape || 'circle' } // accessor to get point shape
20
+ , onlyCircles = true // Set to false to use shapes
21
+ , forceX = [] // List of numbers to Force into the X scale (ie. 0, or a max / min, etc.)
22
+ , forceY = [] // List of numbers to Force into the Y scale
23
+ , forceSize = [] // List of numbers to Force into the Size scale
24
+ , interactive = true // If true, plots a voronoi overlay for advanced point intersection
25
+ , pointKey = null
26
+ , pointActive = function(d) { return !d.notActive } // any points that return false will be filtered out
27
+ , padData = false // If true, adds half a data points width to front and back, for lining up a line chart with a bar chart
28
+ , padDataOuter = .1 //outerPadding to imitate ordinal scale outer padding
29
+ , clipEdge = false // if true, masks points within x and y scale
30
+ , clipVoronoi = true // if true, masks each point with a circle... can turn off to slightly increase performance
31
+ , clipRadius = function() { return 25 } // function to get the radius for voronoi point clips
32
+ , xDomain = null // Override x domain (skips the calculation from data)
33
+ , yDomain = null // Override y domain
34
+ , sizeDomain = null // Override point size domain
35
+ , sizeRange = null
36
+ , singlePoint = false
37
+ , dispatch = d3.dispatch('elementClick', 'elementMouseover', 'elementMouseout')
38
+ , useVoronoi = true
39
+ ;
40
+
41
+ //============================================================
42
+
43
+
44
+ //============================================================
45
+ // Private Variables
46
+ //------------------------------------------------------------
47
+
48
+ var x0, y0, z0 // used to store previous scales
49
+ , timeoutID
50
+ , needsUpdate = false // Flag for when the points are visually updating, but the interactive layer is behind, to disable tooltips
51
+ ;
52
+
53
+ //============================================================
54
+
55
+
56
+ function chart(selection) {
57
+ selection.each(function(data) {
58
+ var availableWidth = width - margin.left - margin.right,
59
+ availableHeight = height - margin.top - margin.bottom,
60
+ container = d3.select(this);
61
+
62
+ //add series index to each data point for reference
63
+ data = data.map(function(series, i) {
64
+ series.values = series.values.map(function(point) {
65
+ point.series = i;
66
+ return point;
67
+ });
68
+ return series;
69
+ });
70
+
71
+ //------------------------------------------------------------
72
+ // Setup Scales
73
+
74
+ // remap and flatten the data for use in calculating the scales' domains
75
+ var seriesData = (xDomain && yDomain && sizeDomain) ? [] : // if we know xDomain and yDomain and sizeDomain, no need to calculate.... if Size is constant remember to set sizeDomain to speed up performance
76
+ d3.merge(
77
+ data.map(function(d) {
78
+ return d.values.map(function(d,i) {
79
+ return { x: getX(d,i), y: getY(d,i), size: getSize(d,i) }
80
+ })
81
+ })
82
+ );
83
+
84
+ x .domain(xDomain || d3.extent(seriesData.map(function(d) { return d.x; }).concat(forceX)))
85
+
86
+ if (padData && data[0])
87
+ x.range([(availableWidth * padDataOuter + availableWidth) / (2 *data[0].values.length), availableWidth - availableWidth * (1 + padDataOuter) / (2 * data[0].values.length) ]);
88
+ //x.range([availableWidth * .5 / data[0].values.length, availableWidth * (data[0].values.length - .5) / data[0].values.length ]);
89
+ else
90
+ x.range([0, availableWidth]);
91
+
92
+ y .domain(yDomain || d3.extent(seriesData.map(function(d) { return d.y }).concat(forceY)))
93
+ .range([availableHeight, 0]);
94
+
95
+ z .domain(sizeDomain || d3.extent(seriesData.map(function(d) { return d.size }).concat(forceSize)))
96
+ .range(sizeRange || [16, 256]);
97
+
98
+ // If scale's domain don't have a range, slightly adjust to make one... so a chart can show a single data point
99
+ if (x.domain()[0] === x.domain()[1] || y.domain()[0] === y.domain()[1]) singlePoint = true;
100
+ if (x.domain()[0] === x.domain()[1])
101
+ x.domain()[0] ?
102
+ x.domain([x.domain()[0] - x.domain()[0] * 0.01, x.domain()[1] + x.domain()[1] * 0.01])
103
+ : x.domain([-1,1]);
104
+
105
+ if (y.domain()[0] === y.domain()[1])
106
+ y.domain()[0] ?
107
+ y.domain([y.domain()[0] + y.domain()[0] * 0.01, y.domain()[1] - y.domain()[1] * 0.01])
108
+ : y.domain([-1,1]);
109
+
110
+ if ( isNaN(x.domain()[0])) {
111
+ x.domain([-1,1]);
112
+ }
113
+
114
+ if ( isNaN(y.domain()[0])) {
115
+ y.domain([-1,1]);
116
+ }
117
+
118
+
119
+ x0 = x0 || x;
120
+ y0 = y0 || y;
121
+ z0 = z0 || z;
122
+
123
+ //------------------------------------------------------------
124
+
125
+
126
+ //------------------------------------------------------------
127
+ // Setup containers and skeleton of chart
128
+
129
+ var wrap = container.selectAll('g.nv-wrap.nv-scatter').data([data]);
130
+ var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-scatter nv-chart-' + id + (singlePoint ? ' nv-single-point' : ''));
131
+ var defsEnter = wrapEnter.append('defs');
132
+ var gEnter = wrapEnter.append('g');
133
+ var g = wrap.select('g');
134
+
135
+ gEnter.append('g').attr('class', 'nv-groups');
136
+ gEnter.append('g').attr('class', 'nv-point-paths');
137
+
138
+ wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
139
+
140
+ //------------------------------------------------------------
141
+
142
+
143
+ defsEnter.append('clipPath')
144
+ .attr('id', 'nv-edge-clip-' + id)
145
+ .append('rect');
146
+
147
+ wrap.select('#nv-edge-clip-' + id + ' rect')
148
+ .attr('width', availableWidth)
149
+ .attr('height', availableHeight);
150
+
151
+ g .attr('clip-path', clipEdge ? 'url(#nv-edge-clip-' + id + ')' : '');
152
+
153
+
154
+ function updateInteractiveLayer() {
155
+
156
+ if (!interactive) return false;
157
+
158
+ var eventElements;
159
+
160
+ var vertices = d3.merge(data.map(function(group, groupIndex) {
161
+ return group.values
162
+ .map(function(point, pointIndex) {
163
+ // *Adding noise to make duplicates very unlikely
164
+ // *Injecting series and point index for reference
165
+ /* *Adding a 'jitter' to the points, because there's an issue in d3.geom.voronoi.
166
+ */
167
+ var pX = getX(point,pointIndex) + Math.random() * 1e-7;
168
+ var pY = getY(point,pointIndex) + Math.random() * 1e-7;
169
+
170
+ return [x(pX),
171
+ y(pY),
172
+ groupIndex,
173
+ pointIndex, point]; //temp hack to add noise untill I think of a better way so there are no duplicates
174
+ })
175
+ .filter(function(pointArray, pointIndex) {
176
+ return pointActive(pointArray[4], pointIndex); // Issue #237.. move filter to after map, so pointIndex is correct!
177
+ })
178
+ })
179
+ );
180
+
181
+
182
+
183
+ //inject series and point index for reference into voronoi
184
+ if (useVoronoi === true) {
185
+
186
+ if (clipVoronoi) {
187
+ var pointClipsEnter = wrap.select('defs').selectAll('.nv-point-clips')
188
+ .data([id])
189
+ .enter();
190
+
191
+ pointClipsEnter.append('clipPath')
192
+ .attr('class', 'nv-point-clips')
193
+ .attr('id', 'nv-points-clip-' + id);
194
+
195
+ var pointClips = wrap.select('#nv-points-clip-' + id).selectAll('circle')
196
+ .data(vertices);
197
+ pointClips.enter().append('circle')
198
+ .attr('r', clipRadius);
199
+ pointClips.exit().remove();
200
+ pointClips
201
+ .attr('cx', function(d) { return d[0] })
202
+ .attr('cy', function(d) { return d[1] });
203
+
204
+ wrap.select('.nv-point-paths')
205
+ .attr('clip-path', 'url(#nv-points-clip-' + id + ')');
206
+ }
207
+
208
+
209
+ if(vertices.length) {
210
+ // Issue #283 - Adding 2 dummy points to the voronoi b/c voronoi requires min 3 points to work
211
+ vertices.push([x.range()[0] - 20, y.range()[0] - 20, null, null]);
212
+ vertices.push([x.range()[1] + 20, y.range()[1] + 20, null, null]);
213
+ vertices.push([x.range()[0] - 20, y.range()[0] + 20, null, null]);
214
+ vertices.push([x.range()[1] + 20, y.range()[1] - 20, null, null]);
215
+ }
216
+
217
+ var bounds = d3.geom.polygon([
218
+ [-10,-10],
219
+ [-10,height + 10],
220
+ [width + 10,height + 10],
221
+ [width + 10,-10]
222
+ ]);
223
+
224
+ var voronoi = d3.geom.voronoi(vertices).map(function(d, i) {
225
+ return {
226
+ 'data': bounds.clip(d),
227
+ 'series': vertices[i][2],
228
+ 'point': vertices[i][3]
229
+ }
230
+ });
231
+
232
+
233
+ var pointPaths = wrap.select('.nv-point-paths').selectAll('path')
234
+ .data(voronoi);
235
+ pointPaths.enter().append('path')
236
+ .attr('class', function(d,i) { return 'nv-path-'+i; });
237
+ pointPaths.exit().remove();
238
+ pointPaths
239
+ .attr('d', function(d) {
240
+ if (d.data.length === 0)
241
+ return 'M 0 0'
242
+ else
243
+ return 'M' + d.data.join('L') + 'Z';
244
+ });
245
+
246
+ pointPaths
247
+ .on('click', function(d) {
248
+ if (needsUpdate) return 0;
249
+ var series = data[d.series],
250
+ point = series.values[d.point];
251
+
252
+ dispatch.elementClick({
253
+ point: point,
254
+ series: series,
255
+ pos: [x(getX(point, d.point)) + margin.left, y(getY(point, d.point)) + margin.top],
256
+ seriesIndex: d.series,
257
+ pointIndex: d.point
258
+ });
259
+ })
260
+ .on('mouseover', function(d) {
261
+ if (needsUpdate) return 0;
262
+ var series = data[d.series],
263
+ point = series.values[d.point];
264
+
265
+ dispatch.elementMouseover({
266
+ point: point,
267
+ series: series,
268
+ pos: [x(getX(point, d.point)) + margin.left, y(getY(point, d.point)) + margin.top],
269
+ seriesIndex: d.series,
270
+ pointIndex: d.point
271
+ });
272
+ })
273
+ .on('mouseout', function(d, i) {
274
+ if (needsUpdate) return 0;
275
+ var series = data[d.series],
276
+ point = series.values[d.point];
277
+
278
+ dispatch.elementMouseout({
279
+ point: point,
280
+ series: series,
281
+ seriesIndex: d.series,
282
+ pointIndex: d.point
283
+ });
284
+ });
285
+
286
+
287
+ } else {
288
+ /*
289
+ // bring data in form needed for click handlers
290
+ var dataWithPoints = vertices.map(function(d, i) {
291
+ return {
292
+ 'data': d,
293
+ 'series': vertices[i][2],
294
+ 'point': vertices[i][3]
295
+ }
296
+ });
297
+ */
298
+
299
+ // add event handlers to points instead voronoi paths
300
+ wrap.select('.nv-groups').selectAll('.nv-group')
301
+ .selectAll('.nv-point')
302
+ //.data(dataWithPoints)
303
+ //.style('pointer-events', 'auto') // recativate events, disabled by css
304
+ .on('click', function(d,i) {
305
+ //nv.log('test', d, i);
306
+ if (needsUpdate || !data[d.series]) return 0; //check if this is a dummy point
307
+ var series = data[d.series],
308
+ point = series.values[i];
309
+
310
+ dispatch.elementClick({
311
+ point: point,
312
+ series: series,
313
+ pos: [x(getX(point, i)) + margin.left, y(getY(point, i)) + margin.top],
314
+ seriesIndex: d.series,
315
+ pointIndex: i
316
+ });
317
+ })
318
+ .on('mouseover', function(d,i) {
319
+ if (needsUpdate || !data[d.series]) return 0; //check if this is a dummy point
320
+ var series = data[d.series],
321
+ point = series.values[i];
322
+
323
+ dispatch.elementMouseover({
324
+ point: point,
325
+ series: series,
326
+ pos: [x(getX(point, i)) + margin.left, y(getY(point, i)) + margin.top],
327
+ seriesIndex: d.series,
328
+ pointIndex: i
329
+ });
330
+ })
331
+ .on('mouseout', function(d,i) {
332
+ if (needsUpdate || !data[d.series]) return 0; //check if this is a dummy point
333
+ var series = data[d.series],
334
+ point = series.values[i];
335
+
336
+ dispatch.elementMouseout({
337
+ point: point,
338
+ series: series,
339
+ seriesIndex: d.series,
340
+ pointIndex: i
341
+ });
342
+ });
343
+ }
344
+
345
+ needsUpdate = false;
346
+ }
347
+
348
+ needsUpdate = true;
349
+
350
+ var groups = wrap.select('.nv-groups').selectAll('.nv-group')
351
+ .data(function(d) { return d }, function(d) { return d.key });
352
+ groups.enter().append('g')
353
+ .style('stroke-opacity', 1e-6)
354
+ .style('fill-opacity', 1e-6);
355
+ d3.transition(groups.exit())
356
+ .style('stroke-opacity', 1e-6)
357
+ .style('fill-opacity', 1e-6)
358
+ .remove();
359
+ groups
360
+ .attr('class', function(d,i) { return 'nv-group nv-series-' + i })
361
+ .classed('hover', function(d) { return d.hover });
362
+ d3.transition(groups)
363
+ .style('fill', function(d,i) { return color(d, i) })
364
+ .style('stroke', function(d,i) { return color(d, i) })
365
+ .style('stroke-opacity', 1)
366
+ .style('fill-opacity', .5);
367
+
368
+
369
+ if (onlyCircles) {
370
+
371
+ var points = groups.selectAll('circle.nv-point')
372
+ .data(function(d) { return d.values }, pointKey);
373
+ points.enter().append('circle')
374
+ .attr('cx', function(d,i) { return x0(getX(d,i)) })
375
+ .attr('cy', function(d,i) { return y0(getY(d,i)) })
376
+ .attr('r', function(d,i) { return Math.sqrt(z(getSize(d,i))/Math.PI) });
377
+ points.exit().remove();
378
+ groups.exit().selectAll('path.nv-point').transition()
379
+ .attr('cx', function(d,i) { return x(getX(d,i)) })
380
+ .attr('cy', function(d,i) { return y(getY(d,i)) })
381
+ .remove();
382
+ points.each(function(d,i) {
383
+ d3.select(this)
384
+ .classed('nv-point', true)
385
+ .classed('nv-point-' + i, true);
386
+ });
387
+ points.transition()
388
+ .attr('cx', function(d,i) { return x(getX(d,i)) })
389
+ .attr('cy', function(d,i) { return y(getY(d,i)) })
390
+ .attr('r', function(d,i) { return Math.sqrt(z(getSize(d,i))/Math.PI) });
391
+
392
+ } else {
393
+
394
+ var points = groups.selectAll('path.nv-point')
395
+ .data(function(d) { return d.values });
396
+ points.enter().append('path')
397
+ .attr('transform', function(d,i) {
398
+ return 'translate(' + x0(getX(d,i)) + ',' + y0(getY(d,i)) + ')'
399
+ })
400
+ .attr('d',
401
+ d3.svg.symbol()
402
+ .type(getShape)
403
+ .size(function(d,i) { return z(getSize(d,i)) })
404
+ );
405
+ points.exit().remove();
406
+ d3.transition(groups.exit().selectAll('path.nv-point'))
407
+ .attr('transform', function(d,i) {
408
+ return 'translate(' + x(getX(d,i)) + ',' + y(getY(d,i)) + ')'
409
+ })
410
+ .remove();
411
+ points.each(function(d,i) {
412
+ d3.select(this)
413
+ .classed('nv-point', true)
414
+ .classed('nv-point-' + i, true);
415
+ });
416
+ points.transition()
417
+ .attr('transform', function(d,i) {
418
+ //nv.log(d,i,getX(d,i), x(getX(d,i)));
419
+ return 'translate(' + x(getX(d,i)) + ',' + y(getY(d,i)) + ')'
420
+ })
421
+ .attr('d',
422
+ d3.svg.symbol()
423
+ .type(getShape)
424
+ .size(function(d,i) { return z(getSize(d,i)) })
425
+ );
426
+ }
427
+
428
+
429
+ // Delay updating the invisible interactive layer for smoother animation
430
+ clearTimeout(timeoutID); // stop repeat calls to updateInteractiveLayer
431
+ timeoutID = setTimeout(updateInteractiveLayer, 300);
432
+ //updateInteractiveLayer();
433
+
434
+ //store old scales for use in transitions on update
435
+ x0 = x.copy();
436
+ y0 = y.copy();
437
+ z0 = z.copy();
438
+
439
+ });
440
+
441
+ return chart;
442
+ }
443
+
444
+
445
+ //============================================================
446
+ // Event Handling/Dispatching (out of chart's scope)
447
+ //------------------------------------------------------------
448
+
449
+ dispatch.on('elementMouseover.point', function(d) {
450
+ if (interactive)
451
+ d3.select('.nv-chart-' + id + ' .nv-series-' + d.seriesIndex + ' .nv-point-' + d.pointIndex)
452
+ .classed('hover', true);
453
+ });
454
+
455
+ dispatch.on('elementMouseout.point', function(d) {
456
+ if (interactive)
457
+ d3.select('.nv-chart-' + id + ' .nv-series-' + d.seriesIndex + ' .nv-point-' + d.pointIndex)
458
+ .classed('hover', false);
459
+ });
460
+
461
+ //============================================================
462
+
463
+
464
+ //============================================================
465
+ // Expose Public Variables
466
+ //------------------------------------------------------------
467
+
468
+ chart.dispatch = dispatch;
469
+
470
+ chart.x = function(_) {
471
+ if (!arguments.length) return getX;
472
+ getX = d3.functor(_);
473
+ return chart;
474
+ };
475
+
476
+ chart.y = function(_) {
477
+ if (!arguments.length) return getY;
478
+ getY = d3.functor(_);
479
+ return chart;
480
+ };
481
+
482
+ chart.size = function(_) {
483
+ if (!arguments.length) return getSize;
484
+ getSize = d3.functor(_);
485
+ return chart;
486
+ };
487
+
488
+ chart.margin = function(_) {
489
+ if (!arguments.length) return margin;
490
+ margin.top = typeof _.top != 'undefined' ? _.top : margin.top;
491
+ margin.right = typeof _.right != 'undefined' ? _.right : margin.right;
492
+ margin.bottom = typeof _.bottom != 'undefined' ? _.bottom : margin.bottom;
493
+ margin.left = typeof _.left != 'undefined' ? _.left : margin.left;
494
+ return chart;
495
+ };
496
+
497
+ chart.width = function(_) {
498
+ if (!arguments.length) return width;
499
+ width = _;
500
+ return chart;
501
+ };
502
+
503
+ chart.height = function(_) {
504
+ if (!arguments.length) return height;
505
+ height = _;
506
+ return chart;
507
+ };
508
+
509
+ chart.xScale = function(_) {
510
+ if (!arguments.length) return x;
511
+ x = _;
512
+ return chart;
513
+ };
514
+
515
+ chart.yScale = function(_) {
516
+ if (!arguments.length) return y;
517
+ y = _;
518
+ return chart;
519
+ };
520
+
521
+ chart.zScale = function(_) {
522
+ if (!arguments.length) return z;
523
+ z = _;
524
+ return chart;
525
+ };
526
+
527
+ chart.xDomain = function(_) {
528
+ if (!arguments.length) return xDomain;
529
+ xDomain = _;
530
+ return chart;
531
+ };
532
+
533
+ chart.yDomain = function(_) {
534
+ if (!arguments.length) return yDomain;
535
+ yDomain = _;
536
+ return chart;
537
+ };
538
+
539
+ chart.sizeDomain = function(_) {
540
+ if (!arguments.length) return sizeDomain;
541
+ sizeDomain = _;
542
+ return chart;
543
+ };
544
+
545
+ chart.sizeRange = function(_) {
546
+ if (!arguments.length) return sizeRange;
547
+ sizeRange = _;
548
+ return chart;
549
+ };
550
+
551
+ chart.forceX = function(_) {
552
+ if (!arguments.length) return forceX;
553
+ forceX = _;
554
+ return chart;
555
+ };
556
+
557
+ chart.forceY = function(_) {
558
+ if (!arguments.length) return forceY;
559
+ forceY = _;
560
+ return chart;
561
+ };
562
+
563
+ chart.forceSize = function(_) {
564
+ if (!arguments.length) return forceSize;
565
+ forceSize = _;
566
+ return chart;
567
+ };
568
+
569
+ chart.interactive = function(_) {
570
+ if (!arguments.length) return interactive;
571
+ interactive = _;
572
+ return chart;
573
+ };
574
+
575
+ chart.pointKey = function(_) {
576
+ if (!arguments.length) return pointKey;
577
+ pointKey = _;
578
+ return chart;
579
+ };
580
+
581
+ chart.pointActive = function(_) {
582
+ if (!arguments.length) return pointActive;
583
+ pointActive = _;
584
+ return chart;
585
+ };
586
+
587
+ chart.padData = function(_) {
588
+ if (!arguments.length) return padData;
589
+ padData = _;
590
+ return chart;
591
+ };
592
+
593
+ chart.padDataOuter = function(_) {
594
+ if (!arguments.length) return padDataOuter;
595
+ padDataOuter = _;
596
+ return chart;
597
+ };
598
+
599
+ chart.clipEdge = function(_) {
600
+ if (!arguments.length) return clipEdge;
601
+ clipEdge = _;
602
+ return chart;
603
+ };
604
+
605
+ chart.clipVoronoi= function(_) {
606
+ if (!arguments.length) return clipVoronoi;
607
+ clipVoronoi = _;
608
+ return chart;
609
+ };
610
+
611
+ chart.useVoronoi= function(_) {
612
+ if (!arguments.length) return useVoronoi;
613
+ useVoronoi = _;
614
+ if (useVoronoi === false) {
615
+ clipVoronoi = false;
616
+ }
617
+ return chart;
618
+ };
619
+
620
+ chart.clipRadius = function(_) {
621
+ if (!arguments.length) return clipRadius;
622
+ clipRadius = _;
623
+ return chart;
624
+ };
625
+
626
+ chart.color = function(_) {
627
+ if (!arguments.length) return color;
628
+ color = nv.utils.getColor(_);
629
+ return chart;
630
+ };
631
+
632
+ chart.shape = function(_) {
633
+ if (!arguments.length) return getShape;
634
+ getShape = _;
635
+ return chart;
636
+ };
637
+
638
+ chart.onlyCircles = function(_) {
639
+ if (!arguments.length) return onlyCircles;
640
+ onlyCircles = _;
641
+ return chart;
642
+ };
643
+
644
+ chart.id = function(_) {
645
+ if (!arguments.length) return id;
646
+ id = _;
647
+ return chart;
648
+ };
649
+
650
+ chart.singlePoint = function(_) {
651
+ if (!arguments.length) return singlePoint;
652
+ singlePoint = _;
653
+ return chart;
654
+ };
655
+
656
+ //============================================================
657
+
658
+
659
+ return chart;
660
+ }