The Line chart getShape function update in the new version

Share RGraph:   Share or Like RGraph on Facebook!

« 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 21st September 2017
Hi Richard,

Thanks for your hard work, and the new version. You updated the line getShape with a hidden checking.
Just one notice, if you use return null instead of continue as I have suggested, the tooltip won't showed for the visible line if there is a point overlap with a hidden line.

Best regards,
Zsolt
Posted by Richard on 21st September 2017
Hi there,

It already returns null. Here's the top bit of the function from version 4.63:



/**
* The getPoint() method - used to get the point the mouse is currently over, if any
*
* @param object e The event object
* @param object OPTIONAL You can pass in the bar object instead of the
* function getting it from the canvas
*/
this.getShape =
this.getPoint = function (e)
{
     var obj = this,
         RG = RGraph,
         ca = canvas = e.target,
         co = context = this.context,
         prop = this.properties;

     var mouseXY = RG.getMouseXY(e),
         mouseX = mouseXY[0],
         mouseY = mouseXY[1];
    
     // This facilitates you being able to pass in the bar object as a parameter instead of
     // the function getting it from the object
     if (arguments[1]) {
         obj = arguments[1];
     }

     for (var i=0; i<obj.coords.length; ++i) {
    
         var x = obj.coords[i][0];
         var y = obj.coords[i][1];

         // Do this if the hotspot is triggered by the X coord AND the Y coord
         if ( mouseX <= (x + prop['chart.tooltips.hotspot.size'])
             && mouseX >= (x - prop['chart.tooltips.hotspot.size'])
             && mouseY <= (y + prop['chart.tooltips.hotspot.size'])
             && mouseY >= (y - prop['chart.tooltips.hotspot.size'])
            ) {

                 if (RG.parseTooltipText) {
                     var tooltip = RG.parseTooltipText(prop['chart.tooltips'], i);
                 }

                 // Work out the dataset
                 var dataset = 0,
                     idx = i;

                 while ((idx + 1) > this.data[dataset].length) {
                     idx -= this.data[dataset].length;
                     dataset++;
                 }

                 // Don't return points for hidden datasets
                 // Added 10/08/17
                 if (this.hidden(dataset)) {
                     return null;
                 }

                 return {
                     0: obj, object: obj,
                     1: x, x: x,
                     2: y, y: y,
                     3: i, index: i,
                             tooltip: tooltip,
                             dataset: dataset,
                             index_adjusted: idx
                 };





The key part is this:

// Don't return points for hidden datasets
// Added 10/08/17
if (this.hidden(dataset)) {
     return null;
}



Richard
Posted by Zsolt on 22nd September 2017
Hi,

Sry, I expressed myself poorly, the right solution is using "continue".

regards,
Zsolt
Posted by Richard on 22nd September 2017
Hi,

No it should be returning null. So if the point you're hovering over is hidden, there's no need to continue on with the loop.

For example:

www.rgraph.net/fiddle/view.html/rgraph-line-chart-hiding-dataset

The green dataset is hidden after five seconds and then stops responding to your mouse. Before it's hidden you can see tooltips on the line.

Richard
Posted by Zsolt on 22nd September 2017
Hi,

Ok, try something:
the red and a green line let overlap each other on a data point
     data: [
         [4,8,6,3,5,2,4],
         [1,8,6,9,3,4,8]
     ],
(second and third values)

in this case the tooltip won't show on a red line at second and third values after the green line is hidden.

regards,
Zsolt
Posted by Richard on 22nd September 2017
Hi there,

Thanks. I've just added a new beta that contains the updated library if you want it.

Richard
Posted by Zsolt on 25th September 2017
Hi,

Thanks

regards,
Zsolt

Add a reply




« Back to message list