-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Implementation of textinfo for waterfall traces #3790
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
Changes from 5 commits
4a6c7c9
64f32e0
f33bed1
711a16d
a2e6e5b
cd5f09f
3832e01
dd5ff48
8846193
cad13aa
87b1c44
424d6f5
aec946e
4fb5a2b
75a5cb4
1504463
1434148
68bd371
3d5b8ff
8d02bcf
c6155db
020a34b
4c741c7
eea4a72
9507640
3159fab
bed6842
86c0c09
bdbbeb1
6ac1dc5
cad2728
92b9471
34e0a4b
7e52977
ba1b6c0
04049f2
6c8a661
2a3c354
1c82f91
6a3a13c
35dfe36
c63caf9
f249c61
d6f023a
0c169b5
c29b58d
e968da6
380db2e
61b6068
0236783
4d403fd
a650170
a744689
30b172a
446bacc
b93e3a5
02a176a
d0e8fe5
0eb3917
fd1f6ca
6d50386
79d6ef1
154e81e
a598343
d69f8a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,8 +22,9 @@ var Registry = require('../../registry'); | |
var attributes = require('./attributes'); | ||
var attributeText = attributes.text; | ||
var attributeTextPosition = attributes.textposition; | ||
var helpers = require('./helpers'); | ||
var style = require('./style'); | ||
var helpers = require('./helpers'); | ||
var pieHelpers = require('../pie/helpers'); | ||
|
||
// padding in pixels around text | ||
var TEXTPAD = 3; | ||
|
@@ -198,7 +199,7 @@ function appendBarText(gd, plotinfo, bar, calcTrace, i, x0, x1, y0, y1) { | |
var trace = calcTrace[0].trace; | ||
var orientation = trace.orientation; | ||
|
||
var text = getText(trace, i); | ||
var text = getText(calcTrace, i, fullLayout); | ||
textPosition = getTextPosition(trace, i); | ||
|
||
// compute text position | ||
|
@@ -469,12 +470,57 @@ function getTransform(textX, textY, targetX, targetY, scale, rotate) { | |
return transformTranslate + transformScale + transformRotate; | ||
} | ||
|
||
function getText(trace, index) { | ||
var value = helpers.getValue(trace.text, index); | ||
function getText(calcTrace, index, fullLayout) { | ||
var trace = calcTrace[0].trace; | ||
|
||
var value; | ||
if(!trace.textinfo || trace.textinfo === 'none') { | ||
value = helpers.getValue(trace.text, index); | ||
} else { | ||
value = calcTextinfo(calcTrace, index, fullLayout); | ||
} | ||
|
||
return helpers.coerceString(attributeText, value); | ||
} | ||
|
||
function getTextPosition(trace, index) { | ||
var value = helpers.getValue(trace.textposition, index); | ||
return helpers.coerceEnumerated(attributeTextPosition, value); | ||
} | ||
|
||
function calcTextinfo(calcTrace, index, fullLayout) { | ||
var trace = calcTrace[0].trace; | ||
var textinfo = trace.textinfo; | ||
var cdi = calcTrace[index]; | ||
|
||
var separators = fullLayout.separators; | ||
var parts = textinfo.split('+'); | ||
var text = []; | ||
|
||
var hasFlag = function(flag) { return parts.indexOf(flag) !== -1; }; | ||
|
||
if(hasFlag('label')) { | ||
if(trace.orientation === 'h') { | ||
text.push(trace.y[index]); | ||
} else { | ||
text.push(trace.x[index]); | ||
} | ||
} | ||
|
||
if(hasFlag('text')) { | ||
var tx = Lib.castOption(trace, cdi.i, 'text'); | ||
if(tx) text.push(tx); | ||
} | ||
|
||
if(trace.type === 'waterfall') { | ||
var delta = +cdi.rawS || cdi.s; | ||
var final = cdi.v; | ||
var initial = final - delta; | ||
|
||
if(hasFlag('initial')) text.push(pieHelpers.formatPieValue(initial, separators)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Try using cc fix3777-textinfo-waterfall-fin...funnel-new-proto#commitcomment-33323818 |
||
if(hasFlag('delta')) text.push(pieHelpers.formatPieValue(delta, separators)); | ||
if(hasFlag('final')) text.push(pieHelpers.formatPieValue(final, separators)); | ||
} | ||
|
||
return text.join('<br>'); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,8 @@ function supplyDefaults(traceIn, traceOut, defaultColor, layout) { | |
coerce('width'); | ||
|
||
coerce('text'); | ||
coerce('textinfo'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't coerce There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in bed6842. |
||
|
||
coerce('hovertext'); | ||
coerce('hovertemplate'); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
{ | ||
"data": [ | ||
{ | ||
"name": "2018", | ||
"type": "waterfall", | ||
"orientation": "h", | ||
"opacity": 0.5, | ||
"measure": [ | ||
"relative", | ||
"relative", | ||
"relative", | ||
"relative", | ||
"total", | ||
"relative", | ||
"relative", | ||
"relative", | ||
"relative", | ||
"total", | ||
"relative", | ||
"relative", | ||
"total", | ||
"relative", | ||
"total" | ||
], | ||
"y": [ | ||
"Sales", | ||
"Consulting", | ||
"Maintenance", | ||
"Other revenue", | ||
"Net revenue", | ||
"Purchases", | ||
"Material expenses", | ||
"Personnel expenses", | ||
"Other expenses", | ||
"Operating profit", | ||
"Investment income", | ||
"Financial income", | ||
"Profit before tax", | ||
"Income tax (15%)", | ||
"Profit after tax" | ||
], | ||
"text": [ | ||
"+ Sales", | ||
"+ Consulting", | ||
"+ Maintenance", | ||
"+ Other revenue", | ||
"= Net revenue", | ||
"- Purchases", | ||
"- Material expenses", | ||
"- Personnel expenses", | ||
"- Other expenses", | ||
"= Operating profit", | ||
"+ Investment income", | ||
"+ Financial income", | ||
"= Profit before tax", | ||
"- Income tax (15%)", | ||
"= Profit after tax" | ||
], | ||
"x": [ | ||
375, | ||
128, | ||
78, | ||
27, | ||
null, | ||
-327, | ||
-12, | ||
-78, | ||
-12, | ||
null, | ||
32, | ||
89, | ||
null, | ||
-45, | ||
null | ||
], | ||
"base": 0, | ||
"textinfo": "text+delta", | ||
"textposition": "outside" | ||
}, | ||
{ | ||
"name": "2019", | ||
"type": "waterfall", | ||
"orientation": "h", | ||
"measure": [ | ||
"relative", | ||
"relative", | ||
"relative", | ||
"relative", | ||
"total", | ||
"relative", | ||
"relative", | ||
"relative", | ||
"relative", | ||
"total", | ||
"relative", | ||
"relative", | ||
"total", | ||
"relative", | ||
"total" | ||
], | ||
"y": [ | ||
"Sales", | ||
"Consulting", | ||
"Maintenance", | ||
"Other revenue", | ||
"Net revenue", | ||
"Purchases", | ||
"Material expenses", | ||
"Personnel expenses", | ||
"Other expenses", | ||
"Operating profit", | ||
"Investment income", | ||
"Financial income", | ||
"Profit before tax", | ||
"Income tax (15%)", | ||
"Profit after tax" | ||
], | ||
"x": [ | ||
307, | ||
102, | ||
187, | ||
172, | ||
null, | ||
-302, | ||
-121, | ||
-187, | ||
-121, | ||
null, | ||
123, | ||
198, | ||
null, | ||
-53.7, | ||
null | ||
], | ||
"base": 255, | ||
"textinfo": "initial+final", | ||
"textposition": "outside" | ||
} | ||
], | ||
"layout": { | ||
"title": { | ||
"text": "Profit and loss statement 2018 vs 2019<br>waterfall chart" | ||
}, | ||
"yaxis": { | ||
"type": "category", | ||
"autorange": "reversed" | ||
}, | ||
"xaxis": { | ||
"type": "linear" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you try adding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call. |
||
}, | ||
"margin": { "l": 150, "r": 50 }, | ||
"height": 1200, | ||
"width": 900, | ||
"hovermode": "closest", | ||
"showlegend": true | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.