Skip to content

Commit 1a991d5

Browse files
committed
indicator: test that it supports layout.template
1 parent d87a448 commit 1a991d5

File tree

5 files changed

+97
-18
lines changed

5 files changed

+97
-18
lines changed

src/traces/indicator/attributes.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ module.exports = {
254254
'Sets the color for increasing value.'
255255
].join(' ')
256256
},
257+
// TODO: add attribute to show sign
257258
editType: 'plot'
258259
},
259260
decreasing: {
@@ -275,6 +276,7 @@ module.exports = {
275276
'Sets the color for increasing value.'
276277
].join(' ')
277278
},
279+
// TODO: add attribute to hide sign
278280
editType: 'plot'
279281
},
280282
font: extendFlat({}, textFontAttrs, {
@@ -335,7 +337,7 @@ module.exports = {
335337
dtick: axesAttrs.dtick,
336338
tickvals: axesAttrs.tickvals,
337339
ticktext: axesAttrs.ticktext,
338-
ticks: extendFlat({}, axesAttrs.ticks, {dflt: ''}),
340+
ticks: extendFlat({}, axesAttrs.ticks, {dflt: 'outside'}),
339341
ticklen: axesAttrs.ticklen,
340342
tickwidth: axesAttrs.tickwidth,
341343
tickcolor: axesAttrs.tickcolor,

src/traces/indicator/defaults.js

+9-12
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
8989
}
9090
if(traceOut._hasGauge) {
9191
gaugeIn = traceIn.gauge;
92+
if(!gaugeIn) gaugeIn = {};
9293
gaugeOut = Template.newContainer(traceOut, 'gauge');
9394
coerceGauge('shape');
9495
var isBullet = traceOut._isBullet = traceOut.gauge.shape === 'bullet';
@@ -113,14 +114,10 @@ function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
113114
coerceGauge('bar.thickness', defaultBarThickness);
114115

115116
// Gauge steps
116-
if(gaugeIn && gaugeIn.steps) {
117-
handleArrayContainerDefaults(gaugeIn, gaugeOut, {
118-
name: 'steps',
119-
handleItemDefaults: stepDefaults
120-
});
121-
} else {
122-
gaugeOut.steps = [];
123-
}
117+
handleArrayContainerDefaults(gaugeIn, gaugeOut, {
118+
name: 'steps',
119+
handleItemDefaults: stepDefaults
120+
});
124121

125122
// Gauge threshold
126123
coerceGauge('threshold.value');
@@ -135,20 +132,20 @@ function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
135132
coerceGaugeAxis('visible');
136133
coerceGaugeAxis('range', [0, 1.5 * traceOut.value]);
137134

135+
var opts = {outerTicks: true};
138136
handleTickValueDefaults(axisIn, axisOut, coerceGaugeAxis, 'linear');
139-
var opts = {outerTicks: false, font: layout.font};
140137
handleTickLabelDefaults(axisIn, axisOut, coerceGaugeAxis, 'linear', opts);
141-
handleTickMarkDefaults(axisIn, axisOut, coerceGaugeAxis, 'linear', opts);
138+
handleTickMarkDefaults(axisIn, axisOut, coerceGaugeAxis, opts);
142139
} else {
143140
coerce('title.align', 'center');
144141
coerce('align', 'center');
145142
traceOut._isAngular = traceOut._isBullet = false;
146143
}
147144
}
148145

149-
function stepDefaults(valueIn, valueOut) {
146+
function stepDefaults(stepIn, stepOut) {
150147
function coerce(attr, dflt) {
151-
return Lib.coerce(valueIn, valueOut, attributes.gauge.steps, attr, dflt);
148+
return Lib.coerce(stepIn, stepOut, attributes.gauge.steps, attr, dflt);
152149
}
153150

154151
coerce('color');
1.92 KB
Loading

test/image/mocks/indicator_grid_template.json

+4-5
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,17 @@
88
}, {
99
"type": "indicator",
1010
"value": 120,
11-
"delta": {"reference": 60},
1211
"gauge": {"shape": "bullet", "axis": {"visible": false}},
13-
"domain": {"row": 1, "y": [0.15, 0.35]}
12+
"domain": {"x": [0.05, 0.5], "y": [0.15, 0.35]}
1413
}, {
1514
"type": "indicator",
1615
"mode": "number+delta",
1716
"value": 120,
18-
"delta": {"reference": 60},
1917
"domain": {"row": 0, "column": 1}
2018
}, {
2119
"type": "indicator",
2220
"mode": "delta",
2321
"value": 40,
24-
"delta": {"reference": 60},
2522
"domain": {"row": 1, "column": 1}
2623
}],
2724
"layout": {
@@ -32,7 +29,9 @@
3229
"template": {
3330
"data": {
3431
"indicator": [{
35-
"mode": "number+delta+gauge"
32+
"title": {"text": "Title"},
33+
"mode": "number+delta+gauge",
34+
"delta": {"reference": 60}
3635
}]
3736
}
3837
}

test/jasmine/tests/indicator_test.js

+81
Original file line numberDiff line numberDiff line change
@@ -544,3 +544,84 @@ describe('Indicator animations', function() {
544544
});
545545
});
546546
});
547+
548+
describe('Indicator attributes', function() {
549+
var gd;
550+
beforeEach(function() {
551+
gd = createGraphDiv();
552+
});
553+
afterEach(destroyGraphDiv);
554+
555+
it('are inherited from template', function(done) {
556+
Plotly.newPlot(gd, [{
557+
type: 'indicator',
558+
value: 5,
559+
mode: 'number+delta+gauge'
560+
}], {template: {
561+
data: {
562+
indicator: [{
563+
delta: {
564+
valueformat: '0.9f',
565+
reference: -100,
566+
increasing: {
567+
symbol: 'a',
568+
color: 'blue'
569+
},
570+
font: {
571+
family: 'ArialDelta',
572+
size: 20
573+
}
574+
},
575+
number: {
576+
valueformat: '0.8f',
577+
suffix: 'km/h',
578+
font: {
579+
family: 'ArialNumber',
580+
color: 'blue'
581+
}
582+
},
583+
gauge: {
584+
axis: {
585+
range: [0, 500],
586+
tickcolor: 'white',
587+
tickangle: 20,
588+
tickwidth: 1
589+
},
590+
steps: [{
591+
range: [0, 250],
592+
color: 'rgba(255, 255, 0, 0.5)'
593+
}, {
594+
range: [250, 400],
595+
color: 'rgba(0, 0, 255, 0.75)'
596+
}]
597+
}
598+
}]
599+
}
600+
}})
601+
.then(function() {
602+
// Check number
603+
expect(gd._fullData[0].number.valueformat).toEqual('0.8f');
604+
expect(gd._fullData[0].number.suffix).toEqual('km/h');
605+
expect(gd._fullData[0].number.font.color).toEqual('blue');
606+
expect(gd._fullData[0].number.font.family).toEqual('ArialNumber');
607+
608+
// Check delta
609+
expect(gd._fullData[0].delta.valueformat).toEqual('0.9f');
610+
expect(gd._fullData[0].delta.reference).toEqual(-100);
611+
expect(gd._fullData[0].delta.increasing.symbol).toEqual('a');
612+
expect(gd._fullData[0].delta.font.family).toEqual('ArialDelta');
613+
expect(gd._fullData[0].delta.font.size).toEqual(20);
614+
615+
// Check gauge axis
616+
expect(gd._fullData[0].gauge.axis.range).toEqual([0, 500], 'wrong gauge.axis.range');
617+
expect(gd._fullData[0].gauge.axis.tickangle).toEqual(20, 'wrong gauge.axis.tickangle');
618+
expect(gd._fullData[0].gauge.axis.tickcolor).toBe('white', 'wrong gauge.axis.tickcolor');
619+
620+
// TODO: check this works once handleArrayContainerDefaults supports template
621+
// expect(gd._fullData[0].gauge.steps[0].range).toEqual([0, 250], 'wrong gauge.steps[0].range');
622+
// expect(gd._fullData[0].gauge.steps[0].color).toEqual('rgba(255, 255, 0, 0.5)');
623+
})
624+
.catch(failTest)
625+
.then(done);
626+
});
627+
});

0 commit comments

Comments
 (0)