Skip to content

Test mathjax #1991

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 6, 2017
Merged
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
12 changes: 7 additions & 5 deletions src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Plotly.plot = function(gd, data, layout, config) {
// any part of the plotting code can push to gd._promises, then
// before we move to the next step, we check that they're all
// complete, and empty out the promise list again.
gd._promises = [];
if(!Array.isArray(gd._promises)) gd._promises = [];
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This I didn't write a test for... but I made this change so that if you make a plot, then change it before its promises have finished, you should still wait for them (via previousPromises) so you don't get a race condition between them and the new plot (with the old ones potentially overwriting elements of the new plot you made).

I haven't actually managed to cause any ill effects without this change in manual testing, but I think it's safer this way.


var graphWasEmpty = ((gd.data || []).length === 0 && Array.isArray(data));

Expand Down Expand Up @@ -384,14 +384,16 @@ Plotly.plot = function(gd, data, layout, config) {
drawData,
finalDraw,
initInteractions,
Plots.rehover
Plots.rehover,
Plots.previousPromises
];

Lib.syncOrAsync(seq, gd);

// even if everything we did was synchronous, return a promise
// so that the caller doesn't care which route we took
return Promise.all(gd._promises).then(function() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the crux of the issue: if you have more than one async item in seq, only the promises added to gd._promises by the first one will exist when this Promise.all is called (at the synchronous return of Lib.syncOrAsync), so any added after that will not be awaited. But Plots.previousPromises (added to the end of seq above) looks at gd._promises when it's actually invoked so it gets them all.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solid investigation work 🔬 🎉 🥇

Is this enough to close #76 you think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this enough to close #76 you think?

I think so!

var plotDone = Lib.syncOrAsync(seq, gd);
if(!plotDone || !plotDone.then) plotDone = Promise.resolve();

return plotDone.then(function() {
gd.emit('plotly_afterplot');
return gd;
});
Expand Down
Binary file added test/image/baselines/mathjax.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
76 changes: 76 additions & 0 deletions test/image/mocks/mathjax.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"data":[{
"x": [0, 1],
"y": [0, 1.414],
"text": ["Hx+yH", "H\\sqrt{2}H"],
"mode": "text+markers",
"name": "HE^2=m^2c^4+p^2c^2H"
}, {
"x": [0, 1],
"y": [1.4, 0.1],
"text": ["H1.400 \\pm 0.023H", "H0.100 \\pm 0.002H"],
"textposition": "auto",
"type": "bar",
"name": "Hx=\\frac{-b \\pm \\sqrt{b^2-4ac}}{2a}H"
}, {
"type": "pie",
"values": [1, 9],
"labels": ["H\\frac{1}{10}=10\\%H", "H\\frac{9}{10}=90\\%H"],
"textinfo": "label",
"domain": {"x": [0.3, 0.75], "y": [0.55, 1]}
}, {
"type": "heatmap",
"z": [[1,2],[3,4]],
"xaxis": "x2",
"yaxis": "y2",
"colorbar": {"title": "He^{i\\pi}=-1H", "y": 0.225, "len": 0.45}
}],
"layout": {
"yaxis":{"domain": [0, 0.45], "title": "$y=\\sin{2 \\theta}$"},
"xaxis":{
"domain": [0, 0.45],
"title": "$x=\\int_0^a a^2+1$",
"tickvals": [0, 1],
"ticktext": ["$\\frac{0}{100}$", "$\\frac{100}{100}$"]
},
"xaxis2": {"domain": [0.85, 1], "anchor": "y2"},
"yaxis2": {
"domain": [0, 0.45],
"anchor": "x2",
"tickvals": [0, 1],
"ticktext": ["Ha+b+c+dH", "He+f+g+hH"],
"title": "$(||01\\rangle+|10\\rangle)/\\sqrt2$"
},
"height":500,
"width":800,
"title": "$i\\hbar\\frac{d\\Psi}{dt}=-[V-\\frac{-\\hbar^2}{2m}\\nabla^2]\\Psi$",
"annotations":[
{
"text": "H is substituted for $<br>where we would like<br>math but do not yet<br>fully support it",
"xref": "paper", "yref": "paper",
"x": 1.2, "xanchor": "left", "y": 0, "yanchor": "bottom",
"showarrow": false
},
{
"text":"$(top,left)$","showarrow":false,"xref":"paper","yref":"paper",
"xanchor":"left","yanchor":"top","x":0,"y":1,"textangle":10,
"bordercolor":"#0c0","borderpad":3,"bgcolor":"#dfd"
},
{
"text":"$(right,bottom)$","xref":"paper","yref":"paper",
"xanchor":"right","yanchor":"bottom","x":0.2,"y":0.7,"ax":-20,"ay":-20,
"textangle":-30,"bordercolor":"#0c0","borderpad":3,"bgcolor":"#dfd",
"opacity":0.5
},
{"text":"$not-visible$", "visible": false},
{
"text":"$^{29}Si$","x":0.7,"y":0.7,"showarrow":false,
"xanchor":"right","yanchor":"top"
},
{
"text":"$^{17}O$","x":0.7,"y":0.7,"ax":15,"ay":-15,
"xanchor":"left","yanchor":"bottom"
}
]
}
}