Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 87d357b

Browse files
authored
Merge pull request plotly#1228 from plotly/uirevision
document uirevision
2 parents ea82aed + 05ffc45 commit 87d357b

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
title: Javascript Graphing Library uirevision with Plotly.react | Examples | Plotly
3+
name: uirevision in Plotly.react
4+
permalink: javascript/uirevision/
5+
description: Persist user interactions using uirevision with Plotly.react or Dash.
6+
layout: user-guide
7+
thumbnail: thumbnail/uirevision.gif
8+
language: plotly_js
9+
page_type: example_index
10+
has_thumbnail: true
11+
display_as: file_settings
12+
order: 21
13+
---
14+
{% assign examples = site.posts | where:"language","plotly_js" | where:"suite","uirevision" | sort: "order" %}
15+
{% include auto_examples.html examples=examples %}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
name: Persist User Changes
3+
plot_url: https://codepen.io/plotly/embed/ebMJEW/?height=550&theme-id=15263&default-tab=result
4+
language: plotly_js
5+
suite: uirevision
6+
order: 1
7+
sitemap: false
8+
arrangement: horizontal
9+
display_as: basic
10+
markdown_content: |
11+
Adding a `uirevision` attribute and then keeping it the same during the next call to Plotly.react ensures that user
12+
interactions persist.
13+
---
14+
const rand = () => Math.random();
15+
var x = [1, 2, 3, 4, 5];
16+
const new_data = (trace) => Object.assign(trace, {y: x.map(rand)});
17+
18+
// add random data to three line traces
19+
var data = [
20+
{mode:'lines', line: {color: "#b55400"}},
21+
{mode: 'lines', line: {color: "#393e46"}},
22+
{mode: 'lines', line: {color: "#222831"}}
23+
].map(new_data);
24+
25+
var layout = {
26+
title: 'User Zoom Persists<br>When uirevision Unchanged',
27+
uirevision:'true',
28+
xaxis: {autorange: true},
29+
yaxis: {autorange: true}
30+
};
31+
32+
Plotly.react(graphDiv, data, layout);
33+
34+
var myPlot = document.getElementById('graphDiv');
35+
36+
var cnt = 0;
37+
var interval = setInterval(function() {
38+
data = data.map(new_data);
39+
40+
// user interation will mutate layout and set autorange to false
41+
// so we need to reset it to true
42+
layout.xaxis.autorange = true;
43+
layout.yaxis.autorange = true;
44+
45+
// not changing uirevision will ensure that user interactions are unchanged
46+
// layout.uirevision = rand();
47+
48+
Plotly.react(graphDiv, data, layout);
49+
if(cnt === 100) clearInterval(interval);
50+
}, 2500);
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
name: Reset User Changes
3+
plot_url: https://codepen.io/plotly/embed/REMrgv/?height=550&theme-id=15263&default-tab=result
4+
language: plotly_js
5+
suite: uirevision
6+
order: 2
7+
sitemap: false
8+
arrangement: horizontal
9+
display_as: basic
10+
markdown_content: |
11+
Changing the `uirevision` attribute during a Plotly.react call will reset previous user interactions in the updated plot.
12+
---
13+
const rand = () => Math.random();
14+
var x = [1, 2, 3, 4, 5];
15+
const new_data = (trace) => Object.assign(trace, {y: x.map(rand)});
16+
17+
// add random data to three line traces
18+
var data = [
19+
{mode:'lines', line: {color: "#b55400"}},
20+
{mode: 'lines', line: {color: "#393e46"}},
21+
{mode: 'lines', line: {color: "#222831"}}
22+
].map(new_data);
23+
24+
var layout = {
25+
title: 'User Zoom Resets<br>When uirevision Changes',
26+
uirevision:'true',
27+
xaxis: {autorange: true},
28+
yaxis: {autorange: true}
29+
};
30+
31+
Plotly.react(graphDiv, data, layout);
32+
33+
var myPlot = document.getElementById('graphDiv');
34+
35+
var cnt = 0;
36+
var interval = setInterval(function() {
37+
data = data.map(new_data);
38+
39+
// user interation will mutate layout and set autorange to false
40+
// so we need to reset it to true
41+
layout.xaxis.autorange = true;
42+
layout.yaxis.autorange = true;
43+
44+
// a new random number should ensure that uirevision will be different
45+
// and so the graph will autorange after the Plotly.react
46+
layout.uirevision = rand();
47+
48+
Plotly.react(graphDiv, data, layout);
49+
if(cnt === 100) clearInterval(interval);
50+
}, 2500);

0 commit comments

Comments
 (0)