krzysu / flot.tooltip

tooltip plugin for wonderful Flot plotting library
https://github.com/krzysu/flot.tooltip
187 stars 153 forks source link

Escape dollar when replacing values for tick's label #134

Closed daniloisr closed 8 years ago

daniloisr commented 8 years ago

I just found that when a tooltip, beginning with $1, is placed exactly on a tick with the same value the $1 is removed due the $ behaviour on String#replace

From String#replace docs: $n or $nn: Where n or nn are decimal digits, inserts the nth parenthesized submatch string, provided the first argument was a RegExp object.

It's easier to visualize this with this example: flot-tooltip Example here: https://jsbin.com/muvakuxefu/1/edit?output

Solution: Uses replaces to change a single dollar ($) to a double dollar ($$), so when content.replace run we continue with the original $.

From String#replace docs: $$: Inserts a "$".

Here is my solution (this PR changes): https://jsbin.com/tubuxutado/1/edit?output


On my production scenario I have a point with $127,40 dollars exactly on 127,40 tick, and the tooltip value became 27,40.

Another solution to this is using a double dollar on tickFormatter, but I don't know if this is the best solution:

    tickFormatter: function(val, axis) {
      return "$$" + val.toFixed(2);
    }
Roundaround commented 8 years ago

Thanks for this!