|
1 | 1 | var Plotly = require('../../../lib/index'); |
2 | 2 | var Lib = require('../../../src/lib'); |
| 3 | +const Drawing = require('../../../src/components/drawing'); |
3 | 4 | var d3Select = require('../../strict-d3').select; |
4 | 5 |
|
5 | 6 | var createGraphDiv = require('../assets/create_graph_div'); |
@@ -252,6 +253,42 @@ describe('Test MathJax v' + mathjaxVersion + ':', function() { |
252 | 253 | .then(done, done.fail); |
253 | 254 | }); |
254 | 255 |
|
| 256 | + it('should measure a tex label at the font size of its own trace', (done) => { |
| 257 | + Plotly.newPlot(gd, [{ |
| 258 | + mode: 'markers+text', |
| 259 | + x: [0.5], |
| 260 | + y: [0.5], |
| 261 | + text: ['$\\alpha$'], |
| 262 | + textposition: 'auto', |
| 263 | + textfont: {size: 10} |
| 264 | + }, { |
| 265 | + mode: 'markers+text', |
| 266 | + x: [1, 1.3, 1.6, 1.9, 2.2, 2.5], |
| 267 | + y: [2, 2.1, 2, 2.1, 2, 2.1], |
| 268 | + text: ['$\\alpha$', '$\\alpha$', '$\\alpha$', '$\\alpha$', '$\\alpha$', '$\\alpha$'], |
| 269 | + textposition: 'auto', |
| 270 | + textfont: {size: 40} |
| 271 | + }], Lib.extendDeep({}, layout, {showlegend: false, xaxis: {range: [0, 3]}, yaxis: {range: [0, 3]}})) |
| 272 | + .then(() => { |
| 273 | + const sizes = []; |
| 274 | + |
| 275 | + d3Select(gd).selectAll('.textpoint').each(function() { |
| 276 | + const label = d3Select(this); |
| 277 | + const rect = label.select('.text-math-group').node().getBoundingClientRect(); |
| 278 | + const measured = Drawing.textPointBBox(label.select('text')); |
| 279 | + |
| 280 | + expect(Math.abs(measured.width - rect.width)).toBeLessThan(1, 'width of a tex label'); |
| 281 | + expect(Math.abs(measured.height - rect.height)).toBeLessThan(1, 'height of a tex label'); |
| 282 | + sizes.push(Math.round(rect.width)); |
| 283 | + }); |
| 284 | + |
| 285 | + // the two font sizes give two sizes of the same string |
| 286 | + expect(sizes.length).toBe(7, 'tex labels'); |
| 287 | + expect(sizes[1]).toBeGreaterThan(sizes[0] * 2, 'large label against small label'); |
| 288 | + }) |
| 289 | + .then(done, done.fail); |
| 290 | + }); |
| 291 | + |
255 | 292 | it('should place *auto* labels by their rendered box and hide the whole label', function(done) { |
256 | 293 | var n = 12; |
257 | 294 | var x = []; |
|
0 commit comments