Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5b5f22a

Browse filesBrowse files
committed
add delta.prefix and delta.suffix in Indicator trace
1 parent fefa11c commit 5b5f22a
Copy full SHA for 5b5f22a

File tree

Expand file treeCollapse file tree

4 files changed

+27
-13
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+27
-13
lines changed

‎src/traces/indicator/attributes.js

Copy file name to clipboardExpand all lines: src/traces/indicator/attributes.js
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,22 @@ module.exports = {
248248
'Set the font used to display the delta'
249249
].join(' ')
250250
}),
251+
prefix: {
252+
valType: 'string',
253+
dflt: '',
254+
editType: 'plot',
255+
description: [
256+
'Sets a prefix appearing before the delta.'
257+
].join(' ')
258+
},
259+
suffix: {
260+
valType: 'string',
261+
dflt: '',
262+
editType: 'plot',
263+
description: [
264+
'Sets a suffix appearing next to the delta.'
265+
].join(' ')
266+
},
251267
editType: 'calc'
252268
},
253269
gauge: {

‎src/traces/indicator/defaults.js

Copy file name to clipboardExpand all lines: src/traces/indicator/defaults.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
6363
coerce('delta.decreasing.symbol');
6464
coerce('delta.decreasing.color');
6565
coerce('delta.position');
66+
coerce('delta.prefix');
67+
coerce('delta.suffix');
6668
deltaFontSize = traceOut.delta.font.size;
6769
}
6870
traceOut._scaleNumbers = (!traceOut._hasNumber || auto[0]) && (!traceOut._hasDelta || auto[1]) || false;

‎src/traces/indicator/plot.js

Copy file name to clipboardExpand all lines: src/traces/indicator/plot.js
+8-5Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -571,15 +571,15 @@ function drawNumbers(gd, plotGroup, cd, opts) {
571571
bignumberAx.setScale();
572572
Axes.prepTicks(bignumberAx);
573573

574-
var fmt = function(v) { return Axes.tickText(bignumberAx, v).text;};
574+
var bignumberFmt = function(v) { return Axes.tickText(bignumberAx, v).text;};
575575
var bignumberSuffix = trace.number.suffix;
576576
var bignumberPrefix = trace.number.prefix;
577577

578578
var number = numbers.select('text.number');
579579

580580
function writeNumber() {
581581
var txt = typeof cd[0].y === 'number' ?
582-
bignumberPrefix + fmt(cd[0].y) + bignumberSuffix :
582+
bignumberPrefix + bignumberFmt(cd[0].y) + bignumberSuffix :
583583
'-';
584584
number.text(txt)
585585
.call(Drawing.font, trace.number.font)
@@ -598,7 +598,7 @@ function drawNumbers(gd, plotGroup, cd, opts) {
598598
var interpolator = interpolateNumber(cd[0].lastY, cd[0].y);
599599
trace._lastValue = cd[0].y;
600600

601-
var transitionFmt = transitionFormat(trace.number.valueformat, fmt, cd[0].lastY, cd[0].y);
601+
var transitionFmt = transitionFormat(trace.number.valueformat, bignumberFmt, cd[0].lastY, cd[0].y);
602602
return function(t) {
603603
that.text(bignumberPrefix + transitionFmt(interpolator(t)) + bignumberSuffix);
604604
};
@@ -607,7 +607,7 @@ function drawNumbers(gd, plotGroup, cd, opts) {
607607
writeNumber();
608608
}
609609

610-
bignumberbBox = measureText(bignumberPrefix + fmt(cd[0].y) + bignumberSuffix, trace.number.font, numbersAnchor, gd);
610+
bignumberbBox = measureText(bignumberPrefix + bignumberFmt(cd[0].y) + bignumberSuffix, trace.number.font, numbersAnchor, gd);
611611
return number;
612612
}
613613

@@ -617,13 +617,16 @@ function drawNumbers(gd, plotGroup, cd, opts) {
617617
Axes.prepTicks(deltaAx);
618618

619619
var deltaFmt = function(v) { return Axes.tickText(deltaAx, v).text;};
620+
var deltaSuffix = trace.delta.suffix;
621+
var deltaPrefix = trace.delta.prefix;
622+
620623
var deltaValue = function(d) {
621624
var value = trace.delta.relative ? d.relativeDelta : d.delta;
622625
return value;
623626
};
624627
var deltaFormatText = function(value, numberFmt) {
625628
if(value === 0 || typeof value !== 'number' || isNaN(value)) return '-';
626-
return (value > 0 ? trace.delta.increasing.symbol : trace.delta.decreasing.symbol) + numberFmt(value);
629+
return (value > 0 ? trace.delta.increasing.symbol : trace.delta.decreasing.symbol) + deltaPrefix + numberFmt(value) + deltaSuffix;
627630
};
628631
var deltaFill = function(d) {
629632
return d.delta >= 0 ? trace.delta.increasing.color : trace.delta.decreasing.color;

‎test/image/mocks/indicator_scatter.json

Copy file name to clipboardExpand all lines: test/image/mocks/indicator_scatter.json
+1-8Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,10 @@
88
"type": "indicator",
99
"mode": "number+delta",
1010
"delta": {"reference": 512, "valueformat": ".0f"},
11-
"ticker": {
12-
"showticker": true
13-
},
14-
"vmax": 500,
1511
"value": 492
1612
}, {
1713
"name": "Users online",
18-
"y": [325, 324, 405, 400, 424, 404, 417, 432, 419, 394, 410, 426, 413, 419, 404, 408, 401, 377, 368, 361, 356, 359, 375, 397, 394, 418, 437, 450, 430, 442, 424, 443, 420, 418, 423, 423, 426, 440, 437, 436, 447, 460, 478, 472, 450, 456, 436, 418, 429, 412, 429, 442, 464, 447, 434, 457, 474, 480, 499, 497, 480, 502, 512, 492],
19-
"marker": {
20-
"color": "rgba(255, 255, 255, 0.5)"
21-
}
14+
"y": [325, 324, 405, 400, 424, 404, 417, 432, 419, 394, 410, 426, 413, 419, 404, 408, 401, 377, 368, 361, 356, 359, 375, 397, 394, 418, 437, 450, 430, 442, 424, 443, 420, 418, 423, 423, 426, 440, 437, 436, 447, 460, 478, 472, 450, 456, 436, 418, 429, 412, 429, 442, 464, 447, 434, 457, 474, 480, 499, 497, 480, 502, 512, 492]
2215
}],
2316
"layout": {
2417
"width": 400,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.