plotly.js 2.13.0 → 2.13.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plotly.js",
3
- "version": "2.13.0",
3
+ "version": "2.13.3",
4
4
  "description": "The open source javascript graphing library that powers plotly",
5
5
  "license": "MIT",
6
6
  "main": "./lib/index.js",
@@ -50,7 +50,14 @@ var p2r = helpers.p2r;
50
50
  var axValue = helpers.axValue;
51
51
  var getTransform = helpers.getTransform;
52
52
 
53
+ function hasSubplot(dragOptions) {
54
+ // N.B. subplot may be falsy e.g zero sankey index!
55
+ return dragOptions.subplot !== undefined;
56
+ }
57
+
53
58
  function prepSelect(evt, startX, startY, dragOptions, mode) {
59
+ var isCartesian = !hasSubplot(dragOptions);
60
+
54
61
  var isFreeMode = freeMode(mode);
55
62
  var isRectMode = rectMode(mode);
56
63
  var isOpenMode = openMode(mode);
@@ -64,7 +71,7 @@ function prepSelect(evt, startX, startY, dragOptions, mode) {
64
71
  var gd = dragOptions.gd;
65
72
  var fullLayout = gd._fullLayout;
66
73
  var immediateSelect = isSelectMode && fullLayout.newselection.mode === 'immediate' &&
67
- !dragOptions.subplot; // N.B. only cartesian subplots have persistent selection
74
+ isCartesian; // N.B. only cartesian subplots have persistent selection
68
75
 
69
76
  var zoomLayer = fullLayout._zoomlayer;
70
77
  var dragBBox = dragOptions.element.getBoundingClientRect();
@@ -112,9 +119,9 @@ function prepSelect(evt, startX, startY, dragOptions, mode) {
112
119
  opacity: isDrawMode ? newStyle.opacity / 2 : 1,
113
120
  fill: (isDrawMode && !isOpenMode) ? newStyle.fillcolor : 'none',
114
121
  stroke: newStyle.line.color || (
115
- dragOptions.subplot !== undefined ?
116
- '#7f7f7f' : // non-cartesian subplot
117
- Color.contrast(gd._fullLayout.plot_bgcolor) // cartesian subplot
122
+ isCartesian ?
123
+ Color.contrast(gd._fullLayout.plot_bgcolor) :
124
+ '#7f7f7f' // non-cartesian subplot
118
125
  ),
119
126
  'stroke-dasharray': dashStyle(newStyle.line.dash, newStyle.line.width),
120
127
  'stroke-width': newStyle.line.width + 'px',
@@ -145,6 +152,8 @@ function prepSelect(evt, startX, startY, dragOptions, mode) {
145
152
 
146
153
  if(immediateSelect && !evt.shiftKey) {
147
154
  dragOptions._clearSubplotSelections = function() {
155
+ if(!isCartesian) return;
156
+
148
157
  var xRef = xAxis._id;
149
158
  var yRef = yAxis._id;
150
159
  deselectSubplot(gd, xRef, yRef, searchTraces);
@@ -165,6 +174,8 @@ function prepSelect(evt, startX, startY, dragOptions, mode) {
165
174
  }
166
175
 
167
176
  if(selectionErased) {
177
+ gd._fullLayout._noEmitSelectedAtStart = true;
178
+
168
179
  Registry.call('_guiRelayout', gd, {
169
180
  selections: list
170
181
  });
@@ -306,10 +317,10 @@ function prepSelect(evt, startX, startY, dragOptions, mode) {
306
317
  displayOutlines(convertPoly(mergedPolygons, isOpenMode), outlines, dragOptions);
307
318
 
308
319
  if(isSelectMode) {
309
- var _res = reselect(gd);
320
+ var _res = reselect(gd, false);
310
321
  var extraPoints = _res.eventData ? _res.eventData.points.slice() : [];
311
322
 
312
- _res = reselect(gd, selectionTesters, searchTraces, dragOptions);
323
+ _res = reselect(gd, false, selectionTesters, searchTraces, dragOptions);
313
324
  selectionTesters = _res.selectionTesters;
314
325
  eventData = _res.eventData;
315
326
 
@@ -403,9 +414,13 @@ function prepSelect(evt, startX, startY, dragOptions, mode) {
403
414
  }
404
415
  }
405
416
 
406
- Registry.call('_guiRelayout', gd, {
407
- selections: subSelections
408
- });
417
+ if(subSelections.length < allSelections.length) {
418
+ gd._fullLayout._noEmitSelectedAtStart = true;
419
+
420
+ Registry.call('_guiRelayout', gd, {
421
+ selections: subSelections
422
+ });
423
+ }
409
424
  }
410
425
  }
411
426
  } else {
@@ -451,8 +466,9 @@ function prepSelect(evt, startX, startY, dragOptions, mode) {
451
466
  dragOptions.doneFnCompleted(selection);
452
467
  }
453
468
 
454
- eventData.selections = gd.layout.selections;
455
- emitSelected(gd, eventData);
469
+ if(isSelectMode) {
470
+ emitSelected(gd, eventData);
471
+ }
456
472
  }).catch(Lib.error);
457
473
  };
458
474
  }
@@ -530,7 +546,6 @@ function selectOnClick(evt, gd, xAxes, yAxes, subplot, dragOptions, polygonOutli
530
546
  }
531
547
 
532
548
  if(sendEvents) {
533
- eventData.selections = gd.layout.selections;
534
549
  emitSelected(gd, eventData);
535
550
  }
536
551
  }
@@ -675,15 +690,23 @@ function coerceSelectionsCache(evt, gd, dragOptions) {
675
690
  }
676
691
  }
677
692
 
693
+ function hasActiveShape(gd) {
694
+ return gd._fullLayout._activeShapeIndex >= 0;
695
+ }
696
+
697
+ function hasActiveSelection(gd) {
698
+ return gd._fullLayout._activeSelectionIndex >= 0;
699
+ }
700
+
678
701
  function clearSelectionsCache(dragOptions, immediateSelect) {
679
702
  var dragmode = dragOptions.dragmode;
680
703
  var plotinfo = dragOptions.plotinfo;
681
704
 
682
705
  var gd = dragOptions.gd;
683
- if(gd._fullLayout._activeShapeIndex >= 0) {
706
+ if(hasActiveShape(gd)) {
684
707
  gd._fullLayout._deactivateShape(gd);
685
708
  }
686
- if(gd._fullLayout._activeSelectionIndex >= 0) {
709
+ if(hasActiveSelection(gd)) {
687
710
  gd._fullLayout._deactivateSelection(gd);
688
711
  }
689
712
 
@@ -711,11 +734,13 @@ function clearSelectionsCache(dragOptions, immediateSelect) {
711
734
  var selections;
712
735
  if(
713
736
  isSelectMode &&
714
- !dragOptions.subplot // only allow cartesian - no mapbox for now
737
+ !hasSubplot(dragOptions) // only allow cartesian - no mapbox for now
715
738
  ) {
716
739
  selections = newSelections(outlines, dragOptions);
717
740
  }
718
741
  if(selections) {
742
+ gd._fullLayout._noEmitSelectedAtStart = true;
743
+
719
744
  Registry.call('_guiRelayout', gd, {
720
745
  selections: selections
721
746
  }).then(function() {
@@ -750,7 +775,10 @@ function determineSearchTraces(gd, xAxes, yAxes, subplot) {
750
775
 
751
776
  if(trace.visible !== true || !trace._module || !trace._module.selectPoints) continue;
752
777
 
753
- if(subplot && (trace.subplot === subplot || trace.geo === subplot)) {
778
+ if(
779
+ hasSubplot({subplot: subplot}) &&
780
+ (trace.subplot === subplot || trace.geo === subplot)
781
+ ) {
754
782
  searchTraces.push(createSearchInfo(trace._module, cd, xAxes[0], yAxes[0]));
755
783
  } else if(trace.type === 'splom') {
756
784
  // FIXME: make sure we don't have more than single axis for splom
@@ -1050,7 +1078,7 @@ function _doSelect(selectionTesters, searchTraces) {
1050
1078
  return allSelections;
1051
1079
  }
1052
1080
 
1053
- function reselect(gd, selectionTesters, searchTraces, dragOptions) {
1081
+ function reselect(gd, mayEmitSelected, selectionTesters, searchTraces, dragOptions) {
1054
1082
  var hadSearchTraces = !!searchTraces;
1055
1083
  var plotinfo, xRef, yRef;
1056
1084
  if(dragOptions) {
@@ -1173,15 +1201,15 @@ function reselect(gd, selectionTesters, searchTraces, dragOptions) {
1173
1201
  updateSelectedState(gd, allSearchTraces, eventData);
1174
1202
 
1175
1203
  var clickmode = fullLayout.clickmode;
1176
- var sendEvents = clickmode.indexOf('event') > -1;
1204
+ var sendEvents = clickmode.indexOf('event') > -1 && mayEmitSelected;
1177
1205
 
1178
1206
  if(
1179
1207
  !plotinfo && // get called from plot_api & plots
1180
- fullLayout._reselect
1208
+ mayEmitSelected
1181
1209
  ) {
1182
- if(sendEvents) {
1183
- var activePolygons = getLayoutPolygons(gd, true);
1210
+ var activePolygons = getLayoutPolygons(gd, true);
1184
1211
 
1212
+ if(activePolygons.length) {
1185
1213
  var xref = activePolygons[0].xref;
1186
1214
  var yref = activePolygons[0].yref;
1187
1215
  if(xref && yref) {
@@ -1194,9 +1222,12 @@ function reselect(gd, selectionTesters, searchTraces, dragOptions) {
1194
1222
 
1195
1223
  fillRangeItems(eventData, poly);
1196
1224
  }
1225
+ }
1197
1226
 
1198
- eventData.selections = gd.layout.selections;
1199
- emitSelected(gd, eventData);
1227
+ if(gd._fullLayout._noEmitSelectedAtStart) {
1228
+ gd._fullLayout._noEmitSelectedAtStart = false;
1229
+ } else {
1230
+ if(sendEvents) emitSelected(gd, eventData);
1200
1231
  }
1201
1232
 
1202
1233
  fullLayout._reselect = false;
@@ -1216,10 +1247,9 @@ function reselect(gd, selectionTesters, searchTraces, dragOptions) {
1216
1247
 
1217
1248
  if(sendEvents) {
1218
1249
  if(eventData.points.length) {
1219
- eventData.selections = gd.layout.selections;
1220
1250
  emitSelected(gd, eventData);
1221
1251
  } else {
1222
- gd.emit('plotly_deselect', null);
1252
+ emitDeselect(gd);
1223
1253
  }
1224
1254
  }
1225
1255
 
@@ -1511,6 +1541,10 @@ function emitSelecting(gd, eventData) {
1511
1541
  }
1512
1542
 
1513
1543
  function emitSelected(gd, eventData) {
1544
+ if(eventData) {
1545
+ eventData.selections = (gd.layout || {}).selections || [];
1546
+ }
1547
+
1514
1548
  gd.emit('plotly_selected', eventData);
1515
1549
  }
1516
1550
 
@@ -3364,7 +3364,16 @@ plots.redrag = function(gd) {
3364
3364
  };
3365
3365
 
3366
3366
  plots.reselect = function(gd) {
3367
- Registry.getComponentMethod('selections', 'reselect')(gd);
3367
+ var fullLayout = gd._fullLayout;
3368
+
3369
+ var A = (gd.layout || {}).selections;
3370
+ var B = fullLayout._previousSelections;
3371
+ fullLayout._previousSelections = A;
3372
+
3373
+ var mayEmitSelected = fullLayout._reselect ||
3374
+ JSON.stringify(A) !== JSON.stringify(B);
3375
+
3376
+ Registry.getComponentMethod('selections', 'reselect')(gd, mayEmitSelected);
3368
3377
  };
3369
3378
 
3370
3379
  plots.generalUpdatePerTraceModule = function(gd, subplot, subplotCalcData, subplotLayout) {
@@ -48,6 +48,7 @@ function subplotUpdateFx(gd, index) {
48
48
  var dragMode = fullLayout.dragmode;
49
49
  var cursor = fullLayout.dragmode === 'pan' ? 'move' : 'crosshair';
50
50
  var bgRect = trace._bgRect;
51
+ if(!bgRect) return;
51
52
 
52
53
  if(dragMode === 'pan' || dragMode === 'zoom') return;
53
54
 
package/src/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  'use strict';
2
2
 
3
3
  // package version injected by `npm run preprocess`
4
- exports.version = '2.13.0';
4
+ exports.version = '2.13.3';