Skip to content

Commit b6843a6

Browse files
authored
Merge pull request #1788 from plotly/annotations-mathjax
fix and test annotations with mathjax
2 parents 91c0b8d + 1beda28 commit b6843a6

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

src/components/annotations/draw.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
237237
// at the end, even if their position changes
238238
annText.selectAll('tspan.line').attr({y: 0, x: 0});
239239

240-
var mathjaxGroup = annTextGroupInner.select('.annotation-math-group');
240+
var mathjaxGroup = annTextGroupInner.select('.annotation-text-math-group');
241241
var hasMathjax = !mathjaxGroup.empty();
242242
var anntextBB = Drawing.bBox(
243243
(hasMathjax ? mathjaxGroup : annText).node());

src/lib/svg_text_utils.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ exports.convertToTspans = function(_context, gd, _callback) {
3030

3131
// Until we get tex integrated more fully (so it can be used along with non-tex)
3232
// allow some elements to prohibit it by attaching 'data-notex' to the original
33-
var tex = (!_context.attr('data-notex')) && str.match(FIND_TEX);
33+
var tex = (!_context.attr('data-notex')) &&
34+
(typeof MathJax !== 'undefined') &&
35+
str.match(FIND_TEX);
36+
3437
var parent = d3.select(_context.node().parentNode);
3538
if(parent.empty()) return;
3639
var svgClass = (_context.attr('class')) ? _context.attr('class').split(' ')[0] : 'text';

src/plots/cartesian/dragbox.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ var setCursor = require('../../lib/setcursor');
2222
var dragElement = require('../../components/dragelement');
2323
var FROM_TL = require('../../constants/alignment').FROM_TL;
2424

25+
var Plots = require('../plots');
26+
2527
var doTicks = require('./axes').doTicks;
2628
var getFromId = require('./axis_ids').getFromId;
2729
var prepSelect = require('./select');
@@ -655,7 +657,13 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
655657
// be repositioning the data in the relayout. But DON'T call
656658
// ticksAndAnnotations again - it's unnecessary and would overwrite `updates`
657659
updateSubplots([0, 0, pw, ph]);
658-
Plotly.relayout(gd, updates);
660+
661+
// since we may have been redrawing some things during the drag, we may have
662+
// accumulated MathJax promises - wait for them before we relayout.
663+
Lib.syncOrAsync([
664+
Plots.previousPromises,
665+
function() { Plotly.relayout(gd, updates); }
666+
], gd);
659667
}
660668

661669
// updateSubplots - find all plot viewboxes that should be

test/jasmine/tests/annotations_test.js

+6
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ describe('annotations relayout', function() {
159159
var mockData = Lib.extendDeep([], mock.data),
160160
mockLayout = Lib.extendDeep({}, mock.layout);
161161

162+
// insert some MathJax text - to make sure we fall back correctly
163+
// when MathJax is not provided (as is the case in our normal
164+
// jasmine test suite)
165+
expect(typeof MathJax).toBe('undefined');
166+
mockLayout.annotations[14].text = '$x+y+z$';
167+
162168
Plotly.plot(gd, mockData, mockLayout).then(done);
163169

164170
spyOn(Loggers, 'warn');

0 commit comments

Comments
 (0)