Skip to content

Commit

Permalink
pie: test texttemplate with aggregated values
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinerg committed Sep 10, 2019
1 parent cb40618 commit a4bce50
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 26 deletions.
54 changes: 28 additions & 26 deletions test/jasmine/assets/check_texttemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var supplyAllDefaults = require('../assets/supply_defaults');

'use strict';

module.exports = function checkTextTemplate(mock, selector, tests) {
module.exports = function checkTextTemplate(mock, selector, tests, skipExtra) {
var isGL = Registry.traceIs(mock[0].type, 'gl');
var isPolar = Registry.traceIs(mock[0].type, 'polar');
var isScatterLike = Registry.traceIs(mock[0].type, 'scatter-like');
Expand Down Expand Up @@ -46,35 +46,37 @@ module.exports = function checkTextTemplate(mock, selector, tests) {
});
}

var N = tests[0][1].length;
var i;
// Extra tests
if(!skipExtra) {
var N = tests[0][1].length;
var i;

// Generate customdata
var customdata = [];
for(i = 0; i < N; i++) {
customdata.push(Lib.randstr({}));
}
mock[0].customdata = customdata;
tests.push(['%{customdata}', customdata]);
// Generate customdata
var customdata = [];
for(i = 0; i < N; i++) {
customdata.push(Lib.randstr({}));
}
mock[0].customdata = customdata;
tests.push(['%{customdata}', customdata]);

// Generate meta
mock[0].meta = {'colname': 'A'};
var metaSolution = [];
for(i = 0; i < N; i++) {
metaSolution.push(mock[0].meta.colname);
}
tests.push(['%{meta.colname}', metaSolution]);
// Generate meta
mock[0].meta = {'colname': 'A'};
var metaSolution = [];
for(i = 0; i < N; i++) {
metaSolution.push(mock[0].meta.colname);
}
tests.push(['%{meta.colname}', metaSolution]);

// Make sure that empty text shows up as an empty string
var emptyTextMock = Lib.extendDeep([], mock);
var emptyTextSolution = [];
emptyTextMock[0].text = [];
for(i = 0; i < N; i++) {
emptyTextMock[0].text[i] = '';
emptyTextSolution[i] = 'text:';
// Make sure that empty text shows up as an empty string
var emptyTextMock = Lib.extendDeep([], mock);
var emptyTextSolution = [];
emptyTextMock[0].text = [];
for(i = 0; i < N; i++) {
emptyTextMock[0].text[i] = '';
emptyTextSolution[i] = 'text:';
}
tests.push(['text:%{text}', emptyTextSolution, emptyTextMock]);
}
tests.push(['text:%{text}', emptyTextSolution, emptyTextMock]);

if(isGL) {
tests.forEach(function(test) {
it('@gl should support texttemplate', function(done) {
Expand Down
11 changes: 11 additions & 0 deletions test/jasmine/tests/pie_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,17 @@ describe('Pie traces', function() {
[['%{label} - %{value}', '%{text}', '%{value}', '%{percent}'], ['A - 1', 'textB', '3', '18.2%']],
['%{text}-%{color}', ['textA-#d62728', 'textB-#1f77b4', 'textC-#ff7f0e', 'textD-#2ca02c']]
]);

// Check texttemplate with aggregated values
checkTextTemplate([{
type: 'pie',
values: [1, 1, 1],
labels: ['A', 'A', 'B'],
text: ['textA1', 'textA2', 'textB'],
textposition: 'inside'
}], 'g.slicetext', [
['%{text}', ['textA1', 'textB']]
], true);
});

describe('pie hovering', function() {
Expand Down

0 comments on commit a4bce50

Please sign in to comment.