Skip to content

Commit 1a05658

Browse files
committed
support blank tickformat for indicator traces
1 parent fc5c2c9 commit 1a05658

13 files changed

+245
-155
lines changed

src/plots/cartesian/axes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2183,7 +2183,7 @@ axes.makeLabelFns = function(ax, shift, angle) {
21832183
labelShift = ax.ticklen * Math.sin(rad);
21842184
}
21852185
if(ax.showticklabels && (ticksOnOutsideLabels || ax.showline)) {
2186-
labelStandoff += 0.2 * ax.tickfont.size;
2186+
labelStandoff += 0.2 * ((ax.tickfont || {}).size || 0);
21872187
}
21882188
labelStandoff += (ax.linewidth || 1) / 2;
21892189

src/traces/indicator/attributes.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ module.exports = {
162162
number: {
163163
valueformat: {
164164
valType: 'string',
165-
dflt: '.3s',
165+
dflt: '',
166166
role: 'info',
167167
editType: 'plot',
168168
description: [
@@ -227,6 +227,7 @@ module.exports = {
227227
},
228228
valueformat: {
229229
valType: 'string',
230+
dflt: '',
230231
role: 'info',
231232
editType: 'plot',
232233
description: [

src/traces/indicator/defaults.js

+164-18
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,18 @@
88

99
'use strict';
1010

11+
var isNumeric = require('fast-isnumeric');
1112
var Lib = require('../../lib');
1213
var attributes = require('./attributes');
1314
var handleDomainDefaults = require('../../plots/domain').defaults;
1415
var Template = require('../../plot_api/plot_template');
1516
var handleArrayContainerDefaults = require('../../plots/array_container_defaults');
17+
18+
var Axes = require('../../plots/cartesian/axes');
19+
var axesAttrs = require('../../plots/cartesian/layout_attributes');
20+
var handleAxisDefaults = require('../../plots/cartesian/axis_defaults');
21+
var handleAxisPositionDefaults = require('../../plots/cartesian/position_defaults');
22+
1623
var cn = require('./constants.js');
1724

1825
var handleTickValueDefaults = require('../../plots/cartesian/tick_value_defaults');
@@ -33,13 +40,21 @@ function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
3340
traceOut._hasGauge = traceOut.mode.indexOf('gauge') !== -1;
3441

3542
coerce('value');
43+
var dfltRange0 = 0;
44+
var dfltRange1 = 1.5 * traceOut.value;
45+
var range = Lib.coerce(traceIn, traceOut, attributes.gauge.axis, 'range', [dfltRange0, dfltRange1]);
46+
var keepRangeIn;
47+
if(traceIn.gauge && traceIn.gauge.axis && traceIn.gauge.axis.range) {
48+
keepRangeIn = [traceIn.gauge.axis.range[0], traceIn.gauge.axis.range[1]];
49+
if(!isNumeric(traceIn.gauge.axis.range[0])) traceIn.gauge.axis.range[0] = dfltRange0;
50+
if(!isNumeric(traceIn.gauge.axis.range[1])) traceIn.gauge.axis.range[1] = dfltRange1;
51+
}
3652

3753
// Number attributes
3854
var auto = new Array(2);
3955
var bignumberFontSize;
4056
if(traceOut._hasNumber) {
4157
coerce('number.valueformat');
42-
if(!traceOut.number.valueformat) traceOut.number.valueformat = attributes.number.valueformat.dflt;
4358
coerce('number.font.color', layout.font.color);
4459
coerce('number.font.family', layout.font.family);
4560
coerce('number.font.size');
@@ -65,7 +80,6 @@ function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
6580
coerce('delta.reference', traceOut.value);
6681
coerce('delta.relative');
6782
coerce('delta.valueformat');
68-
if(!traceOut.delta.valueformat) traceOut.delta.valueformat = traceOut.delta.relative ? '2%' : '.3s';
6983
coerce('delta.increasing.symbol');
7084
coerce('delta.increasing.color');
7185
coerce('delta.decreasing.symbol');
@@ -82,13 +96,12 @@ function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
8296
coerce('title.text');
8397

8498
// Gauge attributes
85-
var gaugeIn, gaugeOut, axisIn, axisOut;
99+
var gaugeIn, gaugeOut;
100+
86101
function coerceGauge(attr, dflt) {
87102
return Lib.coerce(gaugeIn, gaugeOut, attributes.gauge, attr, dflt);
88103
}
89-
function coerceGaugeAxis(attr, dflt) {
90-
return Lib.coerce(axisIn, axisOut, attributes.gauge.axis, attr, dflt);
91-
}
104+
92105
if(traceOut._hasGauge) {
93106
gaugeIn = traceIn.gauge;
94107
if(!gaugeIn) gaugeIn = {};
@@ -126,23 +139,156 @@ function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
126139
coerceGauge('threshold.thickness');
127140
coerceGauge('threshold.line.width');
128141
coerceGauge('threshold.line.color');
129-
130-
// Gauge axis
131-
axisIn = {};
132-
if(gaugeIn) axisIn = gaugeIn.axis || {};
133-
axisOut = Template.newContainer(gaugeOut, 'axis');
134-
coerceGaugeAxis('visible');
135-
coerceGaugeAxis('range', [0, 1.5 * traceOut.value]);
136-
137-
var opts = {outerTicks: true};
138-
handleTickValueDefaults(axisIn, axisOut, coerceGaugeAxis, 'linear');
139-
handleTickLabelDefaults(axisIn, axisOut, coerceGaugeAxis, 'linear', opts);
140-
handleTickMarkDefaults(axisIn, axisOut, coerceGaugeAxis, opts);
141142
} else {
142143
coerce('title.align', 'center');
143144
coerce('align', 'center');
144145
traceOut._isAngular = traceOut._isBullet = false;
145146
}
147+
148+
var axType = 'linear';
149+
150+
function prepareAxis(axisOut, axisIn, axisAttr) {
151+
var coerceAxis = function(attr, dflt) {
152+
return Lib.coerce(axisIn, axisOut, axisAttr, attr, dflt);
153+
};
154+
155+
axisOut._id = 'x';
156+
axisOut.type = 'linear';
157+
axisOut.range = range;
158+
axisOut.dtick = 0.1 * Math.abs(range[1] - range[0]) || 1;
159+
160+
coerceAxis('visible');
161+
Axes.setConvert(axisOut, layout);
162+
Axes.prepTicks(axisOut);
163+
164+
var tickOptions = {
165+
outerTicks: true
166+
};
167+
handleTickLabelDefaults(axisIn, axisOut, coerceAxis, axType, tickOptions, {pass: 1});
168+
handleTickValueDefaults(axisIn, axisOut, coerceAxis, axType);
169+
handleTickLabelDefaults(axisIn, axisOut, coerceAxis, axType, tickOptions, {pass: 2});
170+
handleTickMarkDefaults(axisIn, axisOut, coerceAxis, tickOptions);
171+
172+
var axisOptions = {
173+
letter: 'x',
174+
font: layout.font,
175+
noHover: true,
176+
noTickson: true
177+
};
178+
handleAxisDefaults(axisIn, axisOut, coerceAxis, axisOptions, layout);
179+
handleAxisPositionDefaults(axisIn, axisOut, coerceAxis, axisOptions);
180+
181+
return axisOut;
182+
}
183+
184+
// Gauge axis
185+
if(traceOut._hasGauge) {
186+
var ax = (traceIn.gauge || {}).axis || {};
187+
var e;
188+
189+
// interface for all possible inputs
190+
var axIn = {
191+
range: ax.range,
192+
visible: ax.visible,
193+
tickmode: ax.tickmode,
194+
nticks: ax.nticks,
195+
tick0: ax.tick0,
196+
dtick: ax.dtick,
197+
tickvals: ax.tickvals,
198+
ticktext: ax.ticktext,
199+
ticks: ax.ticks,
200+
ticklen: ax.ticklen,
201+
tickwidth: ax.tickwidth,
202+
tickcolor: ax.tickcolor,
203+
showticklabels: ax.showticklabels,
204+
tickfont: ax.tickfont,
205+
tickangle: ax.tickangle,
206+
tickformat: ax.tickformat,
207+
tickformatstops: ax.tickformatstops,
208+
tickprefix: ax.tickprefix,
209+
showtickprefix: ax.showtickprefix,
210+
ticksuffix: ax.ticksuffix,
211+
showticksuffix: ax.showticksuffix,
212+
separatethousands: ax.separatethousands,
213+
exponentformat: ax.exponentformat,
214+
showexponent: ax.showexponent
215+
};
216+
217+
// remove undefind keys
218+
for(e in axIn) {
219+
if(axIn[e] === undefined) {
220+
delete axIn[e];
221+
}
222+
}
223+
224+
traceOut.gauge._axis = prepareAxis(
225+
Template.newContainer(traceOut.gauge, '_axis'),
226+
axIn,
227+
axesAttrs
228+
);
229+
230+
ax = traceOut.gauge._axis;
231+
232+
// interface for all possible outputs
233+
var axOut = traceOut.gauge.axis = {
234+
range: ax.range,
235+
visible: ax.visible,
236+
tickmode: ax.tickmode,
237+
nticks: ax.nticks,
238+
tick0: ax.tick0,
239+
dtick: ax.dtick,
240+
tickvals: ax.tickvals,
241+
ticktext: ax.ticktext,
242+
ticks: ax.ticks,
243+
ticklen: ax.ticklen,
244+
tickwidth: ax.tickwidth,
245+
tickcolor: ax.tickcolor,
246+
showticklabels: ax.showticklabels,
247+
tickfont: ax.tickfont,
248+
tickangle: ax.tickangle,
249+
tickformat: ax.tickformat,
250+
tickformatstops: ax.tickformatstops,
251+
tickprefix: ax.tickprefix,
252+
showtickprefix: ax.showtickprefix,
253+
ticksuffix: ax.ticksuffix,
254+
showticksuffix: ax.showticksuffix,
255+
separatethousands: ax.separatethousands,
256+
exponentformat: ax.exponentformat,
257+
showexponent: ax.showexponent
258+
};
259+
260+
// remove undefind keys
261+
for(e in axOut) {
262+
if(axOut[e] === undefined) {
263+
delete axOut[e];
264+
}
265+
}
266+
}
267+
268+
// Number axis
269+
if(traceOut._hasNumber) {
270+
traceOut.number._axis = prepareAxis(
271+
Template.newContainer(traceOut.number, '_axis'),
272+
{
273+
tickformat: traceOut.number.valueformat
274+
},
275+
axesAttrs
276+
);
277+
}
278+
279+
// Delta axis
280+
if(traceOut._hasDelta && traceOut.delta) {
281+
traceOut.delta._axis = prepareAxis(
282+
Template.newContainer(traceOut.delta, '_axis'),
283+
{
284+
tickformat: traceOut.delta.valueformat
285+
},
286+
axesAttrs
287+
);
288+
}
289+
290+
delete traceOut.range;
291+
if(keepRangeIn) traceIn.gauge.axis.range = keepRangeIn;
146292
}
147293

148294
function stepDefaults(stepIn, stepOut) {

0 commit comments

Comments
 (0)