Skip to content

Commit 50ca29e

Browse files
authored
Merge pull request #3207 from plotly/issue-br3d
Implementation of break lines, sub & superscripts and bold & italic styles in WebGL texts
2 parents 3a32ac0 + fc82a19 commit 50ca29e

12 files changed

+85
-82
lines changed

package-lock.json

+23-23
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@
7777
"gl-line3d": "^1.1.6",
7878
"gl-mat4": "^1.2.0",
7979
"gl-mesh3d": "^2.0.2",
80-
"gl-plot2d": "^1.3.1",
81-
"gl-plot3d": "^1.5.11",
80+
"gl-plot2d": "^1.4.0",
81+
"gl-plot3d": "^1.6.0",
8282
"gl-pointcloud2d": "^1.0.1",
83-
"gl-scatter3d": "^1.0.16",
83+
"gl-scatter3d": "^1.1.0",
8484
"gl-select-box": "^1.0.2",
8585
"gl-spikes2d": "^1.0.1",
8686
"gl-streamtube3d": "^1.1.1",

src/lib/html2unicode.js

-45
This file was deleted.

src/plots/gl2d/convert.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
var Axes = require('../cartesian/axes');
1313

14-
var convertHTMLToUnicode = require('../../lib/html2unicode');
1514
var str2RGBArray = require('../../lib/str2rgbarray');
1615

1716
function Axes2DOptions(scene) {
@@ -118,7 +117,7 @@ proto.merge = function(options) {
118117

119118
for(j = 0; j <= 2; j += 2) {
120119
this.labelEnable[i + j] = false;
121-
this.labels[i + j] = convertHTMLToUnicode(axTitle);
120+
this.labels[i + j] = axTitle;
122121
this.labelColor[i + j] = str2RGBArray(ax.titlefont.color);
123122
this.labelFont[i + j] = ax.titlefont.family;
124123
this.labelSize[i + j] = ax.titlefont.size;

src/plots/gl2d/scene2d.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ var getContext = require('webgl-context');
2020

2121
var createOptions = require('./convert');
2222
var createCamera = require('./camera');
23-
var convertHTMLToUnicode = require('../../lib/html2unicode');
2423
var showNoWebGlMsg = require('../../lib/show_no_webgl_msg');
2524
var axisConstraints = require('../cartesian/constraints');
2625
var enforceAxisConstraints = axisConstraints.enforce;
@@ -279,7 +278,7 @@ proto.computeTickMarks = function() {
279278
for(var j = 0; j < 2; ++j) {
280279
for(var i = 0; i < nextTicks[j].length; ++i) {
281280
// coercing tick value (may not be a string) to a string
282-
nextTicks[j][i].text = convertHTMLToUnicode(nextTicks[j][i].text + '');
281+
nextTicks[j][i].text = nextTicks[j][i].text + '';
283282
}
284283
}
285284

src/plots/gl3d/layout/convert.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
'use strict';
1111

12-
var convertHTMLToUnicode = require('../../../lib/html2unicode');
1312
var str2RgbaArray = require('../../../lib/str2rgbarray');
1413

1514
var AXES_NAMES = ['xaxis', 'yaxis', 'zaxis'];
@@ -84,7 +83,7 @@ proto.merge = function(sceneLayout) {
8483
}
8584

8685
// Axes labels
87-
opts.labels[i] = convertHTMLToUnicode(axes.title);
86+
opts.labels[i] = axes.title;
8887
if('titlefont' in axes) {
8988
if(axes.titlefont.color) opts.labelColor[i] = str2RgbaArray(axes.titlefont.color);
9089
if(axes.titlefont.family) opts.labelFont[i] = axes.titlefont.family;

src/plots/gl3d/layout/tick_marks.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ module.exports = computeTickMarks;
1515

1616
var Axes = require('../../cartesian/axes');
1717
var Lib = require('../../../lib');
18-
var convertHTMLToUnicode = require('../../../lib/html2unicode');
1918

2019
var AXES_NAMES = ['xaxis', 'yaxis', 'zaxis'];
2120

@@ -73,7 +72,11 @@ function computeTickMarks(scene) {
7372
var dataTicks = Axes.calcTicks(axes);
7473
for(var j = 0; j < dataTicks.length; ++j) {
7574
dataTicks[j].x = dataTicks[j].x * scene.dataScale[i];
76-
dataTicks[j].text = convertHTMLToUnicode(dataTicks[j].text);
75+
76+
if(axes.type === 'date') {
77+
dataTicks[j].text =
78+
dataTicks[j].text.replace(/\<br\>/g, ' ');
79+
}
7780
}
7881
ticks[i] = dataTicks;
7982

src/plots/gl3d/scene.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ function render(scene) {
169169
scene.drawAnnotations(scene);
170170
}
171171

172-
function initializeGLPlot(scene, fullLayout, canvas, gl) {
172+
function initializeGLPlot(scene, canvas, gl) {
173173
var gd = scene.graphDiv;
174174

175175
var glplotOptions = {
@@ -318,7 +318,7 @@ function Scene(options, fullLayout) {
318318
this.convertAnnotations = Registry.getComponentMethod('annotations3d', 'convert');
319319
this.drawAnnotations = Registry.getComponentMethod('annotations3d', 'draw');
320320

321-
if(!initializeGLPlot(this, fullLayout)) return; // todo check the necessity for this line
321+
if(!initializeGLPlot(this)) return; // todo check the necessity for this line
322322
}
323323

324324
var proto = Scene.prototype;
@@ -334,7 +334,7 @@ proto.recoverContext = function() {
334334
requestAnimationFrame(tryRecover);
335335
return;
336336
}
337-
if(!initializeGLPlot(scene, scene.fullLayout, canvas, gl)) {
337+
if(!initializeGLPlot(scene, canvas, gl)) {
338338
Lib.error('Catastrophic and unrecoverable WebGL error. Context lost.');
339339
return;
340340
}
Loading
530 Bytes
Loading
65 Bytes
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"data": [
3+
{
4+
"x": [3],
5+
"y": [0],
6+
"z": [2],
7+
"text": ["This <i>text</i> was <b>too</b> long.<br>But <i><b>right now</b></i> it is <br>presented on<br>multiple <b><i>lines!<br>It is now<br>also possible</i></b> to use <sup>Super</sup> and <sub>Sub</sub><br>texts either <i>lower</i> or <b>UPPER</b> cases.<br><br>Aa<sup>Xx<sup>23.5<sup>Ab</sup></sup></sup><br>Aa<sub>Xx<sub>23.5<sub>Ab</sub></sub></sub>"],
8+
"type": "scatter3d",
9+
"mode":"markers+text",
10+
"textposition": "middle center"
11+
}
12+
],
13+
"layout": {
14+
"title":"Now texts could be displayed in 3D on multiple lines.",
15+
"width": 1200,
16+
"height": 900,
17+
"scene":{
18+
"xaxis":{
19+
"titlefont": {
20+
"color": "#f00",
21+
"family": "Sans-Serif",
22+
"size": 18
23+
},
24+
"title": "An axis with<br><i>Italic</i> & <b>bold</b> info! &\nSay no to '\\n'.<br>Only use <'br'> for line breaks."
25+
},
26+
"yaxis":{
27+
"titlefont": {
28+
"color": "#00f",
29+
"family": "Times New Roman",
30+
"size": 32
31+
},
32+
"title": "I<sub>x<sub>2<sub>n<sup>3</sup></sub></sub></sub> + z<sup>(n<sup>i</sup>+Log[y<sub>x<sup>2</sup></sub>])</sup>"
33+
},
34+
"zaxis":{
35+
"titlefont": {
36+
"color": "#0f0",
37+
"family": "Courier New",
38+
"size": 18
39+
},
40+
"title": "A <b>long</b><br>axis presented<br>on <i>multiple</i> lines."},
41+
"camera":{
42+
"eye":{"x":-1.5,"y":1.5,"z":1.5},
43+
"center":{"x":0,"y":0,"z":0},
44+
"up":{"x":0,"y":0,"z":1}
45+
}
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)