ogallagher / fxgraph

A JavaFX graph editor
Do What The F*ck You Want To Public License
2 stars 0 forks source link

Scale cartesian graph points to fit initial viewport #21

Open ogallagher opened 2 years ago

ogallagher commented 2 years ago

In a cartesian graph, between the data coordinates for a point (raw x,y) and the viewport coordinates (camera pan, zoom), there should be a transform for display coordinates, given the desired viewport space versus the data space. For example, this transform could optionally flip the y axis and scale the data to fit in the initial viewport (pan=0,0 zoom=1) when displayed.

Use the FitToContentLayout class for this, and make a difference in the placement of a point between the point’s coordinates and the displayed location (CartesianPoint.getGraphic).

ogallagher commented 2 years ago

Change of plan! It should be much easier to just change the initial transform on the graph canvas to fit the content rather than transforming the content to fit the canvas. If I can implement this way, I’ll update the issue title accordingly.

ogallagher commented 2 years ago

So far I’ve implemented basic scaling, but haven’t fixed translation. Scaling the canvas invalidates the calculated translation, and recalculating translation doesn't account for the scaling either, unfortunately.

Also, in order to flip the y axis I need to be able to set the y-scale to -1 in the canvas, which is not possible with the current PannableCanvas class, and I believe would also mess up graph node mouse interaction.