Ravindu89 Posted March 6, 2018 Share Posted March 6, 2018 Is there a way to bind mouse action on PIXI.Graphics line?. I have used below codes to bind action on the line. But the action is bound on all chart area I think, hitArea is not correctly set. this.strategyGraphic.interactive = true; this.strategyGraphic.hitArea = this.strategyGraphic.getBounds(); this.strategyGraphic.click = function (data) { alert('hit rect'); } Would like to hear any advice on the subject. Thanks in advance! Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted March 6, 2018 Share Posted March 6, 2018 Its not possible to bind an action to a line. There were countless issues about it and people used workarounds. Please use "search" function of this subforum, or in https://github.com/pixijs/pixi.js/issues Quote Link to comment Share on other sites More sharing options...
PsichiX Posted March 6, 2018 Share Posted March 6, 2018 hi! tell me, what end goal exactly you want to achieve, then i'll give you a solution. Quote Link to comment Share on other sites More sharing options...
Ravindu89 Posted March 6, 2018 Author Share Posted March 6, 2018 Thank you all for quick replies. Hi PsichiX, I have to achieve two goals, When clicking on a particular line, Double left click - open property window of that line (Need to pass some unique id with that action to identify that line) Single Right click - remove the added line (Need to pass some unique id with that action to identify that line) When hovering on a particular line, Value tooltip should be popped up. Examples how the chart looks on in that above status are shown in below. Quote Link to comment Share on other sites More sharing options...
PsichiX Posted March 6, 2018 Share Posted March 6, 2018 ok, so the working solution (actually only reasonable solution) will be: add listeners on lines parent, then on events for each line convert mouse coords into line local space, then based on x pos sample line data (not visuals, just source data that describe line y) and if distance between mouse y pos to sampled line y is less than some treshold, fire desired action. Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted March 6, 2018 Share Posted March 6, 2018 Alternative: for each line create a Polygon, for every point there has to be two points (x,y-10) and (x,y+10) - that way you'll get some space above and below the line. Use that polygon as hitArea. Quote Link to comment Share on other sites More sharing options...
botmaster Posted March 6, 2018 Share Posted March 6, 2018 best way to do tooltips: Make a tooltip manager plugged to the mouse move/position (bunch of ways to do it) then objects that should get tooltips need to implement an Itooltip protocol/interface with at minimum 2 methods: hasTooltip, getTooltip. The manager works that way: is there a IToolTip under the mouse? yes > is object.hasTooltip() true? yes > display tooltip using object.getTooltip(). Very simple, very efficient. Quote Link to comment Share on other sites More sharing options...
Ravindu89 Posted March 15, 2018 Author Share Posted March 15, 2018 Thank you all for this lot of advice. I have used Ivan posted method and but still down part of the line chart is sensitive to mouse action. Attached figures are shown my implementation. (I have colored hit area polygon' outline to easy read) Hit Area polygon point array I need only outlined polygon area is sensitive to mouse action. Please support me. Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted March 15, 2018 Share Posted March 15, 2018 That's it, you have polygon, you have to use it as hitArea: "graphics.hitArea = polygon" Quote Link to comment Share on other sites More sharing options...
Ravindu89 Posted March 15, 2018 Author Share Posted March 15, 2018 yes as you mentioned the previous post I have set this polygon as line graphics object hit area. But the bottom area of chart (outside of polygon area) is also listening to action. Quote Link to comment Share on other sites More sharing options...
botmaster Posted March 15, 2018 Share Posted March 15, 2018 Make it listen to a separate listener then. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.