-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
trace type indicator
#3978
trace type indicator
#3978
Conversation
number: { | ||
valueformat: { | ||
valType: 'string', | ||
dflt: '.3s', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be nice to be consistent with other *format
attributes in use currently e.g. tickformat
for axis where the dflt
is left blank and we let Axes.tickText
handle things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a strong opinion for this one but having a fixed number of digits with SI suffixes as a default does make sense if we want the number to always fit within the angular gauge regardless of how big or small the value is 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for this one but having a fixed number of digits with SI suffixes as a default does make sense if we want the number to always fit within the angular gauge regardless of how big or small the value is
Good point here. I don't have a strong opinion either.
'Sets the position of delta with respect to the number.' | ||
].join(' ') | ||
}, | ||
relative: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to document something me and @antoinerg discussed in-person last week.
One potential addition to indicator
would be to add a way to show both "absolute" and "relative" delta widgets on the trace same indicator
trace.
One way to achieve this would be to add 'delta2'
flag in mode and have something like:
{
mode: 'number+delta+delta2'
delta: {},
delta2: {relative: true}
}
OR, replace delta
with deltarel
and deltaabs
{
mode: 'number+deltarel+deltaabs'
deltarel: {},
deltaabs: {}
}
making this relative
attribute obsolete.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's definitely a possibility!
I think I prefer having delta2
as it would imply it is to be displayed to the right of delta
. If we have deltarel
and deltaabs
, we'd have to add an attribute to set their position relative to one another. Basically, we'd be trading attribute relative
for relativeposition
...
}, | ||
align: { | ||
valType: 'enumerated', | ||
values: ['left', 'center', 'right'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think title.align
corresponds to what most users will find useful for indicator
traces, but note that align
somewhat conflicts with textposition
in pie traces
plotly.js/src/traces/pie/attributes.js
Lines 208 to 222 in 795220f
position: { | |
valType: 'enumerated', | |
values: [ | |
'top left', 'top center', 'top right', | |
'middle center', | |
'bottom left', 'bottom center', 'bottom right' | |
], | |
role: 'info', | |
editType: 'plot', | |
description: [ | |
'Specifies the location of the `title`.', | |
'Note that the title\'s position used to be set', | |
'by the now deprecated `titleposition` attribute.' | |
].join(' ') | |
}, |
and the (x|y)ref
/ (x|y)anchor
attributes for layout.title
:
plotly.js/src/plots/layout_attributes.js
Lines 51 to 130 in 795220f
xref: { | |
valType: 'enumerated', | |
dflt: 'container', | |
values: ['container', 'paper'], | |
role: 'info', | |
editType: 'layoutstyle', | |
description: [ | |
'Sets the container `x` refers to.', | |
'*container* spans the entire `width` of the plot.', | |
'*paper* refers to the width of the plotting area only.' | |
].join(' ') | |
}, | |
yref: { | |
valType: 'enumerated', | |
dflt: 'container', | |
values: ['container', 'paper'], | |
role: 'info', | |
editType: 'layoutstyle', | |
description: [ | |
'Sets the container `y` refers to.', | |
'*container* spans the entire `height` of the plot.', | |
'*paper* refers to the height of the plotting area only.' | |
].join(' ') | |
}, | |
x: { | |
valType: 'number', | |
min: 0, | |
max: 1, | |
dflt: 0.5, | |
role: 'style', | |
editType: 'layoutstyle', | |
description: [ | |
'Sets the x position with respect to `xref` in normalized', | |
'coordinates from *0* (left) to *1* (right).' | |
].join(' ') | |
}, | |
y: { | |
valType: 'number', | |
min: 0, | |
max: 1, | |
dflt: 'auto', | |
role: 'style', | |
editType: 'layoutstyle', | |
description: [ | |
'Sets the y position with respect to `yref` in normalized', | |
'coordinates from *0* (bottom) to *1* (top).', | |
'*auto* places the baseline of the title onto the', | |
'vertical center of the top margin.' | |
].join(' ') | |
}, | |
xanchor: { | |
valType: 'enumerated', | |
dflt: 'auto', | |
values: ['auto', 'left', 'center', 'right'], | |
role: 'info', | |
editType: 'layoutstyle', | |
description: [ | |
'Sets the title\'s horizontal alignment with respect to its x position.', | |
'*left* means that the title starts at x,', | |
'*right* means that the title ends at x', | |
'and *center* means that the title\'s center is at x.', | |
'*auto* divides `xref` by three and calculates the `xanchor`', | |
'value automatically based on the value of `x`.' | |
].join(' ') | |
}, | |
yanchor: { | |
valType: 'enumerated', | |
dflt: 'auto', | |
values: ['auto', 'top', 'middle', 'bottom'], | |
role: 'info', | |
editType: 'layoutstyle', | |
description: [ | |
'Sets the title\'s vertical alignment with respect to its y position.', | |
'*top* means that the title\'s cap line is at y,', | |
'*bottom* means that the title\'s baseline is at y', | |
'and *middle* means that the title\'s midline is at y.', | |
'*auto* divides `yref` by three and calculates the `yanchor`', | |
'value automatically based on the value of `y`.' | |
].join(' ') | |
}, |
and there's side
in colorbars:
plotly.js/src/plots/layout_attributes.js
Lines 51 to 130 in 795220f
xref: { | |
valType: 'enumerated', | |
dflt: 'container', | |
values: ['container', 'paper'], | |
role: 'info', | |
editType: 'layoutstyle', | |
description: [ | |
'Sets the container `x` refers to.', | |
'*container* spans the entire `width` of the plot.', | |
'*paper* refers to the width of the plotting area only.' | |
].join(' ') | |
}, | |
yref: { | |
valType: 'enumerated', | |
dflt: 'container', | |
values: ['container', 'paper'], | |
role: 'info', | |
editType: 'layoutstyle', | |
description: [ | |
'Sets the container `y` refers to.', | |
'*container* spans the entire `height` of the plot.', | |
'*paper* refers to the height of the plotting area only.' | |
].join(' ') | |
}, | |
x: { | |
valType: 'number', | |
min: 0, | |
max: 1, | |
dflt: 0.5, | |
role: 'style', | |
editType: 'layoutstyle', | |
description: [ | |
'Sets the x position with respect to `xref` in normalized', | |
'coordinates from *0* (left) to *1* (right).' | |
].join(' ') | |
}, | |
y: { | |
valType: 'number', | |
min: 0, | |
max: 1, | |
dflt: 'auto', | |
role: 'style', | |
editType: 'layoutstyle', | |
description: [ | |
'Sets the y position with respect to `yref` in normalized', | |
'coordinates from *0* (bottom) to *1* (top).', | |
'*auto* places the baseline of the title onto the', | |
'vertical center of the top margin.' | |
].join(' ') | |
}, | |
xanchor: { | |
valType: 'enumerated', | |
dflt: 'auto', | |
values: ['auto', 'left', 'center', 'right'], | |
role: 'info', | |
editType: 'layoutstyle', | |
description: [ | |
'Sets the title\'s horizontal alignment with respect to its x position.', | |
'*left* means that the title starts at x,', | |
'*right* means that the title ends at x', | |
'and *center* means that the title\'s center is at x.', | |
'*auto* divides `xref` by three and calculates the `xanchor`', | |
'value automatically based on the value of `x`.' | |
].join(' ') | |
}, | |
yanchor: { | |
valType: 'enumerated', | |
dflt: 'auto', | |
values: ['auto', 'top', 'middle', 'bottom'], | |
role: 'info', | |
editType: 'layoutstyle', | |
description: [ | |
'Sets the title\'s vertical alignment with respect to its y position.', | |
'*top* means that the title\'s cap line is at y,', | |
'*bottom* means that the title\'s baseline is at y', | |
'and *middle* means that the title\'s midline is at y.', | |
'*auto* divides `yref` by three and calculates the `yanchor`', | |
'value automatically based on the value of `y`.' | |
].join(' ') | |
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm willing to either rename the attribute to position
as in pie
or change the API altogether.
FYI, the (title|number).align
attributes were added at the last minute in order to mimic DDK's "data cards" in which the text is left-aligned and position to the left of the domain.
coerceGauge('shape'); | ||
var isBullet = traceOut._isBullet = traceOut.gauge.shape === 'bullet'; | ||
if(!isBullet) { | ||
coerce('title.align', 'center'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't the current behaviour for bullets have essentially title.align: 'right'
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't the current behaviour for bullets have essentially
title.align: 'right'
?
They do yes. However, it cannot be changed. That's why I thought it shouldn't be coerced. Should I coerce it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could it support align: 'center'
and align: 'left'
eventually (i.e. not in this PR)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could it support
align: 'center'
andalign: 'left'
eventually (i.e. not in this PR)?
My thought was that because the title is outside the domain in bullet
, the notion of alignment is not well-defined: it's unclear how much whitespace we have on the left (ie. maybe there's another plot there).
Awesome work @antoinerg ! I'm a big fan of your Your baselines looks great and they appear to 🔒 down a lot of the behaviour. Maybe you could add one more baseline to lock down |
... oh and @antoinerg maybe you could share a codepen example of |
Oh right. Good eye! We should be using |
Here's the requested Codepen: https://codepen.io/antoinerg/full/dBZdpY |
moduleType: 'trace', | ||
name: 'indicator', | ||
basePlotModule: require('./base_plot'), | ||
categories: ['svg', 'noOpacity', 'noHover'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be useful to if this trace had an adjustable opacity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mojtaba "Mr. Opacity" Samimi
All right. Time to merge this thing! https://codepen.io/antoinerg/full/dBZdpY is one of the coolest plotly.js codepen in recent memory 🥇 Not bad for @antoinerg 's first 💃 💃 💃 @antoinerg feel free to open a new issue about the array-container / |
This PR introduces a new trace type
indicator
and closes #3659Codepen to animate mocks: https://codepen.io/antoinerg/full/dBZdpY (using bundle built off 1a991d5)
gauge.axis.visible
)