https://kotlinlang.org logo
Title
h

halirutan

12/22/2021, 4:57 PM
Merry almost Christmas everyone. I'm implementing a small prototype to draw time-series data into a coordinate-system using a Canvas. To give an example, look at the following graph to display financial data. My idea was to transform the viewport into the range of the data points so that I only have one transformation and I don't need to rescale possibly several thousand of data points. So my plan was: • Calculate the viewport transformation (scaling, translation) that depends on the range of the data and e.g. zoom level the user can change • Draw the data without having to re-scale it. Possibly using (hopefully) faster low-level
drawVertices
functions that don't call drawing functions over and over again, but work on arrays Now there are several obstacles. One is, if I scale the viewport, the glyphs of the fonts are also scaled but I think that can be solved rather easily. My question is, is there any example code that does something similar because most of the examples/tutorials only use transformations for animations? Even after a rather careful search, I couldn't find anything remotely related to what I try to do which is "plotting mathematical functions". If someone has hints or links how I could approach this or why my plan is destined to fail, I'm all ears.
m

Michael Paus

12/22/2021, 6:06 PM
I think you are on the right track. This is from the JavaFX world but maybe you can draw some inspiration from it. Chart-FX
h

halirutan

12/23/2021, 6:23 AM
Thanks Michael. I also found https://github.com/Madrapps/plot which does the unwanted data scaling, but contains other good ideas.
And there seem to be similar library for Jetpack Compose where you could potentially collect ides.