Bug fix and additions for obj.getShape(event) in the Line chart API documentation

Share RGraph:  

« Back to message list

Enter your email address to get email updates on this topic. You can stop receiving updates by clicking the link in the update email messages.

Posted by Zsolt on 27th July 2017
Hi Richard,

There was a bug what I fixed, and I added some small additions, see my comments.
The important part is the fix of calling of the tooltip function.
Use it if you want to.

Best regards,
Zsolt

The function:
     line.canvas.onmousemove = function (e)
     {
         RGraph.fixEventObject(e);

         var ca = e.target;
         var co = ca.getContext('2d');
         var obj = e.target.__object__;
      
         // This is the method which simplifies getting coordinates
         var point = obj.getShape(e);
      
      
         if (point) {
//My code -- if the line is hidden don't show the tooltip
             if (line.hidden(point.dataset))
             {
                 return;
             }
//My code -- if the line is hidden don't show the tooltip
            
             ca.style.cursor = 'pointer';
            
             // Is this the same tooltip as the one (if any) that's already being shown
             if (RGraph.Registry.get('chart.tooltip') && RGraph.Registry.get('chart.tooltip').__index__ == point[3]) {
                 return;
             }

             // Start afresh
             RGraph.redraw();

             // Show the tooltip
//My code -- check the value is exists, if you use dynamic data (not hard coded)
             if (obj.get('labels')[point[3]] !== undefined && obj.get('labels')[point[3]] !== null)
             {
//My code -- check the value is exists, if you use dynamic data (not hard coded)


//My code -- fix the call, as You can see the first argument is the obj not the ca, and I added a new arg at the end: 'e', and I also added a toString() for safety
                 RGraph.tooltip(obj, obj.get('labels')[point[3]].toString(), e.pageX, e.pageY, point[3], e);
//old code: RGraph.tooltip(ca, obj.get('labels')[point[3]], e.pageX, e.pageY, point[3]);

                 // Highlight the point
                 co.strokeStyle = 'gray';
                 co.fillStyle = 'white';
                 co.beginPath();
                 co.moveTo(point[1], point[2]);
                 co.arc(point[1], point[2], 2, 0, 6.26, 0);
                 co.stroke();
                 co.fill();
             }
            
             return;
         }
        
         ca.style.cursor = 'default';
     }
Posted by Richard on 27th July 2017
Hi there,

The API documentation page? That's just an example function that illustrates how you can use the .getShape() function. I don't think it's used by anything.

I'll have a look to see what I can use in it though from your code.

Thanks.


Richard
Posted by Richard on 27th July 2017
Hi there,

OK I've updated the page with your code and when 4.63 is released you'll be able to see it here:

www.rgraph.net/canvas/docs/line.html#getshape

Thanks.



Richard
Posted by Zsolt on 28th July 2017
Hi,

I know, it's not a demo example, but sometimes if You looking for a solution, it's just hard to find in the demo charts.
Too many of them - the search function was very useful, I think lot of people don't know the google site search.

Anyway, thanks for your answer and your superb library.

Regards,
Zsolt
 

Add a reply




« Back to message list