-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdc-canvas-scatterplot-d3v4.js
681 lines (610 loc) · 24.9 KB
/
dc-canvas-scatterplot-d3v4.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
/**
* A scatter plot chart
*
* Examples:
* - {@link http://dc-js.github.io/dc.js/examples/scatter.html Scatter Chart}
* - {@link http://dc-js.github.io/dc.js/examples/multi-scatter.html Multi-Scatter Chart}
* @class scatterPlot
* @memberof dc
* @mixes dc.coordinateGridMixin
* @example
* // create a scatter plot under #chart-container1 element using the default global chart group
* var chart1 = dc.scatterPlot('#chart-container1');
* // create a scatter plot under #chart-container2 element using chart group A
* var chart2 = dc.scatterPlot('#chart-container2', 'chartGroupA');
* // create a sub-chart under a composite parent chart
* var chart3 = dc.scatterPlot(compositeChart);
* @param {String|node|d3.selection} parent - Any valid
* {@link https://github.com/d3/d3-3.x-api-reference/blob/master/Selections.md#selecting-elements d3 single selector} specifying
* a dom block element such as a div; or a dom element or d3 selection.
* @param {String} [chartGroup] - The name of the chart group this chart instance should be placed in.
* Interaction with a chart will only trigger events and redraws within the chart's group.
* @returns {dc.scatterPlot}
*/
dc.scatterPlot = function (parent, chartGroup) {
var _chart = dc.coordinateGridMixin({});
var _symbol = d3.symbol();
var _existenceAccessor = function (d) { return d.value; };
var originalKeyAccessor = _chart.keyAccessor();
_chart.keyAccessor(function (d) { return originalKeyAccessor(d)[0]; });
_chart.valueAccessor(function (d) { return originalKeyAccessor(d)[1]; });
_chart.colorAccessor(function () { return _chart._groupName; });
_chart.title(function (d) {
// this basically just counteracts the setting of its own key/value accessors
// see https://github.com/dc-js/dc.js/issues/702
return _chart.keyAccessor()(d) + ',' + _chart.valueAccessor()(d) + ': ' +
_chart.existenceAccessor()(d);
});
var _locator = function (d) {
return 'translate(' + _chart.x()(_chart.keyAccessor()(d)) + ',' +
_chart.y()(_chart.valueAccessor()(d)) + ')';
};
var _highlightedSize = 7;
var _symbolSize = 5;
var _excludedSize = 3;
var _excludedColor = null;
var _excludedOpacity = 1.0;
var _emptySize = 0;
var _emptyOpacity = 0;
var _nonemptyOpacity = 1;
var _emptyColor = null;
var _filtered = [];
var _canvas = null;
var _context = null;
var _useCanvas = false;
// Use a 2 dimensional brush
_chart.brush(d3.brush());
// Calculates element radius for canvas plot to be comparable to D3 area based symbol sizes
function canvasElementSize (d, isFiltered) {
if (!_existenceAccessor(d)) {
return _emptySize / Math.sqrt(Math.PI);
} else if (isFiltered) {
return _symbolSize / Math.sqrt(Math.PI);
} else {
return _excludedSize / Math.sqrt(Math.PI);
}
}
function elementSize (d, i) {
if (!_existenceAccessor(d)) {
return Math.pow(_emptySize, 2);
} else if (_filtered[i]) {
return Math.pow(_symbolSize, 2);
} else {
return Math.pow(_excludedSize, 2);
}
}
_symbol.size(elementSize);
dc.override(_chart, '_filter', function (filter) {
if (!arguments.length) {
return _chart.__filter();
}
return _chart.__filter(dc.filters.RangedTwoDimensionalFilter(filter));
});
_chart._resetSvgOld = _chart.resetSvg; // Copy original closure from base-mixin
/**
* Method that replaces original resetSvg and appropriately inserts canvas
* element along with svg element and sets their CSS properties appropriately
* so they are overlapped on top of each other.
* Remove the chart's SVGElements from the dom and recreate the container SVGElement.
* @method resetSvg
* @memberof dc.scatterPlot
* @instance
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/SVGElement SVGElement}
* @returns {SVGElement}
*/
_chart.resetSvg = function () {
if (!_useCanvas) {
return _chart._resetSvgOld();
} else {
_chart._resetSvgOld(); // Perform original svgReset inherited from baseMixin
_chart.select('canvas').remove(); // remove old canvas
var svgSel = _chart.svg();
var rootSel = _chart.root();
// Set root node to relative positioning and svg to absolute
rootSel.style('position', 'relative');
svgSel.style('position', 'relative');
// Check if SVG element already has any extra top/left CSS offsets
var svgLeft = isNaN(parseInt(svgSel.style('left'), 10)) ? 0 : parseInt(svgSel.style('left'), 10);
var svgTop = isNaN(parseInt(svgSel.style('top'), 10)) ? 0 : parseInt(svgSel.style('top'), 10);
var width = _chart.effectiveWidth();
var height = _chart.effectiveHeight();
var margins = _chart.margins(); // {top: 10, right: 130, bottom: 42, left: 42}
// Add the canvas element such that it perfectly overlaps the plot area of the scatter plot SVG
var devicePixelRatio = window.devicePixelRatio || 1;
_canvas = _chart.root().append('canvas')
.attr('x', 0)
.attr('y', 0)
.attr('width', (width) * devicePixelRatio)
.attr('height', (height) * devicePixelRatio)
.style('width', width + 'px')
.style('height', height + 'px')
.style('position', 'absolute')
.style('top', margins.top + svgTop + 'px')
.style('left', margins.left + svgLeft + 'px')
.style('pointer-events', 'none'); // Disable pointer events on canvas so SVG can capture brushing
// Define canvas context and set clipping path
_context = _canvas.node().getContext('2d');
_context.scale(devicePixelRatio, devicePixelRatio);
_context.rect(0, 0, width, height);
_context.clip(); // Setup clipping path
_context.imageSmoothingQuality = 'high';
return _chart.svg(); // Respect original return param for _chart.resetSvg;
}
};
/**
* Set or get whether to use canvas backend for plotting scatterPlot. Note that the
* canvas backend does not currently support
* {@link dc.scatterPlot#customSymbol customSymbol} or
* {@link dc.scatterPlot#symbol symbol} methods and is limited to always plotting
* with filled circles. Symbols are drawn with
* {@link dc.scatterPlot#symbolSize symbolSize} radius. By default, the SVG backend
* is used when `useCanvas` is set to `false`.
* @method useCanvas
* @memberof dc.scatterPlot
* @instance
* @param {Boolean} [useCanvas=false]
* @return {Boolean|d3.selection}
*/
_chart.useCanvas = function (useCanvas) {
if (!arguments.length) {
return _useCanvas;
}
_useCanvas = useCanvas;
return _chart;
};
/**
* Set or get canvas element. You should usually only ever use the get method as
* dc.js will handle canvas element generation. Provides valid canvas only when
* {@link dc.scatterPlot#useCanvas useCanvas} is set to `true`
* @method canvas
* @memberof dc.scatterPlot
* @instance
* @param {CanvasElement|d3.selection} [canvasElement]
* @return {CanvasElement|d3.selection}
*/
_chart.canvas = function (canvasElement) {
if (!arguments.length) {
return _canvas;
}
_canvas = canvasElement;
return _chart;
};
/**
* Get canvas 2D context. Provides valid context only when
* {@link dc.scatterPlot#useCanvas useCanvas} is set to `true`
* @method context
* @memberof dc.scatterPlot
* @instance
* @return {CanvasContext}
*/
_chart.context = function () {
return _context;
};
// Plots data on canvas element. If argument provided, assumes legend is
// currently being highlighted and modifies opacity/size of symbols accordingly
// @param {Object} [legendHighlightDatum] - Datum provided to legendHighlight method
function plotOnCanvas (legendHighlightDatum) {
var context = _chart.context();
context.clearRect(0, 0, (context.canvas.width + 2) * 1, (context.canvas.height + 2) * 1);
var data = _chart.data();
// Draw the data on canvas
data.forEach(function (d, i) {
var isFiltered = !_chart.filter() || _chart.filter().isFiltered([d.key[0], d.key[1]]);
// Calculate opacity for current data point
var cOpacity = 1;
if (!_existenceAccessor(d)) {
cOpacity = _emptyOpacity;
} else if (isFiltered) {
cOpacity = _nonemptyOpacity;
} else {
cOpacity = _chart.excludedOpacity();
}
// Calculate color for current data point
var cColor = null;
if (_emptyColor && !_existenceAccessor(d)) {
cColor = _emptyColor;
} else if (_chart.excludedColor() && !isFiltered) {
cColor = _chart.excludedColor();
} else {
cColor = _chart.getColor(d);
}
var cSize = canvasElementSize(d, isFiltered);
// Adjust params for data points if legend is highlighted
if (legendHighlightDatum) {
var isHighlighted = (cColor === legendHighlightDatum.color);
// Calculate opacity for current data point
var fadeOutOpacity = 0.1; // TODO: Make this programmatically setable
if (!isHighlighted) { // Fade out non-highlighted colors + highlighted colors outside filter
cOpacity = fadeOutOpacity;
}
if (isHighlighted) { // Set size for highlighted color data points
cSize = _highlightedSize / Math.sqrt(Math.PI);
}
}
// Draw point on canvas
context.save();
context.globalAlpha = cOpacity;
context.beginPath();
context.arc(_chart.x()(_chart.keyAccessor()(d)), _chart.y()(_chart.valueAccessor()(d)), cSize, 0, 2 * Math.PI, true);
context.fillStyle = cColor;
context.fill();
// context.lineWidth = 0.5; // Commented out code to add stroke around scatter points if desired
// context.strokeStyle = '#333';
// context.stroke();
context.restore();
});
}
_chart.plotData = function () {
if (_useCanvas) {
plotOnCanvas();
} else {
var symbols = _chart.chartBodyG().selectAll('path.symbol')
.data(_chart.data());
symbols
.enter()
.append('path')
.attr('class', 'symbol')
.attr('opacity', 0)
.attr('fill', _chart.getColor)
.attr('transform', _locator);
symbols.call(renderTitles, _chart.data());
symbols.each(function (d, i) {
_filtered[i] = !_chart.filter() || _chart.filter().isFiltered([d.key[0], d.key[1]]);
});
dc.transition(symbols, _chart.transitionDuration(), _chart.transitionDelay())
.attr('opacity', function (d, i) {
if (!_existenceAccessor(d)) {
return _emptyOpacity;
} else if (_filtered[i]) {
return _nonemptyOpacity;
} else {
return _chart.excludedOpacity();
}
})
.attr('fill', function (d, i) {
if (_emptyColor && !_existenceAccessor(d)) {
return _emptyColor;
} else if (_chart.excludedColor() && !_filtered[i]) {
return _chart.excludedColor();
} else {
return _chart.getColor(d);
}
})
.attr('transform', _locator)
.attr('d', _symbol);
dc.transition(symbols.exit(), _chart.transitionDuration(), _chart.transitionDelay())
.attr('opacity', 0).remove();
}
};
function renderTitles (symbol, d) {
if (_chart.renderTitle()) {
symbol.selectAll('title').remove();
symbol.append('title').text(function (d) {
return _chart.title()(d);
});
}
}
/**
* Get or set the existence accessor. If a point exists, it is drawn with
* {@link dc.scatterPlot#symbolSize symbolSize} radius and
* opacity 1; if it does not exist, it is drawn with
* {@link dc.scatterPlot#emptySize emptySize} radius and opacity 0. By default,
* the existence accessor checks if the reduced value is truthy.
* @method existenceAccessor
* @memberof dc.scatterPlot
* @instance
* @see {@link dc.scatterPlot#symbolSize symbolSize}
* @see {@link dc.scatterPlot#emptySize emptySize}
* @example
* // default accessor
* chart.existenceAccessor(function (d) { return d.value; });
* @param {Function} [accessor]
* @returns {Function|dc.scatterPlot}
*/
_chart.existenceAccessor = function (accessor) {
if (!arguments.length) {
return _existenceAccessor;
}
_existenceAccessor = accessor;
return this;
};
/**
* Get or set the symbol type used for each point. By default the symbol is a circle.
* Type can be a constant or an accessor.
* @method symbol
* @memberof dc.scatterPlot
* @instance
* @see {@link https://github.com/d3/d3-3.x-api-reference/blob/master/SVG-Shapes.md#symbol_type d3.svg.symbol.type}
* @example
* // Circle type
* chart.symbol('circle');
* // Square type
* chart.symbol('square');
* @param {String|Function} [type='circle']
* @returns {String|Function|dc.scatterPlot}
*/
_chart.symbol = function (type) {
if (!arguments.length) {
return _symbol.type();
}
_symbol.type(type);
return _chart;
};
/**
* Get or set the symbol generator. By default `dc.scatterPlot` will use
* {@link https://github.com/d3/d3-3.x-api-reference/blob/master/SVG-Shapes.md#symbol d3.svg.symbol()}
* to generate symbols. `dc.scatterPlot` will set the
* {@link https://github.com/d3/d3-3.x-api-reference/blob/master/SVG-Shapes.md#symbol_size size accessor}
* on the symbol generator.
* @method customSymbol
* @memberof dc.scatterPlot
* @instance
* @see {@link https://github.com/d3/d3-3.x-api-reference/blob/master/SVG-Shapes.md#symbol d3.svg.symbol}
* @see {@link https://stackoverflow.com/questions/25332120/create-additional-d3-js-symbols Create additional D3.js symbols}
* @param {String|Function} [customSymbol=d3.svg.symbol()]
* @returns {String|Function|dc.scatterPlot}
*/
_chart.customSymbol = function (customSymbol) {
if (!arguments.length) {
return _symbol;
}
_symbol = customSymbol;
_symbol.size(elementSize);
return _chart;
};
/**
* Set or get radius for symbols.
* @method symbolSize
* @memberof dc.scatterPlot
* @instance
* @see {@link https://github.com/d3/d3-3.x-api-reference/blob/master/SVG-Shapes.md#symbol_size d3.svg.symbol.size}
* @param {Number} [symbolSize=3]
* @returns {Number|dc.scatterPlot}
*/
_chart.symbolSize = function (symbolSize) {
if (!arguments.length) {
return _symbolSize;
}
_symbolSize = symbolSize;
return _chart;
};
/**
* Set or get radius for highlighted symbols.
* @method highlightedSize
* @memberof dc.scatterPlot
* @instance
* @see {@link https://github.com/d3/d3-3.x-api-reference/blob/master/SVG-Shapes.md#symbol_size d3.svg.symbol.size}
* @param {Number} [highlightedSize=5]
* @returns {Number|dc.scatterPlot}
*/
_chart.highlightedSize = function (highlightedSize) {
if (!arguments.length) {
return _highlightedSize;
}
_highlightedSize = highlightedSize;
return _chart;
};
/**
* Set or get size for symbols excluded from this chart's filter. If null, no
* special size is applied for symbols based on their filter status.
* @method excludedSize
* @memberof dc.scatterPlot
* @instance
* @see {@link https://github.com/d3/d3-3.x-api-reference/blob/master/SVG-Shapes.md#symbol_size d3.svg.symbol.size}
* @param {Number} [excludedSize=null]
* @returns {Number|dc.scatterPlot}
*/
_chart.excludedSize = function (excludedSize) {
if (!arguments.length) {
return _excludedSize;
}
_excludedSize = excludedSize;
return _chart;
};
/**
* Set or get color for symbols excluded from this chart's filter. If null, no
* special color is applied for symbols based on their filter status.
* @method excludedColor
* @memberof dc.scatterPlot
* @instance
* @param {Number} [excludedColor=null]
* @returns {Number|dc.scatterPlot}
*/
_chart.excludedColor = function (excludedColor) {
if (!arguments.length) {
return _excludedColor;
}
_excludedColor = excludedColor;
return _chart;
};
/**
* Set or get opacity for symbols excluded from this chart's filter.
* @method excludedOpacity
* @memberof dc.scatterPlot
* @instance
* @param {Number} [excludedOpacity=1.0]
* @returns {Number|dc.scatterPlot}
*/
_chart.excludedOpacity = function (excludedOpacity) {
if (!arguments.length) {
return _excludedOpacity;
}
_excludedOpacity = excludedOpacity;
return _chart;
};
/**
* Set or get radius for symbols when the group is empty.
* @method emptySize
* @memberof dc.scatterPlot
* @instance
* @see {@link https://github.com/d3/d3-3.x-api-reference/blob/master/SVG-Shapes.md#symbol_size d3.svg.symbol.size}
* @param {Number} [emptySize=0]
* @returns {Number|dc.scatterPlot}
*/
_chart.hiddenSize = _chart.emptySize = function (emptySize) {
if (!arguments.length) {
return _emptySize;
}
_emptySize = emptySize;
return _chart;
};
/**
* Set or get color for symbols when the group is empty. If null, just use the
* {@link dc.colorMixin#colors colorMixin.colors} color scale zero value.
* @name emptyColor
* @memberof dc.scatterPlot
* @instance
* @param {String} [emptyColor=null]
* @return {String}
* @return {dc.scatterPlot}/
*/
_chart.emptyColor = function (emptyColor) {
if (!arguments.length) {
return _emptyColor;
}
_emptyColor = emptyColor;
return _chart;
};
/**
* Set or get opacity for symbols when the group is empty.
* @name emptyOpacity
* @memberof dc.scatterPlot
* @instance
* @param {Number} [emptyOpacity=0]
* @return {Number}
* @return {dc.scatterPlot}
*/
_chart.emptyOpacity = function (emptyOpacity) {
if (!arguments.length) {
return _emptyOpacity;
}
_emptyOpacity = emptyOpacity;
return _chart;
};
/**
* Set or get opacity for symbols when the group is not empty.
* @name nonemptyOpacity
* @memberof dc.scatterPlot
* @instance
* @param {Number} [nonemptyOpacity=1]
* @return {Number}
* @return {dc.scatterPlot}
*/
_chart.nonemptyOpacity = function (nonemptyOpacity) {
if (!arguments.length) {
return _emptyOpacity;
}
_nonemptyOpacity = nonemptyOpacity;
return _chart;
};
_chart.legendables = function () {
return [{chart: _chart, name: _chart._groupName, color: _chart.getColor()}];
};
_chart.legendHighlight = function (d) {
if (_useCanvas) {
plotOnCanvas(d); // Supply legend datum to plotOnCanvas
} else {
resizeSymbolsWhere(function (symbol) {
return symbol.attr('fill') === d.color;
}, _highlightedSize);
_chart.chartBodyG().selectAll('.chart-body path.symbol').filter(function () {
return d3.select(this).attr('fill') !== d.color;
}).classed('fadeout', true);
}
};
_chart.legendReset = function (d) {
if (_useCanvas) {
plotOnCanvas();
} else {
resizeSymbolsWhere(function (symbol) {
return symbol.attr('fill') === d.color;
}, _symbolSize);
_chart.chartBodyG().selectAll('.chart-body path.symbol').filter(function () {
return d3.select(this).attr('fill') !== d.color;
}).classed('fadeout', false);
}
};
function resizeSymbolsWhere (condition, size) {
var symbols = _chart.chartBodyG().selectAll('.chart-body path.symbol').filter(function () {
return condition(d3.select(this));
});
var oldSize = _symbol.size();
_symbol.size(Math.pow(size, 2));
dc.transition(symbols, _chart.transitionDuration(), _chart.transitionDelay()).attr('d', _symbol);
_symbol.size(oldSize);
}
_chart.createBrushHandlePaths = function () {
// no handle paths for poly-brushes
};
_chart.extendBrush = function (brushSelection) {
if (_chart.round()) {
brushSelection[0] = brushSelection[0].map(_chart.round());
brushSelection[1] = brushSelection[1].map(_chart.round());
}
return brushSelection;
};
_chart.brushIsEmpty = function (brushSelection) {
return !brushSelection || brushSelection[0][0] >= brushSelection[1][0] || brushSelection[0][1] >= brushSelection[1][1];
};
_chart._brushing = function () {
// Avoids infinite recursion (mutual recursion between range and focus operations)
// Source Event will be null when brush.move is called programmatically (see below as well).
if (!d3.event.sourceEvent) { return; }
// Ignore event if recursive event - i.e. not directly generated by user action (like mouse/touch etc.)
// In this case we are more worried about this handler causing brush move programmatically which will
// cause this handler to be invoked again with a new d3.event (and current event set as sourceEvent)
// This check avoids recursive calls
if (d3.event.sourceEvent.type && ['start', 'brush', 'end'].indexOf(d3.event.sourceEvent.type) !== -1) {
return;
}
var brushSelection = d3.event.selection;
// Testing with pixels is more reliable
var brushIsEmpty = _chart.brushIsEmpty(brushSelection);
if (brushSelection) {
brushSelection = brushSelection.map(function (point) {
return point.map(function (coord, i) {
var scale = i === 0 ? _chart.x() : _chart.y();
return scale.invert(coord);
});
});
brushSelection = _chart.extendBrush(brushSelection);
// The rounding process might have made brushSelection empty, so we need to recheck
brushIsEmpty = brushIsEmpty && _chart.brushIsEmpty(brushSelection);
}
_chart.redrawBrush(brushSelection, false);
var ranged2DFilter = brushIsEmpty ? null : dc.filters.RangedTwoDimensionalFilter(brushSelection);
dc.events.trigger(function () {
_chart.replaceFilter(ranged2DFilter);
_chart.redrawGroup();
}, dc.constants.EVENT_DELAY);
};
_chart.redrawBrush = function (brushSelection, doTransition) {
// override default x axis brush from parent chart
var _brush = _chart.brush();
var _gBrush = _chart.gBrush();
if (_chart.brushOn() && _gBrush) {
if (_chart.resizing()) {
_chart.setBrushExtents(doTransition);
}
if (!brushSelection) {
_gBrush
.call(_brush.move, brushSelection);
} else {
brushSelection = brushSelection.map(function (point) {
return point.map(function (coord, i) {
var scale = i === 0 ? _chart.x() : _chart.y();
return scale(coord);
});
});
var gBrush = dc.optionalTransition(doTransition, _chart.transitionDuration(), _chart.transitionDelay())(_gBrush);
gBrush
.call(_brush.move, brushSelection);
}
}
_chart.fadeDeselectedArea(brushSelection);
};
_chart.setBrushY = function (gBrush) {
gBrush.call(_chart.brush().y(_chart.y()));
};
return _chart.anchor(parent, chartGroup);
};