Skip to content

Commit a4bce50

Browse files
committed
pie: test texttemplate with aggregated values
1 parent cb40618 commit a4bce50

File tree

2 files changed

+39
-26
lines changed

2 files changed

+39
-26
lines changed

Diff for: test/jasmine/assets/check_texttemplate.js

+28-26
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var supplyAllDefaults = require('../assets/supply_defaults');
99

1010
'use strict';
1111

12-
module.exports = function checkTextTemplate(mock, selector, tests) {
12+
module.exports = function checkTextTemplate(mock, selector, tests, skipExtra) {
1313
var isGL = Registry.traceIs(mock[0].type, 'gl');
1414
var isPolar = Registry.traceIs(mock[0].type, 'polar');
1515
var isScatterLike = Registry.traceIs(mock[0].type, 'scatter-like');
@@ -46,35 +46,37 @@ module.exports = function checkTextTemplate(mock, selector, tests) {
4646
});
4747
}
4848

49-
var N = tests[0][1].length;
50-
var i;
49+
// Extra tests
50+
if(!skipExtra) {
51+
var N = tests[0][1].length;
52+
var i;
5153

52-
// Generate customdata
53-
var customdata = [];
54-
for(i = 0; i < N; i++) {
55-
customdata.push(Lib.randstr({}));
56-
}
57-
mock[0].customdata = customdata;
58-
tests.push(['%{customdata}', customdata]);
54+
// Generate customdata
55+
var customdata = [];
56+
for(i = 0; i < N; i++) {
57+
customdata.push(Lib.randstr({}));
58+
}
59+
mock[0].customdata = customdata;
60+
tests.push(['%{customdata}', customdata]);
5961

60-
// Generate meta
61-
mock[0].meta = {'colname': 'A'};
62-
var metaSolution = [];
63-
for(i = 0; i < N; i++) {
64-
metaSolution.push(mock[0].meta.colname);
65-
}
66-
tests.push(['%{meta.colname}', metaSolution]);
62+
// Generate meta
63+
mock[0].meta = {'colname': 'A'};
64+
var metaSolution = [];
65+
for(i = 0; i < N; i++) {
66+
metaSolution.push(mock[0].meta.colname);
67+
}
68+
tests.push(['%{meta.colname}', metaSolution]);
6769

68-
// Make sure that empty text shows up as an empty string
69-
var emptyTextMock = Lib.extendDeep([], mock);
70-
var emptyTextSolution = [];
71-
emptyTextMock[0].text = [];
72-
for(i = 0; i < N; i++) {
73-
emptyTextMock[0].text[i] = '';
74-
emptyTextSolution[i] = 'text:';
70+
// Make sure that empty text shows up as an empty string
71+
var emptyTextMock = Lib.extendDeep([], mock);
72+
var emptyTextSolution = [];
73+
emptyTextMock[0].text = [];
74+
for(i = 0; i < N; i++) {
75+
emptyTextMock[0].text[i] = '';
76+
emptyTextSolution[i] = 'text:';
77+
}
78+
tests.push(['text:%{text}', emptyTextSolution, emptyTextMock]);
7579
}
76-
tests.push(['text:%{text}', emptyTextSolution, emptyTextMock]);
77-
7880
if(isGL) {
7981
tests.forEach(function(test) {
8082
it('@gl should support texttemplate', function(done) {

Diff for: test/jasmine/tests/pie_test.js

+11
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,17 @@ describe('Pie traces', function() {
876876
[['%{label} - %{value}', '%{text}', '%{value}', '%{percent}'], ['A - 1', 'textB', '3', '18.2%']],
877877
['%{text}-%{color}', ['textA-#d62728', 'textB-#1f77b4', 'textC-#ff7f0e', 'textD-#2ca02c']]
878878
]);
879+
880+
// Check texttemplate with aggregated values
881+
checkTextTemplate([{
882+
type: 'pie',
883+
values: [1, 1, 1],
884+
labels: ['A', 'A', 'B'],
885+
text: ['textA1', 'textA2', 'textB'],
886+
textposition: 'inside'
887+
}], 'g.slicetext', [
888+
['%{text}', ['textA1', 'textB']]
889+
], true);
879890
});
880891

881892
describe('pie hovering', function() {

0 commit comments

Comments
 (0)