-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Cartesian dropline support
#1461
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 1 commit
d9fab15
5d39b53
be47533
17d815c
162068e
762b54a
d680bd4
2433d4c
75da2fe
7953488
55b17b2
b9f6ab1
7fe4363
34a1562
8c7ac76
6e243de
c036bf7
08371c2
69dc781
37b77fe
710d2d6
e509fa7
75121d2
bd11567
3a9aa58
052417b
a3a0a4f
f7b467e
7aa4359
5925049
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Move 'dash' function to lib for re-use Use dynamic contrast color based on same logic as hovertext contrast text
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -857,73 +857,95 @@ function createDroplines(hoverData, opts) { | |
yAnchoredBase = yEdge - outerBBox.top, | ||
xBase = c0.ya.anchor === 'free' ? xFreeBase : xAnchoredBase, | ||
yBase = c0.xa.anchor === 'free' ? yFreeBase : yAnchoredBase, | ||
color = c0.color; | ||
xColor = c0.xa.spikecolor ? c0.xa.spikecolor : c0.color, | ||
yColor = c0.ya.spikecolor ? c0.ya.spikecolor : c0.color, | ||
xContrastColor = tinycolor(xColor).getBrightness() > 128 ? | ||
'#000' : Color.background, | ||
yContrastColor = tinycolor(yColor).getBrightness() > 128 ? | ||
'#000' : Color.background, | ||
xThickness = c0.xa.spikethickness, | ||
yThickness = c0.ya.spikethickness, | ||
xDash = Lib.dash(c0.xa.spikedash, xThickness), | ||
yDash = Lib.dash(c0.xa.spikedash, yThickness), | ||
xMarker = c0.xa.spikemode.indexOf('marker') !== -1, | ||
yMarker = c0.ya.spikemode.indexOf('marker') !== -1, | ||
xSpikeLine = c0.xa.spikemode.indexOf('toaxis') !== -1 || c0.xa.spikemode.indexOf('across') !== -1, | ||
ySpikeLine = c0.ya.spikemode.indexOf('toaxis') !== -1 || c0.ya.spikemode.indexOf('across') !== -1, | ||
xEndSpike = c0.xa.spikemode.indexOf('across') !== -1 ? xBase + xLength : xPoint, | ||
yEndSpike = c0.ya.spikemode.indexOf('across') !== -1 ? yBase - yLength : yPoint; | ||
|
||
// Remove old dropline items | ||
container.selectAll('line.dropline').remove(); | ||
container.selectAll('circle.dropline').remove(); | ||
|
||
|
||
if(c0.ya.showspikes) { | ||
// Background horizontal Line (to y-axis) | ||
container.append('line') | ||
.attr('x1', xBase) | ||
.attr('x2', xPoint) | ||
.attr('y1', yPoint) | ||
.attr('y2', yPoint) | ||
.attr('stroke-width', 5) | ||
.attr('stroke', '#fff') | ||
.attr('class', 'dropline'); | ||
|
||
// Foreground horizontal line (to y-axis) | ||
container.append('line') | ||
.attr('x1', xBase) | ||
.attr('x2', xPoint) | ||
.attr('y1', yPoint) | ||
.attr('y2', yPoint) | ||
.attr('stroke-width', 3) | ||
.attr('stroke', color) | ||
.attr('stroke-dasharray', '5,5') | ||
.attr('class', 'dropline'); | ||
|
||
if(ySpikeLine) { | ||
// Background horizontal Line (to y-axis) | ||
container.append('line') | ||
.attr('x1', xBase) | ||
.attr('x2', xEndSpike) | ||
.attr('y1', yPoint) | ||
.attr('y2', yPoint) | ||
.attr('stroke-width', yThickness + 2) | ||
.attr('stroke', yContrastColor) | ||
.attr('class', 'dropline'); | ||
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.
also it's a bit nicer to use 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. Both coming in next commit. |
||
|
||
// Foreground horizontal line (to y-axis) | ||
container.append('line') | ||
.attr('x1', xBase) | ||
.attr('x2', xEndSpike) | ||
.attr('y1', yPoint) | ||
.attr('y2', yPoint) | ||
.attr('stroke-width', yThickness) | ||
.attr('stroke', yColor) | ||
.attr('stroke-dasharray', yDash) | ||
.attr('class', 'dropline'); | ||
} | ||
// Y axis marker | ||
container.append('circle') | ||
.attr('cx', xBase) | ||
.attr('cy', yPoint) | ||
.attr('r', 3) | ||
.attr('fill', color) | ||
.attr('class', 'dropline'); | ||
if(yMarker) { | ||
container.append('circle') | ||
.attr('cx', xAnchoredBase) | ||
.attr('cy', yPoint) | ||
.attr('r', yThickness) | ||
.attr('fill', yColor) | ||
.attr('class', 'dropline'); | ||
} | ||
} | ||
|
||
if(c0.xa.showspikes) { | ||
if(xSpikeLine) { | ||
// Background vertical line (to x-axis) | ||
container.append('line') | ||
.attr('x1', xPoint) | ||
.attr('x2', xPoint) | ||
.attr('y1', yPoint) | ||
.attr('y2', yBase) | ||
.attr('stroke-width', 5) | ||
.attr('stroke', '#fff') | ||
.attr('class', 'dropline'); | ||
|
||
// Foreground vertical line (to x-axis) | ||
container.append('line') | ||
.attr('x1', xPoint) | ||
.attr('x2', xPoint) | ||
.attr('y1', yPoint) | ||
.attr('y2', yBase) | ||
.attr('stroke-width', 3) | ||
.attr('stroke', color) | ||
.attr('stroke-dasharray', '5,5') | ||
.attr('class', 'dropline'); | ||
container.append('line') | ||
.attr('x1', xPoint) | ||
.attr('x2', xPoint) | ||
.attr('y1', yEndSpike) | ||
.attr('y2', yBase) | ||
.attr('stroke-width', xThickness + 2) | ||
.attr('stroke', xContrastColor) | ||
.attr('class', 'dropline'); | ||
|
||
// Foreground vertical line (to x-axis) | ||
container.append('line') | ||
.attr('x1', xPoint) | ||
.attr('x2', xPoint) | ||
.attr('y1', yEndSpike) | ||
.attr('y2', yBase) | ||
.attr('stroke-width', xThickness) | ||
.attr('stroke', xColor) | ||
.attr('stroke-dasharray', xDash) | ||
.attr('class', 'dropline'); | ||
} | ||
|
||
// X axis marker | ||
container.append('circle') | ||
.attr('cx', xPoint) | ||
.attr('cy', yBase) | ||
.attr('r', 3) | ||
.attr('fill', color) | ||
.attr('class', 'dropline'); | ||
if(xMarker) { | ||
container.append('circle') | ||
.attr('cx', xPoint) | ||
.attr('cy', yAnchoredBase) | ||
.attr('r', xThickness) | ||
.attr('fill', xColor) | ||
.attr('class', 'dropline'); | ||
} | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -246,13 +246,57 @@ module.exports = { | |
}, | ||
showspikes: { | ||
valType: 'boolean', | ||
dflt: false, | ||
dflt: true, | ||
role: 'style', | ||
description: [ | ||
'Determines whether or not spikes (aka droplines) are drawn for this axis.', | ||
'Note: This only takes affect when hovermode = closest' | ||
].join(' ') | ||
}, | ||
spikecolor: { | ||
valType: 'color', | ||
dflt: null, | ||
role: 'style', | ||
description: 'Sets the spike color. If undefined, will use the series color' | ||
}, | ||
spikethickness: { | ||
valType: 'number', | ||
dflt: 3, | ||
role: 'style', | ||
description: 'Sets the width (in px) of the zero line.' | ||
}, | ||
spikedash: { | ||
valType: 'string', | ||
// string type usually doesn't take values... this one should really be | ||
// a special type or at least a special coercion function, from the GUI | ||
// you only get these values but elsewhere the user can supply a list of | ||
// dash lengths in px, and it will be honored | ||
values: ['solid', 'dot', 'dash', 'longdash', 'dashdot', 'longdashdot'], | ||
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. Non- ⛔ , but It would be nice to reuse the list in 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. I cleaned up a bunch of things in bd11567 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Lear C281 n more. Looking good 👍 |
||
dflt: 'dash', | ||
role: 'style', | ||
description: [ | ||
'Sets the style of the lines. Set to a dash string type', | ||
'or a dash length in px.' | ||
].join(' ') | ||
}, | ||
spikemode: { | ||
valType: 'flaglist', | ||
flags: ['toaxis', 'across', 'marker'], | ||
extras: ['none'], | ||
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. Isn't |
||
role: 'style', | ||
dflt: 'toaxis', | ||
description: [ | ||
'Determines the drawing mode for the spike line', | ||
'If *toaxis*, the line is drawn from the data point to the axis the ', | ||
'series is plotted on.', | ||
|
||
'If *across*, the line is drawn across the entire plot area, and', | ||
'supercedes *toaxis*.', | ||
|
||
'If *marker*, then a marker dot is drawn on the axis the series is', | ||
'plotted on' | ||
].join(' ') | ||
}, | ||
tickfont: extendFlat({}, fontAttrs, { | ||
description: 'Sets the tick font.' | ||
}), | ||
|
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 like the idea of breaking this out - but lets keep it in
drawing
, it fits there thematically andlib
is a bit overloaded.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.
Coming in next commit.