Skip to content

Commit 5d93f74

Browse files
author
ivankirshin
committed
plotly#2261: Front: Reset zoom when detection time is applied
1 parent fda4d7d commit 5d93f74

File tree

4 files changed

+32
-18
lines changed

4 files changed

+32
-18
lines changed

lib/index-newcrom.d.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,8 @@ export function react(
435435
data: Data[],
436436
layout?: Partial<Layout>,
437437
config?: Partial<Config>,
438-
isForceUpdate?: boolean
438+
isForceUpdate?: boolean,
439+
xAxisRange?: [x0: number, x1: number] | null
439440
): Promise<PlotlyHTMLElement>;
440441
export function addFrames(root: Root, frames: Array<Partial<Frame>>): Promise<PlotlyHTMLElement>;
441442
export function deleteFrames(root: Root, frames: number[]): Promise<PlotlyHTMLElement>;

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "plotly.js-newcrom",
3-
"version": "2.27.1",
3+
"version": "2.27.1-1",
44
"description": "The open source javascript graphing library that powers plotly",
55
"license": "MIT",
66
"main": "./lib/index-newcrom.js",

src/plot_api/plot_api.js

+14-6
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ var numericNameWarningCountLimit = 5;
5757
*
5858
*/
5959
function _doPlot(gd, data, layout, config) {
60-
const isForceRerender = window.isForceRerender
61-
window.isForceRerender = false;
60+
const isForceRerender = window[`plotly-${gd.dataset.chartId}`].isForceRerender
61+
window[`plotly-${gd.dataset.chartId}`].isForceRerender = false;
6262

6363
var frames;
6464

@@ -330,9 +330,10 @@ function _doPlot(gd, data, layout, config) {
330330

331331
subroutines.doAutoRangeAndConstraints(gd);
332332

333+
// !!! We don't need to save an initial range because we change it if we apply a detection time.
333334
// store initial ranges *after* enforcing constraints, otherwise
334335
// we will never look like we're at the initial ranges
335-
if(graphWasEmpty) Axes.saveRangeInitial(gd);
336+
// if(graphWasEmpty) Axes.saveRangeInitial(gd);
336337

337338
// this one is different from shapes/annotations calcAutorange
338339
// the others incorporate those components into ax._extremes,
@@ -365,7 +366,8 @@ function _doPlot(gd, data, layout, config) {
365366
gd._fullLayout._insideTickLabelsUpdaterange = undefined;
366367

367368
return relayout(gd, insideTickLabelsUpdaterange).then(function() {
368-
Axes.saveRangeInitial(gd, true);
369+
// !!! We don't need to save an initial range because we change it if we apply a detection time.
370+
// Axes.saveRangeInitial(gd, true);
369371
});
370372
}
371373
}
@@ -552,6 +554,8 @@ function redraw(gd) {
552554
});
553555
}
554556

557+
const generateId = () => Math.random().toString(36).substr(2, 10);
558+
555559
/**
556560
* Convenience function to make idempotent plot option obvious to users.
557561
*
@@ -561,7 +565,9 @@ function redraw(gd) {
561565
* @param {Object} config
562566
*/
563567
function newPlot(gd, data, layout, config) {
568+
gd.dataset.chartId = generateId()
564569
gd = Lib.getGraphDiv(gd);
570+
window[`plotly-${gd.dataset.chartId}`] = {}
565571

566572
// remove gl contexts
567573
Plots.cleanPlot([], {}, gd._fullData || [], gd._fullLayout || {});
@@ -2635,7 +2641,9 @@ function applyUIRevisions(data, layout, oldFullData, oldFullLayout) {
26352641
* object containing `data`, `layout`, `config`, and `frames` members
26362642
*
26372643
*/
2638-
function react(gd, data, layout, config, isForce) {
2644+
function react(gd, data, layout, config, isForce, xAxisRange) {
2645+
window[`plotly-${gd.dataset.chartId}`].xAxisRange = xAxisRange;
2646+
26392647
var frames, plotDone;
26402648

26412649
function addFrames() { return exports.addFrames(gd, frames); }
@@ -2744,7 +2752,7 @@ function react(gd, data, layout, config, isForce) {
27442752
});
27452753
} else if(isForce || restyleFlags.fullReplot || relayoutFlags.layoutReplot || configChanged) {
27462754
gd._fullLayout._skipDefaults = true;
2747-
window.isForceRerender = true
2755+
window[`plotly-${gd.dataset.chartId}`].isForceRerender = true
27482756
seq.push(exports._doPlot);
27492757
} else {
27502758
for(var componentType in relayoutFlags.arrays) {

src/plots/cartesian/dragbox.js

+15-10
Original file line numberDiff line numberDiff line change
@@ -827,17 +827,22 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
827827
if(!ax.fixedrange) {
828828
var axName = ax._name;
829829

830-
var autorangeInitial = ax._autorangeInitial;
831-
if(ax._rangeInitial0 === undefined && ax._rangeInitial1 === undefined) {
832-
attrs[axName + '.autorange'] = true;
833-
} else if(ax._rangeInitial0 === undefined) {
834-
attrs[axName + '.autorange'] = autorangeInitial;
835-
attrs[axName + '.range'] = [null, ax._rangeInitial1];
836-
} else if(ax._rangeInitial1 === undefined) {
837-
attrs[axName + '.range'] = [ax._rangeInitial0, null];
838-
attrs[axName + '.autorange'] = autorangeInitial;
830+
const xAxisRange = window[`plotly-${gd.dataset.chartId}`].xAxisRange
831+
if (xAxisRange != null && axName === 'xaxis'){
832+
attrs[axName + '.range'] = [...xAxisRange];
839833
} else {
840-
attrs[axName + '.range'] = [ax._rangeInitial0, ax._rangeInitial1];
834+
var autorangeInitial = ax._autorangeInitial;
835+
if (ax._rangeInitial0 === undefined && ax._rangeInitial1 === undefined) {
836+
attrs[axName + '.autorange'] = true;
837+
} else if (ax._rangeInitial0 === undefined) {
838+
attrs[axName + '.autorange'] = autorangeInitial;
839+
attrs[axName + '.range'] = [null, ax._rangeInitial1];
840+
} else if (ax._rangeInitial1 === undefined) {
841+
attrs[axName + '.range'] = [ax._rangeInitial0, null];
842+
attrs[axName + '.autorange'] = autorangeInitial;
843+
} else {
844+
attrs[axName + '.range'] = [ax._rangeInitial0, ax._rangeInitial1];
845+
}
841846
}
842847
}
843848
}

0 commit comments

Comments
 (0)