Raruto / leaflet-elevation

Leaflet plugin that allows to add elevation profiles using d3js
GNU General Public License v3.0
254 stars 82 forks source link

Excessive approximation of tooltip values (map marker) #200

Closed hupe13 closed 1 year ago

hupe13 commented 2 years ago

Hi Raruto,

during my tests, I noticed the accuracy of the tooltip and marker information. Most of the time, the marker is rounded to whole numbers, altitude and distance have options opts.decimalsX and opts.decimalsY. Isn't it better to use the same precision for the marker and tooltip? Or even better you can make the accuracy dependent on the size of value. Is this useful and possible?

grafik grafik grafik grafik

Thank you very much.

Raruto commented 2 years ago

As I remember lately I added this option as well (mainly in use within the various handlers):

https://github.com/Raruto/leaflet-elevation/blob/37372a5dcf0a68b9d520b1195a488fbd1f140869/src/control.js#L1049-L1052


Regarding the following options:

https://github.com/Raruto/leaflet-elevation/blob/37372a5dcf0a68b9d520b1195a488fbd1f140869/src/options.js#L78-L79

they are a legacy of MrMufflon/Leaflet.Elevation library. Honestly, I don't know how much they are in use today and personally I've never even felt the need to use them.


Isn't it better to use the same precision for the marker and tooltip?

If I'm not mistaken in the beginning it was like this, but in my opinion the information showed inside the map marker was more difficult to read, also because the tooltip moves in multiple dimensions while hovering. For example, the acceleration value showed too many useless changes in the decimals part that could distract the user too much from the value contained inside the integer part (which should be the most relevant part).


Or even better you can make the accuracy dependent on the size of value. Is this useful and possible?

Possible, but I don't think we can make it a general rule that applies to everyone, anyway, let me know if you think you have a pretty nifty solution.

Have a nice day, Raruto

hupe13 commented 2 years ago

I think the best is when the accuracy is dependent on the size. What do I care about the decimal places when the speed is 500 km/h? But it's not really true when the displayed value on the marker is always 0 when in the tooltip it's in the range from 0 to 0.5 (e.g.) I will think about it.

hupe13 commented 2 years ago

https://github.com/Raruto/leaflet-elevation/pull/210#discussion_r977833344 I will use

parseFloat((x).toPrecision(n))

because of

// note that exponential notation might be returned in some circumstances console.log((1234.5).toPrecision(2)) // logs '1.2e+3'

(see here)

hupe13 commented 1 year ago

I'm closing this, I solved it with your example code.

Thank you very much.