Skip to content

Vertical line following mouse cursor #54

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

Closed
prog8 opened this issue Dec 1, 2015 · 9 comments
Closed

Vertical line following mouse cursor #54

prog8 opened this issue Dec 1, 2015 · 9 comments

Comments

@prog8
Copy link

prog8 commented Dec 1, 2015

Is it possible to draw vertical line on charts which follows the mouse or which can be controlled by method calls? The motivation is that if you have multiple time series charts you may want to show the vertical line on all of charts when you move mouse within one any of them.

@etpinard
Copy link
Contributor

etpinard commented Dec 1, 2015

Should be doable with plotly_hover event handler and an appropriate shape. Here's an example with a click event handler: http://chriddyp.github.io/interactive-heatmaps/ .

In the future, implementation questions should be asked on Stack Overflow (tagged plotly) or community.plot.ly (tagged plotly-js). GitHub issues are reserved for bugs reports and feature requests.

@prog8
Copy link
Author

prog8 commented Dec 1, 2015

Thanks for your response. I'll keep in mind that I should write on Stack Overflow or community.plot.ly. From one side I wrote a question but from the other side it is feature request since Plotly doesn't support this out of the box.

@etpinard
Copy link
Contributor

etpinard commented Dec 1, 2015

Correct.

#53 is a feature request, which is totally fine in this repo. 🍻

@etpinard etpinard closed this as completed Dec 1, 2015
@fhurta
Copy link
Contributor

fhurta commented Jul 14, 2016

Was any feature request created out of this? I would need this feature too

@leifdejong
Copy link

Hi! Hope you guys are well and not too overworked. I wanted to follow up to this question and see if you guys had an example for how this would work or a codepen or feature that I missed while digging through the documentation... Please let us know if you have any direction as this seems to be a common struggle. Thank a lot!

@fhurta
Copy link
Contributor

fhurta commented Aug 22, 2016

I put together some working example using shape, check this out

@leifdejong
Copy link

leifdejong commented Aug 22, 2016

@fhurta you're the man! Thanks

@jayfresh
Copy link

jayfresh commented Dec 2, 2016

@fhurta 👍

@backgroundColor
Copy link

backgroundColor commented Feb 14, 2017

const gd = this.refs.headerLine
const d3 = Plotly.d3
gd.on('plotly_hover', (data) => {
      const originTooltip = document.querySelector('.hovertext')
      const rectH = d3.select(gd).select('.xy').select('rect').attr('height')
      const transformAttr = originTooltip.getAttribute('transform')
      const translate = /translate\(\s*([^\s,)]+)[ ,]([^\s,)]+)/.exec(transformAttr)
      const translateX = parseInt(translate[1])
      const translateY = parseInt(translate[2])
      const xAxisH = d3.select(gd).select('.xaxislayer')[0][0]
      const xAxisTranslateY = /translate\(\s*([^\s,)]+)[ ,]([^\s,)]+)/.exec(xAxisH.getAttribute('transform'))[2]
      let toolMarker, sheet
      const stylesheets = document.styleSheets
      if (document.querySelector('.toolMarker')) {
        toolMarker = document.querySelector('.toolMarker')
      } else {
        toolMarker = document.createElement('div')
        document.createElement('div')
        toolMarker.style.position = 'absolute'
        toolMarker.style.zIndex = '10000'
        toolMarker.setAttribute('class', 'toolMarker')
        this.refs.headerLine.appendChild(toolMarker)
      }
      toolMarker.style.left = `${translateX - 3}px`
      toolMarker.style.top = `${translateY - 3}px`

      if (stylesheets) {
        sheet = stylesheets[stylesheets.length - 1]
      } else {
        const style = document.createElement('style')
        document.head.appendChild(style)
      }
      const cssRulesLength = sheet.cssRules.length
      sheet.insertRule(`.toolMarker::after{height:${rectH}px; top:${xAxisTranslateY - translateY}px}`, cssRulesLength)
    }).on('plotly_unhover', (data) => {
      const sheet = document.styleSheets[document.styleSheets.length - 1]
      sheet.deleteRule(sheet.cssRules.length - 1)
      document.querySelector('.toolMarker').remove()
    })

I passsed this method to achieve

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants