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 (finance) v2.13.1
2
+ * plotly.js (finance) v2.14.0
3
3
  * Copyright 2012-2022, Plotly, Inc.
4
4
  * All rights reserved.
5
5
  * Licensed under the MIT license
@@ -37355,6 +37355,10 @@ function draw(gd) {
37355
37355
  }
37356
37356
  }
37357
37357
 
37358
+ function couldHaveActiveSelection(gd) {
37359
+ return gd._context.editSelection;
37360
+ }
37361
+
37358
37362
  function drawOne(gd, index) {
37359
37363
  // remove the existing selection if there is one.
37360
37364
  // because indices can change, we need to look in all selection layers
@@ -37391,7 +37395,7 @@ function drawOne(gd, index) {
37391
37395
  lineDash = 'solid';
37392
37396
  }
37393
37397
 
37394
- var isActiveSelection =
37398
+ var isActiveSelection = couldHaveActiveSelection(gd) &&
37395
37399
  gd._fullLayout._activeSelectionIndex === index;
37396
37400
 
37397
37401
  if(isActiveSelection) {
@@ -37458,6 +37462,8 @@ function setClipPath(selectionPath, gd, selectionOptions) {
37458
37462
 
37459
37463
 
37460
37464
  function activateSelection(gd, path) {
37465
+ if(!couldHaveActiveSelection(gd)) return;
37466
+
37461
37467
  var element = path.node();
37462
37468
  var id = +element.getAttribute('data-index');
37463
37469
  if(id >= 0) {
@@ -37474,6 +37480,8 @@ function activateSelection(gd, path) {
37474
37480
  }
37475
37481
 
37476
37482
  function activateLastSelection(gd) {
37483
+ if(!couldHaveActiveSelection(gd)) return;
37484
+
37477
37485
  var id = gd._fullLayout.selections.length - 1;
37478
37486
  gd._fullLayout._activeSelectionIndex = id;
37479
37487
  gd._fullLayout._deactivateSelection = deactivateSelection;
@@ -37481,6 +37489,8 @@ function activateLastSelection(gd) {
37481
37489
  }
37482
37490
 
37483
37491
  function deactivateSelection(gd) {
37492
+ if(!couldHaveActiveSelection(gd)) return;
37493
+
37484
37494
  var id = gd._fullLayout._activeSelectionIndex;
37485
37495
  if(id >= 0) {
37486
37496
  clearOutlineControllers(gd);
@@ -37812,7 +37822,14 @@ var p2r = helpers.p2r;
37812
37822
  var axValue = helpers.axValue;
37813
37823
  var getTransform = helpers.getTransform;
37814
37824
 
37825
+ function hasSubplot(dragOptions) {
37826
+ // N.B. subplot may be falsy e.g zero sankey index!
37827
+ return dragOptions.subplot !== undefined;
37828
+ }
37829
+
37815
37830
  function prepSelect(evt, startX, startY, dragOptions, mode) {
37831
+ var isCartesian = !hasSubplot(dragOptions);
37832
+
37816
37833
  var isFreeMode = freeMode(mode);
37817
37834
  var isRectMode = rectMode(mode);
37818
37835
  var isOpenMode = openMode(mode);
@@ -37826,7 +37843,7 @@ function prepSelect(evt, startX, startY, dragOptions, mode) {
37826
37843
  var gd = dragOptions.gd;
37827
37844
  var fullLayout = gd._fullLayout;
37828
37845
  var immediateSelect = isSelectMode && fullLayout.newselection.mode === 'immediate' &&
37829
- !dragOptions.subplot; // N.B. only cartesian subplots have persistent selection
37846
+ isCartesian; // N.B. only cartesian subplots have persistent selection
37830
37847
 
37831
37848
  var zoomLayer = fullLayout._zoomlayer;
37832
37849
  var dragBBox = dragOptions.element.getBoundingClientRect();
@@ -37874,9 +37891,9 @@ function prepSelect(evt, startX, startY, dragOptions, mode) {
37874
37891
  opacity: isDrawMode ? newStyle.opacity / 2 : 1,
37875
37892
  fill: (isDrawMode && !isOpenMode) ? newStyle.fillcolor : 'none',
37876
37893
  stroke: newStyle.line.color || (
37877
- dragOptions.subplot !== undefined ?
37878
- '#7f7f7f' : // non-cartesian subplot
37879
- Color.contrast(gd._fullLayout.plot_bgcolor) // cartesian subplot
37894
+ isCartesian ?
37895
+ Color.contrast(gd._fullLayout.plot_bgcolor) :
37896
+ '#7f7f7f' // non-cartesian subplot
37880
37897
  ),
37881
37898
  'stroke-dasharray': dashStyle(newStyle.line.dash, newStyle.line.width),
37882
37899
  'stroke-width': newStyle.line.width + 'px',
@@ -37907,6 +37924,8 @@ function prepSelect(evt, startX, startY, dragOptions, mode) {
37907
37924
 
37908
37925
  if(immediateSelect && !evt.shiftKey) {
37909
37926
  dragOptions._clearSubplotSelections = function() {
37927
+ if(!isCartesian) return;
37928
+
37910
37929
  var xRef = xAxis._id;
37911
37930
  var yRef = yAxis._id;
37912
37931
  deselectSubplot(gd, xRef, yRef, searchTraces);
@@ -37927,6 +37946,8 @@ function prepSelect(evt, startX, startY, dragOptions, mode) {
37927
37946
  }
37928
37947
 
37929
37948
  if(selectionErased) {
37949
+ gd._fullLayout._noEmitSelectedAtStart = true;
37950
+
37930
37951
  Registry.call('_guiRelayout', gd, {
37931
37952
  selections: list
37932
37953
  });
@@ -38068,10 +38089,10 @@ function prepSelect(evt, startX, startY, dragOptions, mode) {
38068
38089
  displayOutlines(convertPoly(mergedPolygons, isOpenMode), outlines, dragOptions);
38069
38090
 
38070
38091
  if(isSelectMode) {
38071
- var _res = reselect(gd);
38092
+ var _res = reselect(gd, false);
38072
38093
  var extraPoints = _res.eventData ? _res.eventData.points.slice() : [];
38073
38094
 
38074
- _res = reselect(gd, selectionTesters, searchTraces, dragOptions);
38095
+ _res = reselect(gd, false, selectionTesters, searchTraces, dragOptions);
38075
38096
  selectionTesters = _res.selectionTesters;
38076
38097
  eventData = _res.eventData;
38077
38098
 
@@ -38165,9 +38186,13 @@ function prepSelect(evt, startX, startY, dragOptions, mode) {
38165
38186
  }
38166
38187
  }
38167
38188
 
38168
- Registry.call('_guiRelayout', gd, {
38169
- selections: subSelections
38170
- });
38189
+ if(subSelections.length < allSelections.length) {
38190
+ gd._fullLayout._noEmitSelectedAtStart = true;
38191
+
38192
+ Registry.call('_guiRelayout', gd, {
38193
+ selections: subSelections
38194
+ });
38195
+ }
38171
38196
  }
38172
38197
  }
38173
38198
  } else {
@@ -38213,7 +38238,9 @@ function prepSelect(evt, startX, startY, dragOptions, mode) {
38213
38238
  dragOptions.doneFnCompleted(selection);
38214
38239
  }
38215
38240
 
38216
- emitSelected(gd, eventData);
38241
+ if(isSelectMode) {
38242
+ emitSelected(gd, eventData);
38243
+ }
38217
38244
  }).catch(Lib.error);
38218
38245
  };
38219
38246
  }
@@ -38435,15 +38462,23 @@ function coerceSelectionsCache(evt, gd, dragOptions) {
38435
38462
  }
38436
38463
  }
38437
38464
 
38465
+ function hasActiveShape(gd) {
38466
+ return gd._fullLayout._activeShapeIndex >= 0;
38467
+ }
38468
+
38469
+ function hasActiveSelection(gd) {
38470
+ return gd._fullLayout._activeSelectionIndex >= 0;
38471
+ }
38472
+
38438
38473
  function clearSelectionsCache(dragOptions, immediateSelect) {
38439
38474
  var dragmode = dragOptions.dragmode;
38440
38475
  var plotinfo = dragOptions.plotinfo;
38441
38476
 
38442
38477
  var gd = dragOptions.gd;
38443
- if(gd._fullLayout._activeShapeIndex >= 0) {
38478
+ if(hasActiveShape(gd)) {
38444
38479
  gd._fullLayout._deactivateShape(gd);
38445
38480
  }
38446
- if(gd._fullLayout._activeSelectionIndex >= 0) {
38481
+ if(hasActiveSelection(gd)) {
38447
38482
  gd._fullLayout._deactivateSelection(gd);
38448
38483
  }
38449
38484
 
@@ -38471,11 +38506,13 @@ function clearSelectionsCache(dragOptions, immediateSelect) {
38471
38506
  var selections;
38472
38507
  if(
38473
38508
  isSelectMode &&
38474
- !dragOptions.subplot // only allow cartesian - no mapbox for now
38509
+ !hasSubplot(dragOptions) // only allow cartesian - no mapbox for now
38475
38510
  ) {
38476
38511
  selections = newSelections(outlines, dragOptions);
38477
38512
  }
38478
38513
  if(selections) {
38514
+ gd._fullLayout._noEmitSelectedAtStart = true;
38515
+
38479
38516
  Registry.call('_guiRelayout', gd, {
38480
38517
  selections: selections
38481
38518
  }).then(function() {
@@ -38510,7 +38547,10 @@ function determineSearchTraces(gd, xAxes, yAxes, subplot) {
38510
38547
 
38511
38548
  if(trace.visible !== true || !trace._module || !trace._module.selectPoints) continue;
38512
38549
 
38513
- if(subplot && (trace.subplot === subplot || trace.geo === subplot)) {
38550
+ if(
38551
+ hasSubplot({subplot: subplot}) &&
38552
+ (trace.subplot === subplot || trace.geo === subplot)
38553
+ ) {
38514
38554
  searchTraces.push(createSearchInfo(trace._module, cd, xAxes[0], yAxes[0]));
38515
38555
  } else if(trace.type === 'splom') {
38516
38556
  // FIXME: make sure we don't have more than single axis for splom
@@ -38810,7 +38850,7 @@ function _doSelect(selectionTesters, searchTraces) {
38810
38850
  return allSelections;
38811
38851
  }
38812
38852
 
38813
- function reselect(gd, selectionTesters, searchTraces, dragOptions) {
38853
+ function reselect(gd, mayEmitSelected, selectionTesters, searchTraces, dragOptions) {
38814
38854
  var hadSearchTraces = !!searchTraces;
38815
38855
  var plotinfo, xRef, yRef;
38816
38856
  if(dragOptions) {
@@ -38933,15 +38973,15 @@ function reselect(gd, selectionTesters, searchTraces, dragOptions) {
38933
38973
  updateSelectedState(gd, allSearchTraces, eventData);
38934
38974
 
38935
38975
  var clickmode = fullLayout.clickmode;
38936
- var sendEvents = clickmode.indexOf('event') > -1;
38976
+ var sendEvents = clickmode.indexOf('event') > -1 && mayEmitSelected;
38937
38977
 
38938
38978
  if(
38939
38979
  !plotinfo && // get called from plot_api & plots
38940
- fullLayout._reselect
38980
+ mayEmitSelected
38941
38981
  ) {
38942
- if(sendEvents) {
38943
- var activePolygons = getLayoutPolygons(gd, true);
38982
+ var activePolygons = getLayoutPolygons(gd, true);
38944
38983
 
38984
+ if(activePolygons.length) {
38945
38985
  var xref = activePolygons[0].xref;
38946
38986
  var yref = activePolygons[0].yref;
38947
38987
  if(xref && yref) {
@@ -38954,8 +38994,12 @@ function reselect(gd, selectionTesters, searchTraces, dragOptions) {
38954
38994
 
38955
38995
  fillRangeItems(eventData, poly);
38956
38996
  }
38997
+ }
38957
38998
 
38958
- emitSelected(gd, eventData);
38999
+ if(gd._fullLayout._noEmitSelectedAtStart) {
39000
+ gd._fullLayout._noEmitSelectedAtStart = false;
39001
+ } else {
39002
+ if(sendEvents) emitSelected(gd, eventData);
38959
39003
  }
38960
39004
 
38961
39005
  fullLayout._reselect = false;
@@ -38977,7 +39021,7 @@ function reselect(gd, selectionTesters, searchTraces, dragOptions) {
38977
39021
  if(eventData.points.length) {
38978
39022
  emitSelected(gd, eventData);
38979
39023
  } else {
38980
- gd.emit('plotly_deselect', null);
39024
+ emitDeselect(gd);
38981
39025
  }
38982
39026
  }
38983
39027
 
@@ -39265,13 +39309,10 @@ function getFillRangeItems(dragOptions) {
39265
39309
  }
39266
39310
 
39267
39311
  function emitSelecting(gd, eventData) {
39268
- if(drawMode(gd._fullLayout.dragmode)) return;
39269
39312
  gd.emit('plotly_selecting', eventData);
39270
39313
  }
39271
39314
 
39272
39315
  function emitSelected(gd, eventData) {
39273
- if(drawMode(gd._fullLayout.dragmode)) return;
39274
-
39275
39316
  if(eventData) {
39276
39317
  eventData.selections = (gd.layout || {}).selections || [];
39277
39318
  }
@@ -39280,7 +39321,6 @@ function emitSelected(gd, eventData) {
39280
39321
  }
39281
39322
 
39282
39323
  function emitDeselect(gd) {
39283
- if(drawMode(gd._fullLayout.dragmode)) return;
39284
39324
  gd.emit('plotly_deselect', null);
39285
39325
  }
39286
39326
 
@@ -56739,6 +56779,11 @@ var configAttributes = {
56739
56779
  }
56740
56780
  },
56741
56781
 
56782
+ editSelection: {
56783
+ valType: 'boolean',
56784
+ dflt: true,
56785
+ },
56786
+
56742
56787
  autosizable: {
56743
56788
  valType: 'boolean',
56744
56789
  dflt: false,
@@ -75742,7 +75787,16 @@ plots.redrag = function(gd) {
75742
75787
  };
75743
75788
 
75744
75789
  plots.reselect = function(gd) {
75745
- Registry.getComponentMethod('selections', 'reselect')(gd);
75790
+ var fullLayout = gd._fullLayout;
75791
+
75792
+ var A = (gd.layout || {}).selections;
75793
+ var B = fullLayout._previousSelections;
75794
+ fullLayout._previousSelections = A;
75795
+
75796
+ var mayEmitSelected = fullLayout._reselect ||
75797
+ JSON.stringify(A) !== JSON.stringify(B);
75798
+
75799
+ Registry.getComponentMethod('selections', 'reselect')(gd, mayEmitSelected);
75746
75800
  };
75747
75801
 
75748
75802
  plots.generalUpdatePerTraceModule = function(gd, subplot, subplotCalcData, subplotLayout) {
@@ -92673,7 +92727,7 @@ function getSortFunc(opts, d2c) {
92673
92727
  'use strict';
92674
92728
 
92675
92729
  // package version injected by `npm run preprocess`
92676
- exports.version = '2.13.1';
92730
+ exports.version = '2.14.0';
92677
92731
 
92678
92732
  },{}]},{},[12])(12)
92679
92733
  });