Skip to content

Commit 5fd878f

Browse files
Adjusting yAxis based on scale
1 parent 684c92c commit 5fd878f

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

Sources/Microcharts/Charts/AxisBasedChart.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public float SerieLabelTextSize
133133
/// <summary>
134134
/// Determines whether pinch to zoom will work on the chart
135135
/// </summary>
136-
public bool EnableZoom { get; set; } = false;
136+
public bool EnableZoom { get; set; } = true; //FIXME: This should be off by default, but easier to test charts with it on
137137

138138
public ChartXForm XForm { get; } = new ChartXForm();
139139

@@ -197,10 +197,22 @@ public override void DrawContent(SKCanvas canvas, int width, int height)
197197
float maxValue = InternalMaxValue.HasValue ? InternalMaxValue.Value : MaxValue;
198198
float minValue = InternalMinValue.HasValue ? InternalMinValue.Value : MinValue;
199199

200-
//This function might change the min/max value
201-
string yAxisFormat = XForm.Scale == 1.0f ? "G" : "F1";
200+
//FIXME: If you don't mark it as fixed range, the vertical scale can change while zooming based on rounding in NiceNum
201+
//This causes a POP in scale, so we calculated the Min/Max based on a scale of 1.0 and mark it has fixed
202+
203+
float yAxisXShift;
204+
List<float> yAxisIntervalLabels;
205+
string yAxisFormat = XForm.Scale == 1.0f ? "G" : "F1"; //As we scale the yAxis we get more decimal places
206+
if (EnableZoom && !fixedRange)
207+
{
208+
//WARNING: This will change Min/Max based on a scale of 1.0
209+
MeasureHelper.CalculateYAxis(ShowYAxisText, ShowYAxisLines, yAxisFormat, YAxisMaxTicks, YAxisTextPaint, YAxisPosition, width, fixedRange, ref maxValue, ref minValue, out yAxisXShift, out yAxisIntervalLabels);
210+
fixedRange = true;
211+
}
212+
213+
//WARNING: This will change Min/Max based on a scale of XForm.Scale
202214
int yMaxTicks = (int)(YAxisMaxTicks * XForm.Scale);
203-
var yAxisSize = MeasureHelper.CalculateYAxis(ShowYAxisText, ShowYAxisLines, yAxisFormat, yMaxTicks, YAxisTextPaint, YAxisPosition, width, fixedRange, ref maxValue, ref minValue, out float yAxisXShift, out List<float> yAxisIntervalLabels);
215+
var yAxisSize = MeasureHelper.CalculateYAxis(ShowYAxisText, ShowYAxisLines, yAxisFormat, yMaxTicks, YAxisTextPaint, YAxisPosition, width, fixedRange, ref maxValue, ref minValue, out yAxisXShift, out yAxisIntervalLabels);
204216
width = (int)yAxisSize.Width;
205217

206218
float valRange = maxValue - minValue;

0 commit comments

Comments
 (0)