faheem801 / flot

Automatically exported from code.google.com/p/flot
MIT License
0 stars 0 forks source link

Data Series should have an associated unit #407

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
It would be fantastic if a data series implicitly had an associated unit.

My problem is trying to add the unit to a tooltip (through the hover binding). 
The item available in the hover callback contains a series object. But the 
series object doesn't contain the unit of the series. This leads me to manually 
stripping part of the series label as a unit.

Perhaps the series isn't the best place to store this... afterall all series on 
the same axes share the same units. So maybe the axes should allow this to be 
stored somewhere.

Here is some code:

function handleHover(DOM_placeholder) {
    DOM_placeholder.bind("plothover", function (event, pos, item) {
        if (pos.x) {
            $("#x").text(pos.x.toFixed(2));
            $("#y").text(pos.y.toFixed(2));

            if (item) {
                if (previousPoint != item.datapoint) {
                    previousPoint = item.datapoint;

                    $("#tooltip").remove();
                    var x = item.datapoint[0],
                        y = item.datapoint[1].toFixed(2);
                    // Here's where I'd like to access a unit string without
                                        // manually parsing it out.
                                        var unit = item.series.label.split("(")[1].split(")")[0];
                    var date = new Date(x);
                    var date_str = date.toUTCString();
                    showTooltip(item.pageX, item.pageY,
                                date_str + ", " + y + " " + unit);
                } 
            }
            else {
                $("#tooltip").remove();
            }
        }
    });
}

Original issue reported on code.google.com by DaveMass...@gmail.com on 31 Aug 2010 at 12:34

GoogleCodeExporter commented 9 years ago
I'm sorry... I don't mean for this to be a defect, but rather an enhancement. I 
don't know how to correctly indicate this, though.

Original comment by DaveMass...@gmail.com on 31 Aug 2010 at 5:12

GoogleCodeExporter commented 9 years ago
Hi!

If I remember correctly, Flot will actually keep most of the stuff you put into 
a series when parsing the data. So you can just add a "unit" member if you want 
to, then read it out later.

If you can't get that to work, you can always store the units in a Javascript 
object, then look them up there.

Original comment by olau%iol...@gtempaccount.com on 14 Dec 2010 at 9:47

GoogleCodeExporter commented 9 years ago
I forgot to add that I don't want to add this to Flot directly as this would 
just be another thing I would have to document - and the documentation is 
already big enough as it is (I get reports from people who miss features that 
are already coded and documented :).

Original comment by olau%iol...@gtempaccount.com on 14 Dec 2010 at 9:51

GoogleCodeExporter commented 9 years ago

Original comment by dnsch...@gmail.com on 4 Jun 2012 at 2:52