From 8b92ca7ff87776720db0d1dddf45709491e78a0f Mon Sep 17 00:00:00 2001 From: Andrew Watkins Date: Mon, 26 Jun 2017 14:40:40 -0700 Subject: [PATCH] Persist legend in when hovered over --- ui/src/shared/components/Dygraph.js | 37 +++++++++++++++++++-------- ui/src/style/components/dygraphs.scss | 1 - 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/ui/src/shared/components/Dygraph.js b/ui/src/shared/components/Dygraph.js index 1aec6434bc..46528d369a 100644 --- a/ui/src/shared/components/Dygraph.js +++ b/ui/src/shared/components/Dygraph.js @@ -158,6 +158,7 @@ export default class Dygraph extends Component { gridLineWidth: 1, highlightCircleSize: 3, animatedZooms: true, + hideOverlayOnMouseOut: false, colors: finalLineColors, series: dygraphSeries, axes: { @@ -172,16 +173,31 @@ export default class Dygraph extends Component { strokeWidth: 2, highlightCircleSize: 5, }, - unhighlightCallback: () => { - legendContainerNode.className = 'container--dygraph-legend hidden' // hide + unhighlightCallback: e => { + const { + top, + bottom, + left, + right, + } = legendContainerNode.getBoundingClientRect() - // part of optional workaround for preventing updateOptions from breaking legend - // this.isMouseOverGraph = false + const mouseY = e.clientY + const mouseX = e.clientX + + const mouseInLegendY = mouseY <= bottom && mouseY >= top + const mouseInLegendX = mouseX <= right && mouseX >= left + const isMouseHoveringLegend = mouseInLegendY && mouseInLegendX + + if (!isMouseHoveringLegend) { + legendContainerNode.className = 'container--dygraph-legend hidden' // hide + } }, highlightCallback: e => { // don't make visible yet, but render on DOM to capture position for calcs legendContainerNode.style.visibility = 'hidden' legendContainerNode.className = 'container--dygraph-legend' + legendContainerNode.onmouseleave = () => + legendContainerNode.className = 'container--dygraph-legend hidden' // Move the Legend on hover const graphRect = graphContainerNode.getBoundingClientRect() @@ -322,6 +338,13 @@ export default class Dygraph extends Component { render() { return (
+
{ + this.legendContainer = r + }} + className={'container--dygraph-legend hidden'} + />
{ this.graphContainer = r @@ -329,12 +352,6 @@ export default class Dygraph extends Component { style={this.props.containerStyle} className="dygraph-child-container" /> -
{ - this.legendContainer = r - }} - className={'container--dygraph-legend hidden'} - />
) } diff --git a/ui/src/style/components/dygraphs.scss b/ui/src/style/components/dygraphs.scss index f0a07d37cb..bf3560da1e 100644 --- a/ui/src/style/components/dygraphs.scss +++ b/ui/src/style/components/dygraphs.scss @@ -33,7 +33,6 @@ border-radius: 3px; font-weight: 600; line-height: 13px; - pointer-events: none; &.hidden { display: none !important;