Skip to content

Commit aeb6d1f

Browse files
committed
texttemplate: add support for scatterpolargl
1 parent 7fa4dc5 commit aeb6d1f

File tree

6 files changed

+33
-4
lines changed

6 files changed

+33
-4
lines changed

src/lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,7 @@ function templateFormatString(string, labels, d3locale) {
10671067

10681068
if(format) {
10691069
var fmt;
1070-
if(d3locale) {
1070+
if(d3locale && d3locale.numberFormat) {
10711071
fmt = d3locale.numberFormat;
10721072
} else {
10731073
fmt = d3.format;

src/traces/scattergl/convert.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ function convertTextStyle(trace) {
124124
optsOut.text.push(Lib.texttemplateString(texttemplate[i], pt, function() {}, pt));
125125
}
126126
} else {
127-
for(i = 0; i < trace.x.length; i++) {
127+
for(i = 0; i < count; i++) {
128128
pt = {};
129129
appendArrayPointValue(pt, trace, i);
130130
optsOut.text.push(Lib.texttemplateString(texttemplate, pt, function() {}, pt));

src/traces/scatterpolargl/attributes.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
var scatterPolarAttrs = require('../scatterpolar/attributes');
1212
var scatterGlAttrs = require('../scattergl/attributes');
13+
var texttemplateAttrs = require('../../plots/texttemplate_attributes');
1314

1415
module.exports = {
1516
mode: scatterPolarAttrs.mode,
@@ -22,6 +23,9 @@ module.exports = {
2223
thetaunit: scatterPolarAttrs.thetaunit,
2324

2425
text: scatterPolarAttrs.text,
26+
texttemplate: texttemplateAttrs({editType: 'plot'}, {
27+
keys: ['r', 'theta', 'text']
28+
}),
2529
hovertext: scatterPolarAttrs.hovertext,
2630
hovertemplate: scatterPolarAttrs.hovertemplate,
2731

src/traces/scatterpolargl/defaults.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
3434
coerce('thetaunit');
3535
coerce('mode', len < PTS_LINESONLY ? 'lines+markers' : 'lines');
3636
coerce('text');
37+
coerce('texttemplate');
3738
coerce('hovertext');
3839
if(traceOut.hoveron !== 'fills') coerce('hovertemplate');
3940

test/jasmine/assets/check_texttemplate.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ var supplyAllDefaults = require('../assets/supply_defaults');
1111

1212
module.exports = function checkTextTemplate(mock, selector, tests) {
1313
var isGL = Registry.traceIs(mock[0].type, 'gl');
14+
var isPolar = Registry.traceIs(mock[0].type, 'polar');
1415

1516
it('should not coerce textinfo when texttemplate', function() {
1617
var gd = {};
@@ -38,7 +39,12 @@ module.exports = function checkTextTemplate(mock, selector, tests) {
3839
Plotly.newPlot(gd, mockCopy)
3940
.then(function() {
4041
if(isGL) {
41-
var glText = gd._fullLayout._plots.xy._scene.glText;
42+
var glText;
43+
if(isPolar) {
44+
glText = gd._fullLayout.polar._subplot._scene.glText;
45+
} else {
46+
glText = gd._fullLayout._plots.xy._scene.glText;
47+
}
4248
expect(glText.length).toEqual(1);
4349
expect(glText[0].textOffsets.length).toEqual(test[1].length);
4450
for(var i = 0; i < glText[0].textOffsets.length - 1; i++) {
@@ -57,7 +63,10 @@ module.exports = function checkTextTemplate(mock, selector, tests) {
5763
}
5864
})
5965
.catch(failTest)
60-
.finally(destroyGraphDiv)
66+
.finally(function() {
67+
Plotly.purge(gd);
68+
destroyGraphDiv();
69+
})
6170
.then(done);
6271
});
6372
});

test/jasmine/tests/scatterpolargl_test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ var readPixel = require('../assets/read_pixel');
1111

1212
var customAssertions = require('../assets/custom_assertions');
1313
var assertHoverLabelContent = customAssertions.assertHoverLabelContent;
14+
var checkTextTemplate = require('../assets/check_texttemplate');
1415

1516
describe('Test scatterpolargl hover:', function() {
1617
var gd;
@@ -377,3 +378,17 @@ describe('Test scatterpolargl autorange:', function() {
377378
});
378379
});
379380
});
381+
382+
describe('Test scatterpolargl texttemplate:', function() {
383+
checkTextTemplate([{
384+
'type': 'scatterpolargl',
385+
'mode': 'markers+text',
386+
'text': ['A', 'B', 'C'],
387+
'textposition': 'top center',
388+
'r': [1, 0.5, 1],
389+
'theta': [0, 90, 180],
390+
}], 'g.textpoint', [
391+
['%{text}: (%{r:0.2f}, %{theta:0.1f})', ['A: (1.00, 0.0)', 'B: (0.50, 90.0)', 'C: (1.00, 180.0)']],
392+
[['', 'b%{theta:0.2f}', '%{theta:0.2f}'], ['', 'b90.00', '180.00']]
393+
]);
394+
});

0 commit comments

Comments
 (0)