forked from predixdesignsystem/px-vis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpx-vis-interaction-space.html
778 lines (668 loc) · 26 KB
/
px-vis-interaction-space.html
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
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
<link rel="import" href="../polymer/polymer.html"/>
<link rel="import" href="px-vis-behavior-common.html" />
<link rel="import" href="px-vis-behavior-d3.html" />
<link rel="import" href="../px-colors-design/colors.html" />
<!--
Element providing on-chart hover functionality to get data values near the mouse cursor and listen to mouse events on the chart.
- Sets tooltipData property which can then be used to share adjacent datapoint values with other components, such as the register.
##### Usage
<px-vis-interaction-space
svg="[[svg]]"
width="[[width]]"
height="[[height]]"
margin="[[margin]]"
chart-data="[[chartData]]"
x="[[x]]"
y="[[y]]"
current-domain-x="[[currentDomainX]]"
current-domain-y="[[currentDomainY]]"
tooltip-data="{{tooltipData}}"
extents-data="{{extentsData}}">
</px-vis-interaction-space>
@element px-vis-interaction-space
@blurb Element providing on-chart hover functionality to get data values near the mouse cursor.
@homepage index.html
@demo demo.html
TODO implement a dev setting to choose between only showing data at that x, snapping to nearest data, or interpolating value at x
-->
<link rel="import" href="css/px-vis-styles.html">
<dom-module id="px-vis-interaction-space">
<template>
<style include="px-vis-styles"></style>
</template>
</dom-module>
<script>
Polymer({
is: 'px-vis-interaction-space',
behaviors: [
PxVisBehavior.sizing,
PxVisBehaviorD3.svg,
PxVisBehaviorD3.axes,
PxVisBehavior.dataset,
PxVisBehavior.tooltipData,
PxVisBehavior.extentsData,
PxVisBehavior.commonMethods,
PxVisBehavior.axisTypes,
PxVisBehavior.completeSeriesConfig,
PxVisBehavior.zoomSelection,
PxVisBehavior.seriesKeys,
PxColorsBehavior.baseColors,
PxVisBehavior.actionConfig
],
/***EVENTS****
/*
* fires an update to the interaction svg
* @event px-vis-interaction-svg-updated
*/
/*
* fires an update to the tooltip
* @event px-vis-tooltip-updated
*/
/*
* fired when panning starts
* @event px-vis-interaction-space-start-panning
*/
/*
* fired when panning stop
* @event px-vis-interaction-space-stop-panning
*/
/**
* Properties block, expose attribute values to the DOM via 'reflect'
*
* @property properties
* @type Object
*/
properties: {
/**
* Holder for the interaction rectangle object
*
*/
_rect:{
type:Object
},
/**
* an object that contains meta data for the area drawn by the user
*
*/
_actionArea: {
type: Object,
value: function() {return {};}
},
/**
* The actual mouse svg rect which can be used to activate tooltip
*
*/
mouseRect: {
type: Object,
notify: true
},
/**
* Name of the variable holding the time stamp in the data. Used for non timeseries charts
*/
timeData: {
type: String,
value: 'Timestamp'
},
/**
* set of predefined action that can be used out of the box
*/
actionMapping: {
type: Object,
readOnly: true,
value: {
'startZooming': '_drawActionBox',
'stopZooming': '_finishActionBox',
'calcTooltipData': '_calcTooltipData',
'resetTooltip': '_resetTooltipData',
'startPanning': '_startPanning',
'stopPanning': '_stopPanning'
}
},
_panningStartVal: {
type: Array,
value: function() {
return [];
}
}
},
observers: [
'drawElement(currentDomainX,currentDomainY,chartData.*,svg,width,height, completeSeriesConfig)',
'_setupActions(actionConfig.*)',
'_resetTooltipDataLegacy(completeSeriesConfig.*,)',
'_resetTooltipData(seriesKeys.*)'
],
/**
* when attached, re-fire set properties for precipitation pattern
*
* @method attached
*/
attached: function(){
if(this._doesObjHaveValues(this.tooltipData)){
this.fire('px-vis-tooltip-updated', { 'dataVar': 'tooltipData', 'data': this.tooltipData, 'method':'set' });
}
if(this._doesObjHaveValues(this.mouseRect)){
this.fire('px-vis-mouse-rect-updated', {'data': this.mouseRect, 'dataVar': 'mouseRect', 'method': 'set'});
}
},
/**
* Draws the tooltip elements and sets up listeners and callbacks on chart hover
* Sets the tooltipData property which gets passed to the register.
*
* @method drawElement
*/
drawElement: function() {
// append the rectangle to capture mouse interactions
if(!this._rect) {
this._rect = this.svg.append('rect')
.attr('id','mouseCapture')
.attr('width', Math.max(this.width - this.margin.left - this.margin.right,0))
.attr('height', Math.max(this.height - this.margin.bottom - this.margin.top,0))
.attr('fill', 'none')
.attr('pointer-events', 'all')
.style('cursor','crosshair');
this._setupActions();
this.set('mouseRect', this._rect.node());
this.fire('px-vis-mouse-rect-updated', {'data': this.mouseRect, 'dataVar': 'mouseRect', 'method': 'set'});
} else {
this._rect.attr('width', Math.max(0, this.width - this.margin.left - this.margin.right))
.attr('height', Math.max(0, this.height - this.margin.bottom - this.margin.top));
}
}, //drawElement
_setupActions: function() {
if(this._rect) {
var keys = Object.keys(this.actionConfig),
mouseEvent,
action,
bindingContext = this,
toBeUsed,
noChartContext;
for(var i=0; i<keys.length; i++) {
mouseEvent = keys[i];
action = this.actionConfig[keys[i]];
mappedAction = this[this.actionMapping[action]];
//toBeUsed = null;
noChartContext = false;
//is this a function defined here
if(mappedAction && typeof mappedAction === 'function') {
//we don't need to remove previous handlers as if they have the same
//mouseEVent name then they will be overriden
toBeUsed = mappedAction;
noChartContext = true;
} else if(typeof action === 'function') {
toBeUsed = action;
} else if(typeof action === 'string') {
toBeUsed = eval('var f = function() { return ' + action + ';}; f();');
}
if(toBeUsed) {
var wrapper;
if(noChartContext) {
wrapper = toBeUsed.bind(this);
} else {
//now ensure the action will be run within the context of the chart
var _this = this;
wrapper = function(evt) {
_this.fire('px-vis-action-request', {'function': this});
}.bind(toBeUsed);
}
this._rect.on(mouseEvent, wrapper);
} else {
//remove listener
this._rect.on(mouseEvent, null);
}
}
}
},
_resetTooltipDataLegacy: function() {
if(!this.seriesKeys){
this._resetTooltipData();
}
},
/**
* Helper function called on mouseout
* resets tooltipData
*
* @method _resetTooltipData
*/
_resetTooltipData: function() {
var ttD = {
'time': null,
'hidden': true,
'series': [],
'mouse': null,
'xArr': null,
'yArr': null
},
keys = (this.seriesKeys) ? this.seriesKeys : Object.keys(this.completeSeriesConfig),
len = keys.length,
i;
for(i = 0; i < len; i++){
ttD.series.push({'name':keys[i],'value': null });
}
this.set('tooltipData',ttD);
this.fire('px-vis-tooltip-updated', { 'dataVar': 'tooltipData', 'data': ttD, 'method':'set' });
},
/**
* Helper function called on mousemove
* Calculates the mouse position and associated x & y values. Then sets the d3 elements and sets tooltipData for consumption elsewhere
*
* @method _calcTooltipData
*/
_calcTooltipData:function() {
if(!this.mouseDown && this.chartData.length > 0) {
// d3.mouse: returns the x position on the screen of the mouse
var mousePos = Px.d3.mouse(this._rect.node()),
x0,
dataObj,
bisectDate,
xArr,
yArr,
len,
index,
d0,
d1,
d,
xCoord,
yCoord;
this.debounce('move',function(){
// TODO Maybe this should be a option: return all val at x or closets vals at cursor
// invert: takes position on the screen and converts it into an equivalent date
var minDist = Number.MAX_VALUE,
result = {},
xArr = [],
yArr = [],
keys = (this.seriesKeys) ? this.seriesKeys : Object.keys(this.completeSeriesConfig),
len = keys.length,
d,
x1 = this.xAxisType !== 'ordinal' ? this.x.invert(mousePos[0]) : null,
y1 = this.yAxisType !== 'ordinal' ? this.y.invert(mousePos[1]) : null,
x2,
y2,
chartData,
//contains [distance, timestamp]
closestTimestamp = [Number.MAX_VALUE, null],
searchTimeStamp;
// setup a holder for our data to pass out
var dataObj = {
'time':(this.xAxisType === 'time' || this.xAxisType === 'timeLocal') ? x1 : null,
'hidden': false,
'series': [],
'mouse': mousePos,
'xArr': null,
'yArr': null
};
//search for timestamp if we don't have it already (non time based chart)
//and we know the data has some notion of time
searchTimeStamp = dataObj.time === null && !!this.chartData[0][this.timeData];
for(var i = 0; i < len; i++) {
var yKey = this.completeSeriesConfig[keys[i]]['y'],
xKey = this.completeSeriesConfig[keys[i]]['x'];
minDist = Number.MAX_VALUE;
result = {};
//ordinal are specials...
if(this.xAxisType === 'ordinal') {
//find ordinal value for X
result[xKey] = this._getOrdinalValue(true, mousePos[0]);
//now get Y
if(this.yAxisType === 'ordinal') {
result[yKey] = this._getOrdinalValue(false, mousePos[1]);
} else {
result[yKey] = this._getClosestValue(false, y1, this.chartData, xKey, yKey, result[xKey]);
}
} else if(this.yAxisType === 'ordinal') {
result[yKey] = this._getOrdinalValue(false, mousePos[1]);
//now get X
if(this.yAxisType === 'ordinal') {
result[xKey] = this._getOrdinalValue(true, mousePos[0]);
} else {
result[xKey] = this._getClosestValue(true, x1, this.chartData, xKey, yKey, result[yKey]);
}
}
//find closest point....
else if(this.xAxisType === 'time' || this.xAxisType === 'timeLocal') {
//time based X axis
/*
d3.bisector returns index in our array that corresponds to the horizontal position of the mouse pointer.
Specifically this returns the date that falls to the left of the mouse cursor.
*/
chartData = this.chartData;
var bisectDate = Px.d3.bisector(function(d) {
return d[this.completeSeriesConfig[keys[i]]['x']];
}.bind(this)).left,
index = bisectDate(chartData, x1, 1),
r;
// get the data values around the index
d0 = chartData[index - 1];
d1 = (chartData[index]) ? chartData[index] : chartData[index - 1];
// sets result as the closest date to the mouse
r = (x1 - d0[xKey] > d1[xKey] - x1) ? d1 : d0;
result[xKey] = r[xKey];
result[yKey] = r[yKey];
} else {
//non time based: iterate over points and find the closest
var currX = this.x.domain(),
currY = this.y.domain(),
dataX,
dataY;
for(var j = 0; j < this.chartData.length; j++) {
//get point values
dataX = this.chartData[j][xKey];
dataY = this.chartData[j][yKey];
if(dataX >= currX[0] && dataX <= currX[1] && dataY >= currY[0] && dataY <= currY[1]) {
//get pixel coords
x2 = this.x(dataX);
y2 = this.y(dataY);
//distance between the two points
//! x2 and y2 are changed during this calculation
d = Math.sqrt( (x2-=mousePos[0])*x2 + (y2-=mousePos[1])*y2 );
//keep the closest point
if(d < minDist) {
minDist = d;
//store this point
result[xKey] = dataX;
result[yKey] = dataY;
//store the timestamp and distance
if(searchTimeStamp && closestTimestamp[0] > minDist) {
closestTimestamp = [minDist, this.chartData[j][this.timeData]];
}
}
}
}
}
// get the pixel coords for that data
xCoord = this.x(result[xKey]);
yCoord = this.y(result[yKey]);
xArr.push(xCoord);
yArr.push(yCoord);
dataObj.series.push({'name':keys[i],'value': result, 'coord': [xCoord,yCoord] });
} //for
dataObj['xArr'] = xArr;
dataObj['yArr'] = yArr;
if(searchTimeStamp) {
dataObj.time = closestTimestamp[1];
}
// now we can set our data that we want to pass out
this.set('tooltipData',dataObj);
this.fire('px-vis-tooltip-updated', { 'dataVar': 'tooltipData', 'data': dataObj, 'method':'set' });
},1);
}
},
/**
* Tries to find the ordinal value for the mouse position on the X (xAxis=true)
* or Y (xAxis=false) axis. If searching on X axis mousePos must be the X value,
* Y value if searching on the Y axis
*
*/
_getOrdinalValue: function(xAxis, mousePos) {
//TODO: try getting the closest one rather than the one directly on the left
var domain = xAxis ? this.x.domain() : this.y.domain(),
range = xAxis ? this.x.range() : this.y.range();
rangeInterval = (range[1] - range[0])/domain.length;
var axisPos = 0,
distance = Number.MAX_VALUE,
minDistance = Number.MAX_VALUE,
result = -1;
for(var index=0; index<domain.length; index++) {
axisPos = (index+0.5)*rangeInterval;
distance = Math.abs(axisPos - mousePos);
if(distance < minDistance) {
minDistance = distance;
result = index;
}
}
return domain[result];
},
/**
* Gets the range of all ordinal values between from and to (both being values of the axis)
*
*/
_getOrdinalRange: function(xAxis, from, to) {
//get the diferent values
var allValues = xAxis === true ? this.x.domain() : this.y.domain(),
fromVal = this._getOrdinalValue(xAxis, from),
toVal = this._getOrdinalValue(xAxis, to),
fromIndex = allValues.indexOf(fromVal),
toIndex = allValues.indexOf(toVal),
result = [];
//now add everything between the two values, including those 2 values
for(var i=fromIndex; i<toIndex+1; i++) {
result.push(allValues[i]);
}
return result;
},
/**
* Gets the closest value on the X (xAxis=true) or Y axis (xAxis=false)
* for a specific ordinal value defined on the other axis
*
*/
_getClosestValue: function(xAxis, value, data, xKey, yKey, ordValue) {
var dataIndex = xAxis ? xKey : yKey,
ordIndex = xAxis ? yKey : xKey,
minDiff = Number.MAX_VALUE,
curr,
currDiff,
result;
data.forEach(function(point, index) {
//only look at points that have the proper ordinal value
if(point[ordIndex] === ordValue) {
curr = point[dataIndex];
currDiff = Math.abs(value - curr);
if(currDiff < minDiff) {
minDiff = currDiff;
result = curr;
}
}
});
return result;
},
/**
* Helper function called on document.mouseup
* assumes the user wanted to 'close' the action box, and calls _finishActionBox
*
* @method _mouseUpOutsideSvg
*/
_mouseUpOutsideSvg: function() {
this._finishActionBox();
},
/**
* Initiate Panning action
*/
_startPanning: function() {
//only allow left clicks
if(Px.d3.event.button === 0) {
this.mouseDown = true;
this._resetTooltipData();
//in case the user clicks inside the chart, and mouses out, we are waiting for a mouseup, and closing our action box with the coordinates available on the mouseup.
Px.d3.select(document).on('mouseup.action', this._stopPanning.bind(this));
Px.d3.select(document).on('mousemove.action', this._updatePanning.bind(this));
var mousePos = Px.d3.mouse(this._rect.node());
//for ordinal axis store mouse pos, for others the corresponding value
if(this.xAxisType === 'ordinal') {
this._panningStartVal[0] = mousePos[0];
} else {
this._panningStartVal[0] = this.x.invert(mousePos[0]);
}
if(this.yAxisType === 'ordinal') {
this._panningStartVal[1] = mousePos[1];
} else {
this._panningStartVal[1] = this.y.invert(mousePos[1]);
}
this.fire('px-vis-interaction-space-start-panning');
}
},
_updatePanning: function() {
var newExtents = {},
mousePos = Px.d3.mouse(this._rect.node()),
currentPanningVal,
diff,
xDomain = this.x.domain(),
yDomain = this.y.domain();
//for now ignore ordinal axis but allow panning along the other axis
//if it's not ordinal as well
//X
if(this.xAxisType !== 'ordinal') {
currentPanningVal = this.x.invert(mousePos[0]);
diff = currentPanningVal - this._panningStartVal[0];
newExtents.eX = [xDomain[0] - diff, xDomain[1] - diff];
} else {
newExtents.eX = xDomain;
this._adjustOrdinalAlign(this.x, mousePos[0], this._panningStartVal[0]);
//store mouse pos for next update
this._panningStartVal[0] = mousePos[0];
}
//Y
if(this.yAxisType !== 'ordinal') {
currentPanningVal = this.y.invert(mousePos[1]);
diff = currentPanningVal - this._panningStartVal[1];
newExtents.eY = [yDomain[0] - diff, yDomain[1] - diff];
} else {
//keep same domain and play on alignment for panning
newExtents.eY = yDomain;
this._adjustOrdinalAlign(this.y, mousePos[1], this._panningStartVal[1]);
//store mouse pos for next update
this._panningStartVal[1] = mousePos[1];
}
this.set('extentsData', newExtents);
},
_adjustOrdinalAlign: function(axis, mousePos, initialMousePos) {
var diff = (mousePos - initialMousePos)/2,
step = axis.step(),
axisRange = axis.range(),
outerSize = axis.step() * axis.padding(),
leftSize = outerSize * axis.align(),
//rightSize = outerSize * (1 - axis.align()),
newAlign;
//adjust sizes with panning
leftSize = Math.min(Math.max(0, leftSize + diff), step);
//rightSize = Math.min(Math.max(0, rightSize - diff), step);
newAlign = Math.max(0, Math.min(leftSize/outerSize, 1));
axis.align(newAlign);
},
_stopPanning: function() {
this._updatePanning();
Px.d3.select(document).on('mouseup.action', null);
Px.d3.select(document).on('mousemove.action', null);
this.mouseDown = false;
this.fire('px-vis-interaction-space-stop-panning');
},
/**
* Helper function called on mousedown.action
* Draws a rectangle on the chart
*
* @method _drawActionBox
*/
_drawActionBox: function() {
//only allow left clicks
if(Px.d3.event.button === 0) {
this.mouseDown = true;
//in case the user clicks inside the chart, and mouses out, we are waiting for a mouseup, and closing our action box with the coordinates available on the mouseup.
Px.d3.select(document).on('mouseup.action', this._mouseUpOutsideSvg.bind(this));
Px.d3.select(document).on('mousemove.action', this._updateActionBox.bind(this));
var mousePos = Px.d3.mouse(this._rect.node());
// use original svg so it draws under the _rect and does not interfer with our mouse events
var startX = mousePos[0],
startY = mousePos[1];
if(this.selectionType === 'xAxis') {
startY = 0;
} else if(this.selectionType === 'yAxis') {
startX = 0;
}
this._actionArea = this.svg.append('rect')
.attr('class', 'action-area')
.attr('x', startX)
.attr('y', startY)
.attr('ox', startX) // save this original position for calcs
.attr('oy', startY) // save this original position for calcs
.attr('rx', 2)
.attr('ry', 2)
.attr('width', 0)
.attr('height', 0)
.attr('fill', this._checkThemeVariable('--px-vis-zoom-brush-fill-color', this.colors.grey2))
.attr('fill-opacity', this._checkThemeVariable('--px-vis-zoom-brush-fill-opacity', 0.5))
.attr('stroke', this._checkThemeVariable('--px-vis-zoom-brush-outline-color', this.colors.grey6));
}
},
/**
* Helper function called on mousedown.action
* Updates the size of the action area rectangle
*
* @method _updateActionBox
*/
_updateActionBox: function() {
if(this._doesObjHaveValues(this._actionArea)) {
var mousePos = Px.d3.mouse(this._rect.node()),
// save somewhere else--> not as an attr, inefficient
ox = parseInt(this._actionArea.attr('ox')),
oy = parseInt(this._actionArea.attr('oy')),
width = this._rect.attr('width'),
height = this._rect.attr('height')
newX = Math.max(Math.min(mousePos[0], width), 0),
newY = Math.max(Math.min(mousePos[1], height), 0);
if(this.selectionType === 'xAxis') {
newY = height;
} else if(this.selectionType === 'yAxis') {
newX = width;
}
// if current position is greater than the original position
if(newX >= ox) {
// set x to the original position to prevent some drift on crossover. width is equal to the difference between the x and current mouse position
this._actionArea.attr('x', ox);
this._actionArea.attr('width', newX - ox);
} else {
// else, the x is the current pos (because we cant have negative width) and width is the difference
this._actionArea.attr('x', newX);
this._actionArea.attr('width', ox - newX);
}
if(newY >= oy) {
this._actionArea.attr('y', oy);
this._actionArea.attr('height', newY - oy);
} else {
this._actionArea.attr('y', newY);
this._actionArea.attr('height', oy - newY);
}
Px.d3.event.preventDefault();
}
},
/**
* Helper function called on mouseup.action
* Gets the size of the action area rectangle, sets the extents, and removes it
*
* @method _finishActionBox
*/
_finishActionBox: function() {
//since we are done drawing our action box, remove the listener from document using d3.
Px.d3.select(document).on('mouseup.action', null);
Px.d3.select(document).on('mousemove.action', null);
this.mouseDown = false;
var extents = {};
if(this._doesD3HaveValues(this._actionArea)) {
//make sure we have somthing selected
if(this._actionArea.attr('width') > 0 && this._actionArea.attr('height') > 0) {
extents.x1 = parseInt(this._actionArea.attr('x'));
extents.y1 = parseInt(this._actionArea.attr('y'));
extents.w = parseInt(this._actionArea.attr('width'));
extents.h = parseInt(this._actionArea.attr('height'));
extents.x2 = extents.x1 + extents.w;
extents.y2 = extents.y1 + extents.h;
if(this.xAxisType === 'ordinal') {
extents.eX = this._getOrdinalRange(true, extents.x1, extents.x2);
} else {
extents.eX = [this.x.invert(extents.x1), this.x.invert(extents.x2)];
}
if(this.yAxisType === 'ordinal') {
//Y axis is top to bottom
extents.eY = this._getOrdinalRange(false, extents.y2, extents.y1);
} else {
//Y axis is top to bottom
extents.eY = [this.y.invert(extents.y2), this.y.invert(extents.y1)];
}
//save zoom state
this.fire('px-vis-save-zoom-state');
//set new extents
this.set('extentsData', extents);
this.fire('px-vis-extents-data-updated', {'data': extents, 'dataVar': 'extentsData', 'method': 'set'});
}
this._actionArea.remove();
}
}
});
</script>