plotly.js 2.13.1 → 2.14.0

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * plotly.js (gl2d) v2.13.1
2
+ * plotly.js (gl2d) v2.14.0
3
3
  * Copyright 2012-2022, Plotly, Inc.
4
4
  * All rights reserved.
5
5
  * Licensed under the MIT license
@@ -49603,6 +49603,10 @@ function draw(gd) {
49603
49603
  }
49604
49604
  }
49605
49605
 
49606
+ function couldHaveActiveSelection(gd) {
49607
+ return gd._context.editSelection;
49608
+ }
49609
+
49606
49610
  function drawOne(gd, index) {
49607
49611
  // remove the existing selection if there is one.
49608
49612
  // because indices can change, we need to look in all selection layers
@@ -49639,7 +49643,7 @@ function drawOne(gd, index) {
49639
49643
  lineDash = 'solid';
49640
49644
  }
49641
49645
 
49642
- var isActiveSelection =
49646
+ var isActiveSelection = couldHaveActiveSelection(gd) &&
49643
49647
  gd._fullLayout._activeSelectionIndex === index;
49644
49648
 
49645
49649
  if(isActiveSelection) {
@@ -49706,6 +49710,8 @@ function setClipPath(selectionPath, gd, selectionOptions) {
49706
49710
 
49707
49711
 
49708
49712
  function activateSelection(gd, path) {
49713
+ if(!couldHaveActiveSelection(gd)) return;
49714
+
49709
49715
  var element = path.node();
49710
49716
  var id = +element.getAttribute('data-index');
49711
49717
  if(id >= 0) {
@@ -49722,6 +49728,8 @@ function activateSelection(gd, path) {
49722
49728
  }
49723
49729
 
49724
49730
  function activateLastSelection(gd) {
49731
+ if(!couldHaveActiveSelection(gd)) return;
49732
+
49725
49733
  var id = gd._fullLayout.selections.length - 1;
49726
49734
  gd._fullLayout._activeSelectionIndex = id;
49727
49735
  gd._fullLayout._deactivateSelection = deactivateSelection;
@@ -49729,6 +49737,8 @@ function activateLastSelection(gd) {
49729
49737
  }
49730
49738
 
49731
49739
  function deactivateSelection(gd) {
49740
+ if(!couldHaveActiveSelection(gd)) return;
49741
+
49732
49742
  var id = gd._fullLayout._activeSelectionIndex;
49733
49743
  if(id >= 0) {
49734
49744
  clearOutlineControllers(gd);
@@ -50060,7 +50070,14 @@ var p2r = helpers.p2r;
50060
50070
  var axValue = helpers.axValue;
50061
50071
  var getTransform = helpers.getTransform;
50062
50072
 
50073
+ function hasSubplot(dragOptions) {
50074
+ // N.B. subplot may be falsy e.g zero sankey index!
50075
+ return dragOptions.subplot !== undefined;
50076
+ }
50077
+
50063
50078
  function prepSelect(evt, startX, startY, dragOptions, mode) {
50079
+ var isCartesian = !hasSubplot(dragOptions);
50080
+
50064
50081
  var isFreeMode = freeMode(mode);
50065
50082
  var isRectMode = rectMode(mode);
50066
50083
  var isOpenMode = openMode(mode);
@@ -50074,7 +50091,7 @@ function prepSelect(evt, startX, startY, dragOptions, mode) {
50074
50091
  var gd = dragOptions.gd;
50075
50092
  var fullLayout = gd._fullLayout;
50076
50093
  var immediateSelect = isSelectMode && fullLayout.newselection.mode === 'immediate' &&
50077
- !dragOptions.subplot; // N.B. only cartesian subplots have persistent selection
50094
+ isCartesian; // N.B. only cartesian subplots have persistent selection
50078
50095
 
50079
50096
  var zoomLayer = fullLayout._zoomlayer;
50080
50097
  var dragBBox = dragOptions.element.getBoundingClientRect();
@@ -50122,9 +50139,9 @@ function prepSelect(evt, startX, startY, dragOptions, mode) {
50122
50139
  opacity: isDrawMode ? newStyle.opacity / 2 : 1,
50123
50140
  fill: (isDrawMode && !isOpenMode) ? newStyle.fillcolor : 'none',
50124
50141
  stroke: newStyle.line.color || (
50125
- dragOptions.subplot !== undefined ?
50126
- '#7f7f7f' : // non-cartesian subplot
50127
- Color.contrast(gd._fullLayout.plot_bgcolor) // cartesian subplot
50142
+ isCartesian ?
50143
+ Color.contrast(gd._fullLayout.plot_bgcolor) :
50144
+ '#7f7f7f' // non-cartesian subplot
50128
50145
  ),
50129
50146
  'stroke-dasharray': dashStyle(newStyle.line.dash, newStyle.line.width),
50130
50147
  'stroke-width': newStyle.line.width + 'px',
@@ -50155,6 +50172,8 @@ function prepSelect(evt, startX, startY, dragOptions, mode) {
50155
50172
 
50156
50173
  if(immediateSelect && !evt.shiftKey) {
50157
50174
  dragOptions._clearSubplotSelections = function() {
50175
+ if(!isCartesian) return;
50176
+
50158
50177
  var xRef = xAxis._id;
50159
50178
  var yRef = yAxis._id;
50160
50179
  deselectSubplot(gd, xRef, yRef, searchTraces);
@@ -50175,6 +50194,8 @@ function prepSelect(evt, startX, startY, dragOptions, mode) {
50175
50194
  }
50176
50195
 
50177
50196
  if(selectionErased) {
50197
+ gd._fullLayout._noEmitSelectedAtStart = true;
50198
+
50178
50199
  Registry.call('_guiRelayout', gd, {
50179
50200
  selections: list
50180
50201
  });
@@ -50316,10 +50337,10 @@ function prepSelect(evt, startX, startY, dragOptions, mode) {
50316
50337
  displayOutlines(convertPoly(mergedPolygons, isOpenMode), outlines, dragOptions);
50317
50338
 
50318
50339
  if(isSelectMode) {
50319
- var _res = reselect(gd);
50340
+ var _res = reselect(gd, false);
50320
50341
  var extraPoints = _res.eventData ? _res.eventData.points.slice() : [];
50321
50342
 
50322
- _res = reselect(gd, selectionTesters, searchTraces, dragOptions);
50343
+ _res = reselect(gd, false, selectionTesters, searchTraces, dragOptions);
50323
50344
  selectionTesters = _res.selectionTesters;
50324
50345
  eventData = _res.eventData;
50325
50346
 
@@ -50413,9 +50434,13 @@ function prepSelect(evt, startX, startY, dragOptions, mode) {
50413
50434
  }
50414
50435
  }
50415
50436
 
50416
- Registry.call('_guiRelayout', gd, {
50417
- selections: subSelections
50418
- });
50437
+ if(subSelections.length < allSelections.length) {
50438
+ gd._fullLayout._noEmitSelectedAtStart = true;
50439
+
50440
+ Registry.call('_guiRelayout', gd, {
50441
+ selections: subSelections
50442
+ });
50443
+ }
50419
50444
  }
50420
50445
  }
50421
50446
  } else {
@@ -50461,7 +50486,9 @@ function prepSelect(evt, startX, startY, dragOptions, mode) {
50461
50486
  dragOptions.doneFnCompleted(selection);
50462
50487
  }
50463
50488
 
50464
- emitSelected(gd, eventData);
50489
+ if(isSelectMode) {
50490
+ emitSelected(gd, eventData);
50491
+ }
50465
50492
  }).catch(Lib.error);
50466
50493
  };
50467
50494
  }
@@ -50683,15 +50710,23 @@ function coerceSelectionsCache(evt, gd, dragOptions) {
50683
50710
  }
50684
50711
  }
50685
50712
 
50713
+ function hasActiveShape(gd) {
50714
+ return gd._fullLayout._activeShapeIndex >= 0;
50715
+ }
50716
+
50717
+ function hasActiveSelection(gd) {
50718
+ return gd._fullLayout._activeSelectionIndex >= 0;
50719
+ }
50720
+
50686
50721
  function clearSelectionsCache(dragOptions, immediateSelect) {
50687
50722
  var dragmode = dragOptions.dragmode;
50688
50723
  var plotinfo = dragOptions.plotinfo;
50689
50724
 
50690
50725
  var gd = dragOptions.gd;
50691
- if(gd._fullLayout._activeShapeIndex >= 0) {
50726
+ if(hasActiveShape(gd)) {
50692
50727
  gd._fullLayout._deactivateShape(gd);
50693
50728
  }
50694
- if(gd._fullLayout._activeSelectionIndex >= 0) {
50729
+ if(hasActiveSelection(gd)) {
50695
50730
  gd._fullLayout._deactivateSelection(gd);
50696
50731
  }
50697
50732
 
@@ -50719,11 +50754,13 @@ function clearSelectionsCache(dragOptions, immediateSelect) {
50719
50754
  var selections;
50720
50755
  if(
50721
50756
  isSelectMode &&
50722
- !dragOptions.subplot // only allow cartesian - no mapbox for now
50757
+ !hasSubplot(dragOptions) // only allow cartesian - no mapbox for now
50723
50758
  ) {
50724
50759
  selections = newSelections(outlines, dragOptions);
50725
50760
  }
50726
50761
  if(selections) {
50762
+ gd._fullLayout._noEmitSelectedAtStart = true;
50763
+
50727
50764
  Registry.call('_guiRelayout', gd, {
50728
50765
  selections: selections
50729
50766
  }).then(function() {
@@ -50758,7 +50795,10 @@ function determineSearchTraces(gd, xAxes, yAxes, subplot) {
50758
50795
 
50759
50796
  if(trace.visible !== true || !trace._module || !trace._module.selectPoints) continue;
50760
50797
 
50761
- if(subplot && (trace.subplot === subplot || trace.geo === subplot)) {
50798
+ if(
50799
+ hasSubplot({subplot: subplot}) &&
50800
+ (trace.subplot === subplot || trace.geo === subplot)
50801
+ ) {
50762
50802
  searchTraces.push(createSearchInfo(trace._module, cd, xAxes[0], yAxes[0]));
50763
50803
  } else if(trace.type === 'splom') {
50764
50804
  // FIXME: make sure we don't have more than single axis for splom
@@ -51058,7 +51098,7 @@ function _doSelect(selectionTesters, searchTraces) {
51058
51098
  return allSelections;
51059
51099
  }
51060
51100
 
51061
- function reselect(gd, selectionTesters, searchTraces, dragOptions) {
51101
+ function reselect(gd, mayEmitSelected, selectionTesters, searchTraces, dragOptions) {
51062
51102
  var hadSearchTraces = !!searchTraces;
51063
51103
  var plotinfo, xRef, yRef;
51064
51104
  if(dragOptions) {
@@ -51181,15 +51221,15 @@ function reselect(gd, selectionTesters, searchTraces, dragOptions) {
51181
51221
  updateSelectedState(gd, allSearchTraces, eventData);
51182
51222
 
51183
51223
  var clickmode = fullLayout.clickmode;
51184
- var sendEvents = clickmode.indexOf('event') > -1;
51224
+ var sendEvents = clickmode.indexOf('event') > -1 && mayEmitSelected;
51185
51225
 
51186
51226
  if(
51187
51227
  !plotinfo && // get called from plot_api & plots
51188
- fullLayout._reselect
51228
+ mayEmitSelected
51189
51229
  ) {
51190
- if(sendEvents) {
51191
- var activePolygons = getLayoutPolygons(gd, true);
51230
+ var activePolygons = getLayoutPolygons(gd, true);
51192
51231
 
51232
+ if(activePolygons.length) {
51193
51233
  var xref = activePolygons[0].xref;
51194
51234
  var yref = activePolygons[0].yref;
51195
51235
  if(xref && yref) {
@@ -51202,8 +51242,12 @@ function reselect(gd, selectionTesters, searchTraces, dragOptions) {
51202
51242
 
51203
51243
  fillRangeItems(eventData, poly);
51204
51244
  }
51245
+ }
51205
51246
 
51206
- emitSelected(gd, eventData);
51247
+ if(gd._fullLayout._noEmitSelectedAtStart) {
51248
+ gd._fullLayout._noEmitSelectedAtStart = false;
51249
+ } else {
51250
+ if(sendEvents) emitSelected(gd, eventData);
51207
51251
  }
51208
51252
 
51209
51253
  fullLayout._reselect = false;
@@ -51225,7 +51269,7 @@ function reselect(gd, selectionTesters, searchTraces, dragOptions) {
51225
51269
  if(eventData.points.length) {
51226
51270
  emitSelected(gd, eventData);
51227
51271
  } else {
51228
- gd.emit('plotly_deselect', null);
51272
+ emitDeselect(gd);
51229
51273
  }
51230
51274
  }
51231
51275
 
@@ -51513,13 +51557,10 @@ function getFillRangeItems(dragOptions) {
51513
51557
  }
51514
51558
 
51515
51559
  function emitSelecting(gd, eventData) {
51516
- if(drawMode(gd._fullLayout.dragmode)) return;
51517
51560
  gd.emit('plotly_selecting', eventData);
51518
51561
  }
51519
51562
 
51520
51563
  function emitSelected(gd, eventData) {
51521
- if(drawMode(gd._fullLayout.dragmode)) return;
51522
-
51523
51564
  if(eventData) {
51524
51565
  eventData.selections = (gd.layout || {}).selections || [];
51525
51566
  }
@@ -51528,7 +51569,6 @@ function emitSelected(gd, eventData) {
51528
51569
  }
51529
51570
 
51530
51571
  function emitDeselect(gd) {
51531
- if(drawMode(gd._fullLayout.dragmode)) return;
51532
51572
  gd.emit('plotly_deselect', null);
51533
51573
  }
51534
51574
 
@@ -69231,6 +69271,11 @@ var configAttributes = {
69231
69271
  }
69232
69272
  },
69233
69273
 
69274
+ editSelection: {
69275
+ valType: 'boolean',
69276
+ dflt: true,
69277
+ },
69278
+
69234
69279
  autosizable: {
69235
69280
  valType: 'boolean',
69236
69281
  dflt: false,
@@ -89608,7 +89653,16 @@ plots.redrag = function(gd) {
89608
89653
  };
89609
89654
 
89610
89655
  plots.reselect = function(gd) {
89611
- Registry.getComponentMethod('selections', 'reselect')(gd);
89656
+ var fullLayout = gd._fullLayout;
89657
+
89658
+ var A = (gd.layout || {}).selections;
89659
+ var B = fullLayout._previousSelections;
89660
+ fullLayout._previousSelections = A;
89661
+
89662
+ var mayEmitSelected = fullLayout._reselect ||
89663
+ JSON.stringify(A) !== JSON.stringify(B);
89664
+
89665
+ Registry.getComponentMethod('selections', 'reselect')(gd, mayEmitSelected);
89612
89666
  };
89613
89667
 
89614
89668
  plots.generalUpdatePerTraceModule = function(gd, subplot, subplotCalcData, subplotLayout) {
@@ -103014,7 +103068,7 @@ function getSortFunc(opts, d2c) {
103014
103068
  'use strict';
103015
103069
 
103016
103070
  // package version injected by `npm run preprocess`
103017
- exports.version = '2.13.1';
103071
+ exports.version = '2.14.0';
103018
103072
 
103019
103073
  },{}],600:[function(_dereq_,module,exports){
103020
103074
  (function (global){(function (){