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

Skip to content

Commit f9062e4

Browse files
committed
texttemplate: add support for scatter3d
1 parent aeb6d1f commit f9062e4

File tree

5 files changed

+221
-0
lines changed

5 files changed

+221
-0
lines changed

src/traces/scatter3d/attributes.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
var scatterAttrs = require('../scatter/attributes');
1212
var colorAttributes = require('../../components/colorscale/attributes');
1313
var hovertemplateAttrs = require('../../components/fx/hovertemplate_attributes');
14+
var texttemplateAttrs = require('../../plots/texttemplate_attributes');
1415
var baseAttrs = require('../../plots/attributes');
1516
var DASHES = require('../../constants/gl3d_dashes');
1617

@@ -84,6 +85,9 @@ var attrs = module.exports = overrideAll({
8485
'If trace `hoverinfo` contains a *text* flag and *hovertext* is not set,',
8586
'these elements will be seen in the hover labels.'
8687
].join(' ')
88+
}),
89+
texttemplate: texttemplateAttrs({arrayOk: true}, {
90+
8791
}),
8892
hovertext: extendFlat({}, scatterAttrs.hovertext, {
8993
description: [

src/traces/scatter3d/convert.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ var makeBubbleSizeFn = require('../scatter/make_bubble_size_func');
2222
var DASH_PATTERNS = require('../../constants/gl3d_dashes');
2323
var MARKER_SYMBOLS = require('../../constants/gl3d_markers');
2424

25+
var appendArrayPointValue = require('../../components/fx/helpers').appendArrayPointValue;
26+
2527
var calculateError = require('./calc_errors');
2628

2729
function LineWithMarkers(scene, uid) {
@@ -239,6 +241,27 @@ function convertPlotlyOptions(scene, data) {
239241
for(i = 0; i < len; i++) text[i] = data.text;
240242
}
241243

244+
// check texttemplate
245+
if(data.texttemplate) {
246+
if(Array.isArray(data.texttemplate)) {
247+
text = new Array(data.texttemplate.length);
248+
for(i = 0; i < data.texttemplate.length; i++) {
249+
var pt = {};
250+
pt.text = text[i];
251+
appendArrayPointValue(pt, data, i);
252+
text[i] = Lib.texttemplateString(data.texttemplate[i], pt, function() {}, pt);
253+
}
254+
} else {
255+
text = new Array(len);
256+
for(i = 0; i < len; i++) {
257+
var pt1 = {};
258+
pt1.text = text[i];
259+
appendArrayPointValue(pt1, data, i);
260+
text[i] = Lib.texttemplateString(data.texttemplate, pt1, function() {}, pt1);
261+
}
262+
}
263+
}
264+
242265
// Build object parameters
243266
params = {
244267
position: points,

src/traces/scatter3d/defaults.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
3131
}
3232

3333
coerce('text');
34+
coerce('texttemplate');
3435
coerce('hovertext');
3536
coerce('hovertemplate');
3637
coerce('mode');
97.2 KB
Loading

test/image/mocks/texttemplate_2.json

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
{
2+
"data": [{
3+
"type": "scatter3d",
4+
"x": [0, 1, 2],
5+
"y": [0, 2, 1],
6+
"z": [-5, -2, 4],
7+
"texttemplate": "%{x}, %{y}, %{z}",
8+
"mode": "markers+text"
9+
}, {
10+
"type": "scattergeo",
11+
"mode": "markers+text",
12+
"lon": [
13+
-73.57,
14+
-79.24,
15+
-123.06
16+
],
17+
"lat": [
18+
45.5,
19+
43.4,
20+
49.13
21+
],
22+
"text": [
23+
"Montreal",
24+
"Toronto",
25+
"Vancouver"
26+
],
27+
"texttemplate": "%{text} (%{lonlat[0]}, %{lonlat[1]}): %{customdata:.2s}",
28+
"textposition": "top center",
29+
"customdata": [1780000, 2930000, 675218],
30+
"geo": "geo"
31+
}, {
32+
"type": "carpet",
33+
"carpet": "carpet1",
34+
"a": [0.1, 0.2, 0.3],
35+
"b": [1, 2, 3],
36+
"y": [
37+
[1, 2.2, 3],
38+
[1.5, 2.7, 3.5],
39+
[1.7, 2.9, 3.7]
40+
],
41+
"cheaterslope": 1,
42+
43+
"xaxis": "x2",
44+
"yaxis": "y2"
45+
},
46+
{
47+
"type": "scattercarpet",
48+
"carpet": "carpet1",
49+
"name": "b = 1.5",
50+
"mode": "markers+text",
51+
"a": [0.1, 0.15, 0.25, 0.3],
52+
"b": [1.5, 1.5, 1.5, 1.5],
53+
54+
"text": ["a", "b", "c", "d"],
55+
"texttemplate": "%{text}: (%{a}, %{b})",
56+
"textposition": "top center",
57+
"xaxis": "x2",
58+
"yaxis": "y2"
59+
}, {
60+
"type": "scattergl",
61+
"mode": "markers+text",
62+
"x": [0, 1, 2, 3],
63+
"y": [0, 1, 4, 9],
64+
65+
"text": ["a", "b", "c", "d"],
66+
"texttemplate": "%{text}: (%{x}, %{y})",
67+
"textposition": "top center",
68+
"xaxis": "x8",
69+
"yaxis": "y8"
70+
}, {
71+
"type": "scatterpolar",
72+
"mode": "markers+text",
73+
"text": ["A", "B", "C", "D"],
74+
"texttemplate": "%{text}: (%{r:0.2f},%{theta:0.2f})",
75+
"textposition": "top center",
76+
"r": [1, 0.5, 1, 1.5],
77+
"theta": [0, 90, 180, 270],
78+
"showgrid": false
79+
}, {
80+
"type": "scatterpolargl",
81+
"mode": "markers+text",
82+
"text": ["A", "B", "C", "D"],
83+
"texttemplate": "%{text}: (%{r:0.2f},%{theta:0.2f})",
84+
"textposition": "top center",
85+
"r": [1, 0.5, 1, 1.5],
86+
"theta": [0, 90, 180, 270],
87+
"showgrid": false,
88+
"subplot": "polar2"
89+
}, {
90+
"type": "scatterternary",
91+
"a": [
92+
3,
93+
2,
94+
5
95+
],
96+
"b": [
97+
2,
98+
5,
99+
2
100+
],
101+
"c": [
102+
5,
103+
2,
104+
2
105+
],
106+
"mode": "markers+text",
107+
"text": ["A", "B", "C"],
108+
"texttemplate": "%{text}<br>(%{a:.2f}, %{b:.2f}, %{c:.2f})",
109+
"textposition": "bottom center"
110+
}
111+
],
112+
"layout": {
113+
"showlegend": false,
114+
"width": 1000,
115+
"height": 500,
116+
"margin": {
117+
"t": 50,
118+
"b": 50,
119+
"l": 50,
120+
"r": 50
121+
},
122+
"geo": {
123+
"scope": "north america",
124+
"domain": {
125+
"row": 0,
126+
"column": 2
127+
},
128+
"lonaxis": {
129+
"range": [
130+
-130,
131+
-55
132+
]
133+
},
134+
"lataxis": {
135+
"range": [
136+
40,
137+
70
138+
]
139+
},
140+
"center": {
141+
"lat": 57
142+
}
143+
},
144+
"mapbox": {
145+
"domain": {"row": 1, "column": 0},
146+
"center": {"lon": -90, "lat": 45},
147+
"zoom": 0.7,
148+
"style": "white-bg"
149+
},
150+
"polar": {
151+
"radialaxis": {
152+
"showline": false,
153+
"linewidth": 0,
154+
"tickwidth": 2,
155+
"gridcolor": "white",
156+
"gridwidth": 0
157+
}
158+
},
159+
"polar2": {
160+
"domain": {
161+
"row": 1,
162+
"column": 2
163+
},
164+
"radialaxis": {
165+
"showline": false,
166+
"linewidth": 0,
167+
"tickwidth": 2,
168+
"gridcolor": "white",
169+
"gridwidth": 0
170+
}
171+
},
172+
"ternary": {
173+
"sum": 10,
174+
"domain": {
175+
"row": 0,
176+
"column": 3
177+
}
178+
},
179+
"scene": {
180+
"domain": {"row": 1, "column": 1}
181+
},
182+
"scene1": {
183+
"domain": {"row": 1, "column": 3}
184+
},
185+
"grid": {
186+
"rows": 2,
187+
"columns": 4,
188+
"pattern": "independent",
189+
"xgap": 5,
190+
"ygap": 5
191+
}
192+
}
193+
}

0 commit comments

Comments
 (0)