Skip to content

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

Merged
merged 65 commits into from
May 8, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
4a6c7c9
waterfall text info
archmoj Apr 18, 2019
64f32e0
added label option - fixup computed value - improve mock and print order
archmoj Apr 19, 2019
f33bed1
rename new mock filename i.e. hoverinfo > textinfo
archmoj Apr 24, 2019
711a16d
revised flag order and output
archmoj Apr 24, 2019
a2e6e5b
Merge remote-tracking branch 'origin/master' into fix3777-textinfo-wa…
archmoj Apr 24, 2019
cd5f09f
replace pie helpers with ax ticktext - fixup and added tests
archmoj Apr 29, 2019
3832e01
add funnel - changes to lib
archmoj Apr 13, 2019
dd5ff48
add funnel - changes to src plot plot_api and legend style
archmoj Apr 13, 2019
8846193
add funnel - chanegs to bar
archmoj Apr 13, 2019
cad13aa
add funnel - new trace files
archmoj Apr 13, 2019
87b1c44
add funnel test - mocks and baselines
archmoj Apr 13, 2019
424d6f5
add funnel jasmine test
archmoj Apr 15, 2019
aec946e
revisions after etpinard comments
archmoj Apr 26, 2019
4fb5a2b
add comment to describe how trace._base is different than trace.base …
archmoj Apr 29, 2019
75a5cb4
clean up bar cross calc - pass prefix - remove mockGd from funnel and…
archmoj Apr 30, 2019
1504463
combine blank horizontal and vertical bar text mocks in one
archmoj Apr 30, 2019
1434148
reduced number of funnel mocks
archmoj Apr 30, 2019
68bd371
remove unused handleGroupingDefaults exports from funnel and waterfal…
archmoj Apr 30, 2019
3d5b8ff
remove unused node3 link from funnel and waterfall plots
archmoj Apr 30, 2019
8d02bcf
describe non-arrayOk textinfo flags
archmoj Apr 30, 2019
c6155db
cut category types from funnel axis mocks and add anchors
archmoj Apr 30, 2019
020a34b
rm autorange true
archmoj Apr 30, 2019
4c741c7
finalize connector line and region edit types
archmoj Apr 30, 2019
eea4a72
revise funnel select and fixup select test
archmoj Apr 30, 2019
9507640
fixup axis anchors and added histogram case in image tests
archmoj Apr 30, 2019
3159fab
fixup new waterfall_axis mock
archmoj Apr 30, 2019
bed6842
dont coerce waterfall textinfo if textposition is none
archmoj Apr 30, 2019
86c0c09
pass opts to bar cross trace calc
archmoj Apr 30, 2019
bdbbeb1
remove one more unused node3 link
archmoj Apr 30, 2019
6ac1dc5
add jasmine tests of waterfall textinfo coerce
archmoj Apr 30, 2019
cad2728
need extra precision in textinfo values of funnel and waterfall
archmoj Apr 30, 2019
92b9471
dont coerce funnel textinfo if textposition is none - also add jasmin…
archmoj Apr 30, 2019
34e0a4b
add noCI tag for one sankey test which started to fail after adding f…
archmoj Apr 30, 2019
7e52977
fixup waterfall jasmine test for textinfo - note value was not a vali…
archmoj Apr 30, 2019
ba1b6c0
refactor bar waterfall and funnle plot - rm prefix - pass opts
archmoj May 1, 2019
04049f2
revisit bar-like hideOutsideRangePoints
archmoj May 1, 2019
6c8a661
default fillcolor to marker.color
archmoj May 1, 2019
2a3c354
drop funnelnorm
archmoj May 1, 2019
1c82f91
waterfall hover bug fix
archmoj May 1, 2019
6a3a13c
add jasmine test to lock waterfall hover on different types of measur…
archmoj May 1, 2019
35dfe36
coerce tick label defaults even if axis is not visible i.e. required …
archmoj May 1, 2019
c63caf9
refactor layout defaults before addressing nXn loop issue
archmoj May 2, 2019
f249c61
drop arrayOk support of bar width and offset of funnels - improve fil…
archmoj May 2, 2019
d6f023a
revise draw order for funnel connector regions and lines
archmoj May 2, 2019
0c169b5
improve image test to contain one overlay example
archmoj May 2, 2019
c29b58d
revisit textinfo and width defaults - fix and improve tests
archmoj May 3, 2019
e968da6
split handleTickLabelDefaults and split the process into two passes t…
archmoj May 2, 2019
380db2e
implement textangle for bars funnels and waterfalls - add tests
archmoj May 3, 2019
61b6068
fix alignmentgroup attributes of funnel and waterfall
archmoj May 4, 2019
0236783
refactor bar inside text if statement
archmoj May 6, 2019
4d403fd
revert cartesian layout_default file
archmoj May 6, 2019
a650170
minimal change to add logic to hide funnels
archmoj May 6, 2019
a744689
drop texangle and position defaults from funnel mocks
archmoj May 6, 2019
30b172a
fixup textangle algo - added test for outside text
archmoj May 6, 2019
446bacc
fix outside long text position with textangle - add test
archmoj May 6, 2019
b93e3a5
default funnels to horizontal
archmoj May 6, 2019
02a176a
handle multicategory labels in funnel and waterfall textinfo
archmoj May 7, 2019
d0e8fe5
add logic to reverse y axis by default if only funnels
archmoj May 7, 2019
0eb3917
remove yaxis autorange reversed from funnel mocks
archmoj May 7, 2019
fd1f6ca
improve funnel orientation description and do base waterfall and funn…
archmoj May 7, 2019
6d50386
revisit transform inside bar to reduce diff after textangle - revert …
archmoj May 7, 2019
79d6ef1
Merge pull request #3817 from plotly/funnel-traces
archmoj May 7, 2019
154e81e
fixup after merge of funnel
archmoj May 7, 2019
a598343
textinfo do not leave a blank line when text is empty but print zero
archmoj May 8, 2019
d69f8a4
improve jasmine tests for textinfo
archmoj May 8, 2019
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
54 changes: 50 additions & 4 deletions src/traces/bar/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if(hasFlag('delta')) text.push(pieHelpers.formatPieValue(delta, separators));
if(hasFlag('final')) text.push(pieHelpers.formatPieValue(final, separators));
}

return text.join('<br>');
}
9 changes: 9 additions & 0 deletions src/traces/waterfall/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

'use strict';

var pieAtts = require('../pie/attributes');
var barAttrs = require('../bar/attributes');
var lineAttrs = require('../scatter/attributes').line;
var extendFlat = require('../../lib/extend').extendFlat;
Expand Down Expand Up @@ -76,6 +77,14 @@ module.exports = {
hovertext: barAttrs.hovertext,
hovertemplate: barAttrs.hovertemplate,

textinfo: extendFlat({}, pieAtts.textinfo, {
editType: 'plot',
flags: ['label', 'text', 'initial', 'delta', 'final'],
description: [
'Determines which trace information appear on the graph.'
].join(' ')
}),

text: barAttrs.text,
textposition: barAttrs.textposition,
textfont: barAttrs.textfont,
Expand Down
2 changes: 2 additions & 0 deletions src/traces/waterfall/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ module.exports = function calc(gd, trace) {
if(trace.ids) {
cdi.id = String(trace.ids[i]);
}

cdi.v = trace.base + previousSum;
}

if(cd.length) cd[0].hasTotals = hasTotals;
Expand Down
2 changes: 2 additions & 0 deletions src/traces/waterfall/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
coerce('width');

coerce('text');
coerce('textinfo');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't coerce textinfo when textposition: 'none'.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in bed6842.


coerce('hovertext');
coerce('hovertemplate');

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
157 changes: 157 additions & 0 deletions test/image/mocks/waterfall_profit-loss_2018vs2019_textinfo_base.json
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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you try adding ticksuffix and tickprefix to these axes to see if things work as planned?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call.
Done in the funnel PR 6a3a13c.

},
"margin": { "l": 150, "r": 50 },
"height": 1200,
"width": 900,
"hovermode": "closest",
"showlegend": true
}
}