epezent / implot

Immediate Mode Plotting
MIT License
4.65k stars 517 forks source link

ColormapScale function cannot handle inverted min / max ranges #368

Closed WeirdRubberDuck closed 2 years ago

WeirdRubberDuck commented 2 years ago

See example in demo, where I set min > max: image

The ticks and labels do not show up in the ColromapScale. Would be great if they did, or if there was another way to invert the color map

epezent commented 2 years ago

Thanks for flagging this -- we can work in support for inverted scales. I think it would make more sense to enable inversion with e.g. ImPlotColormapScaleFlags_Invert than misconstruing the min/max values (this flag could also allow for more options/customization in the future). Thoughts?

epezent commented 2 years ago

Hi, let me know if https://github.com/epezent/implot/commit/0f4d4dccc333c4e5aeebeb27866857cc45627dfe helps you achieve the functionality you need. See below:

cmapscale

WeirdRubberDuck commented 2 years ago

I agree, an invert flag is perfect.

However, in that flip, I would expect 0 db to be mapped to yellow and 100 dB to be mapped to purple when the ImPlotColormapScaleFlags_Invert is set to true

epezent commented 2 years ago

Oh! I completely missed your point. I see now you want to invert the mapping from from the data range to color range. I thought you just wanted to turn the widget upside down 😂

In that case, I think your original proposal of flipping min/max scale is the right one. I'll take a look and figure out why that's not working. Sorry for the mixup!

epezent commented 2 years ago

Ok, give https://github.com/epezent/implot/commit/6c00109636a78cd317de2b2a02744deec523b181 a go! To summarize the new behavior, scale_min > scale_max will reverse the mapping from the scale range to the color range (i.e. only affects axis direction) and ImPlotColormapScale_Invert will invert both the colormap bar and axis. See below:

scale_min < scale_max scale_min > scale_max
ImPlotColormapScaleFlags_None image image
ImPlotColormapScaleFlags_Invert image image
WeirdRubberDuck commented 2 years ago

Cool! Have some other things to prioritize but will try that out asap 😄 Thanks !