Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions draftlogs/XXXX_fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix values of the previous figure that stay in `Plotly.react`, `Plotly.relayout` and `Plotly.restyle` updates [[#XXXX](https://github.com/plotly/plotly.js/pull/XXXX)], with thanks to @akysil for the contribution!
3 changes: 3 additions & 0 deletions src/components/colorscale/cross_trace_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ module.exports = function crossTraceDefaults(fullData, fullLayout) {
// stash ref to color axis
cont._colorAx = fullLayout[cont.coloraxis];
} else {
// remove the color axis that relinkPrivateKeys copied from the previous figure
delete cont._colorAx;

var cOpts = extractOpts(cont);
var isAuto = cOpts.auto;

Expand Down
3 changes: 3 additions & 0 deletions src/plots/cartesian/axis_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, coerce,
handleItemDefaults: rangebreaksDefaults
});

// reset the flag here, so that relinkPrivateKeys does not keep the value of the previous figure
containerOut._hasDayOfWeekBreaks = false;

if(!containerOut.rangebreaks.length) {
delete containerOut.rangebreaks;
} else {
Expand Down
8 changes: 7 additions & 1 deletion src/plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ plots.supplyDefaults = function(gd, opts) {
// eg set `_requestRangeslider.x2 = true` for xaxis2
newFullLayout._requestRangeslider = {};

// range updates for inside tick labels, set by Axes.draw for the axes of this figure only
newFullLayout._insideTickLabelsUpdaterange = undefined;

// pull uids from old data to use as new defaults
newFullLayout._traceUids = getTraceUids(oldFullData, newData);

Expand Down Expand Up @@ -335,7 +338,10 @@ plots.supplyDefaults = function(gd, opts) {

if(oldFullData.length === newFullData.length) {
for(i = 0; i < newFullData.length; i++) {
relinkPrivateKeys(newFullData[i], oldFullData[i]);
// private keys of another trace type do not apply to the new trace
if(newFullData[i].type === oldFullData[i].type) {
relinkPrivateKeys(newFullData[i], oldFullData[i]);
}
}
}

Expand Down
49 changes: 49 additions & 0 deletions test/jasmine/tests/axes_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8539,6 +8539,55 @@ describe('more react tests', function() {
expect(gd._fullLayout.xaxis.range).toBeCloseToArray([-0.173, 2]);
}).then(done, done.fail);
});

it('should not keep the day-of-week tick steps after rangebreaks are removed', async () => {
const x = [];
const y = [];
let t = Date.UTC(2024, 0, 1);
while(x.length < 15) {
const weekday = new Date(t).getUTCDay();
if(weekday !== 0 && weekday !== 6) {
x.push(new Date(t).toISOString().slice(0, 10));
y.push(x.length);
}
t += ONEDAY;
}
const data = () => [{x, y}];
const layout = () => ({width: 700, height: 350});
const layoutWithBreaks = () => ({...layout(), xaxis: {rangebreaks: [{bounds: ['sat', 'mon']}]}});

await Plotly.newPlot(gd, data(), layout());
const newPlotDtick = gd._fullLayout.xaxis.dtick;
expect(newPlotDtick).toBeLessThan(ONEWEEK);

await Plotly.newPlot(gd, data(), layoutWithBreaks());
await Plotly.relayout(gd, 'xaxis.rangebreaks', null);
expect(gd._fullLayout.xaxis._hasDayOfWeekBreaks).withContext('relayout').toBe(false);
expect(gd._fullLayout.xaxis.dtick).withContext('relayout').toBe(newPlotDtick);

await Plotly.newPlot(gd, data(), layoutWithBreaks());
await Plotly.react(gd, data(), layout());
expect(gd._fullLayout.xaxis._hasDayOfWeekBreaks).withContext('react').toBe(false);
expect(gd._fullLayout.xaxis.dtick).withContext('react').toBe(newPlotDtick);
});

it('should not relayout axes of the previous figure for inside tick labels', async () => {
const sales = {y: [1, 3, 2]};
const costs = {y: [2, 1, 3], xaxis: 'x2', yaxis: 'y2'};

await Plotly.react(gd, [sales, costs], {
width: 700,
height: 400,
grid: {rows: 1, columns: 2, pattern: 'independent'},
xaxis2: {ticklabelposition: 'inside'},
yaxis2: {ticklabelposition: 'inside'}
});
await Plotly.react(gd, [sales], {width: 700, height: 400});

expect(gd._fullLayout._insideTickLabelsUpdaterange).toBeUndefined();
expect(gd._fullLayout._subplots.cartesian).toEqual(['xy']);
expect(d3SelectAll('.subplot').size()).toBe(1);
});
});

describe('category preservation tests on gd passed to Plotly.react()', function() {
Expand Down
29 changes: 29 additions & 0 deletions test/jasmine/tests/carpet_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -844,4 +844,33 @@ describe('contourcarpet plotting & editing', function() {
})
.then(done, done.fail);
});

[
{type: 'contour', withUids: false},
{type: 'contour', withUids: true},
{type: 'histogram2dcontour', withUids: false}
].forEach(({type, withUids}) => {
it(`can replace a contourcarpet trace with a ${type} trace using react${withUids ? ', with distinct uids' : ''}`, async () => {
const carpet = {type: 'carpet', a: [0.1, 0.2], b: [1.56, 1.01], y: [4.8, 5.1], carpet: 'c1'};
const contourcarpet = {type: 'contourcarpet', z: [0.22, 0.42], carpet: 'c1'};
const contour = type === 'contour' ?
{type, z: [[1, 2, 3], [2, 3, 4], [3, 4, 5]]} :
{type, x: [1, 2, 2, 3, 3, 3], y: [1, 1, 2, 2, 3, 3]};
const layout = {width: 500, height: 400};
if(withUids) {
carpet.uid = 'carpet';
contourcarpet.uid = 'contourcarpet';
contour.uid = 'contour';
}

await Plotly.newPlot(gd, [carpet, contourcarpet], layout);
await Plotly.react(gd, [carpet, contour], layout);

const trace = gd._fullData[1];
expect(trace.type).toBe(type);
expect(trace._carpetTrace).toBeUndefined();
expect(trace._carpet).toBeUndefined();
expect(d3SelectAll('.contour').size()).toBe(1);
});
});
});
30 changes: 30 additions & 0 deletions test/jasmine/tests/colorscale_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,36 @@ describe('Test colorscale restyle calls:', function() {
.then(done, done.fail);
});

it('should use the trace colorscale after the coloraxis is removed', async () => {
const left = [[1, 2, 3], [3, 4, 5]];
const right = [[2, 3, 9], [1, 5, 6]];
const layout = {width: 700, height: 350, grid: {rows: 1, columns: 2, xgap: 0.25}};

const shared = () => Plotly.react(gd, [
{type: 'heatmap', z: left, coloraxis: 'coloraxis'},
{type: 'heatmap', z: right, coloraxis: 'coloraxis', xaxis: 'x2'}
], {...layout, coloraxis: {colorscale: 'Viridis'}});

const assertOwnColorscales = (msg) => {
const fullData = gd._fullData;
expect(fullData[0]._colorAx === undefined).withContext(msg).toBe(true);
expect(fullData[1]._colorAx === undefined).withContext(msg).toBe(true);
expect([fullData[0].zmin, fullData[0].zmax]).withContext(msg).toEqual([1, 5]);
expect([fullData[1].zmin, fullData[1].zmax]).withContext(msg).toEqual([1, 9]);
};

await shared();
await Plotly.react(gd, [
{type: 'heatmap', z: left, colorscale: 'Viridis', colorbar: {x: 0.42}},
{type: 'heatmap', z: right, colorscale: 'Viridis', xaxis: 'x2'}
], layout);
assertOwnColorscales('react');

await shared();
await Plotly.restyle(gd, {coloraxis: [null]});
assertOwnColorscales('restyle');
});

it('@gl should work with scatter3d', function(done) {
Plotly.newPlot(gd, [{
type: 'scatter3d',
Expand Down