microcharts-dotnet / Microcharts

Create cross-platform (Xamarin, Windows, ...) simple charts.
MIT License
2.03k stars 360 forks source link

[Bug] The Min/Max values of an Axis chart should be allowed to be less than the Min/Max of the dataset #295

Open brett-estabrook opened 3 years ago

brett-estabrook commented 3 years ago

Currently, you cannot set the Min/Max values of the chart to be more constrained than the Min/Max values of the dataset. If I modify the code to force this, it will draw the chart outside the bounds of the chart area (Covering up the legend, axes, and labels).

The correct behavior would be to set the ClipRect to the Chart Area on the Skia Sharp Canvas when drawing the AxisBasedCharts. This will caused points drawn out of bounds to simply be Culled by the graphics library.

Some Scratch work

Video of Progress: https://github.com/microcharts-dotnet/Microcharts/issues/296#issuecomment-948185762

Todo Items:

brett-estabrook commented 3 years ago

How do we handle chart labels that are outside the chart bounds (Should we just anchor it to the top)?

Screen Shot 2021-10-20 at 8 49 34 PM

The dots for point charts (and line charts), can be clipped on the edges. Should we allow this or move the points inbounds, or extend the clip rect by the radius. If we extend the cliprect then the chart could overlap the labels underneath.

Screen Shot 2021-10-20 at 8 49 44 PM

Lines near the edge have problems as well.

Screen Shot 2021-10-20 at 8 49 53 PM
Seuleuzeuh commented 3 years ago

The main goal it's to use it as part of the PinchToZoom right ? I don't fing another use case for that functionnality, do you have one ?

If the only use case is the PinchToZoom i think we can let the label/point/line generation like this, as a first approach of the functionnality. As the generation of label will be more tricky. I don't like the idea of the chart will be drawn over the other objects (even if it's only some pixels). What do you think @eman1986 ?

For the Y axis, can you show me the problematic result ? It's the only part that (for me) must be update as it's a "mandatory" function for users to allow more readability of charts.

brett-estabrook commented 3 years ago

The main goal it's to use it as part of the PinchToZoom right ?

Yes

I don't fing another use case for that functionnality, do you have one ?

One minor one, is when the MaxValue of the data points is high and the user wants to Set the MaxValue of the chart less than the Max Value of the data and see only a subset of the chart. This is like pinch to zoom, but doesn't necessarily require it.

For the Y axis, can you show me the problematic result

Look at the top most Y axis value in the upper left. It technically draws outside the chart bounds. The horizontal line is the upper most value of the chart bounds.

Screen Shot 2021-10-29 at 6 29 10 PM

Look at the Y axis value in the lower left. It has the same problem.

Screen Shot 2021-10-29 at 6 31 15 PM

My thought is to allow the chart to draw outside the bounds by half the value of the height of a y axis label. @Seuleuzeuh do you think that would work?

Seuleuzeuh commented 3 years ago

Yes I think that should work !