Skip to content

indicator: several improvements/fixes #4029

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Jul 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/traces/indicator/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ module.exports = {
number: {
valueformat: {
valType: 'string',
dflt: '.3s',
dflt: '',
role: 'info',
editType: 'plot',
description: [
Expand Down
11 changes: 8 additions & 3 deletions src/traces/indicator/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ function calc(gd, trace) {
var cd = [];

var lastReading = trace.value;
var secondLastReading = trace.delta ? trace.delta.reference : trace._lastValue || trace.value;
if(!(typeof trace._lastValue === 'number')) trace._lastValue = trace.value;
var secondLastReading = trace._lastValue;
var deltaRef = secondLastReading;
if(trace._hasDelta && typeof trace.delta.reference === 'number') {
deltaRef = trace.delta.reference;
}
cd[0] = {
y: lastReading,
lastY: secondLastReading,

delta: lastReading - secondLastReading,
relativeDelta: (lastReading - secondLastReading) / secondLastReading,
delta: lastReading - deltaRef,
relativeDelta: (lastReading - deltaRef) / deltaRef,
};
return cd;
}
Expand Down
8 changes: 5 additions & 3 deletions src/traces/indicator/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
traceOut._hasDelta = traceOut.mode.indexOf('delta') !== -1;
traceOut._hasGauge = traceOut.mode.indexOf('gauge') !== -1;

coerce('value');
var value = coerce('value');
traceOut._range = [0, (typeof value === 'number' ? 1.5 * value : 1)];

// Number attributes
var auto = new Array(2);
Expand Down Expand Up @@ -63,7 +64,7 @@ function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
}
coerce('delta.reference', traceOut.value);
coerce('delta.relative');
coerce('delta.valueformat', traceOut.delta.relative ? '2%' : '.3s');
coerce('delta.valueformat', traceOut.delta.relative ? '2%' : '');
coerce('delta.increasing.symbol');
coerce('delta.increasing.color');
coerce('delta.decreasing.symbol');
Expand All @@ -87,6 +88,7 @@ function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
function coerceGaugeAxis(attr, dflt) {
return Lib.coerce(axisIn, axisOut, attributes.gauge.axis, attr, dflt);
}

if(traceOut._hasGauge) {
gaugeIn = traceIn.gauge;
if(!gaugeIn) gaugeIn = {};
Expand Down Expand Up @@ -130,7 +132,7 @@ function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
if(gaugeIn) axisIn = gaugeIn.axis || {};
axisOut = Template.newContainer(gaugeOut, 'axis');
coerceGaugeAxis('visible');
coerceGaugeAxis('range', [0, 1.5 * traceOut.value]);
traceOut._range = coerceGaugeAxis('range', traceOut._range);

var opts = {outerTicks: true};
handleTickValueDefaults(axisIn, axisOut, coerceGaugeAxis, 'linear');
Expand Down
Loading