Skip to content

Commit 27a47ea

Browse files
committed
feat: new API. All methods used as getter/setter (setData,setColor,getData...) are now properties (color, data...)
Also charts are now faster, new properties were added, and a lot bugs were fixed BREAKING CHANGE: The API change is breaking (for the better!). Use Typescript typings to find out the new property names (mostly same as what was used in method name).
1 parent aab1079 commit 27a47ea

20 files changed

+160
-200
lines changed

src/ui-chart/charts/BarLineChartBase.ts

+35-35
Original file line numberDiff line numberDiff line change
@@ -182,20 +182,20 @@ export abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatte
182182
// execute all drawing commands
183183
this.drawGridBackground(canvas);
184184
const xAxis = this.xAxis;
185-
const axisLeft = this.axisLeft;
186-
const axisRight = this.axisRight;
185+
const axisLeft = this.mAxisLeft;
186+
const axisRight = this.mAxisRight;
187187

188188
// the order is important:
189-
// * computeAxis needs axis.mAxisMinimum set in autoScale
189+
// * computeAxis needs axis.axisMinimum set in autoScale
190190
// * calculateOffsets needs computeAxis because it needs axis longestLabel
191191
if (!noComputeAutoScaleOnNextDraw && this.autoScaleMinMaxEnabled) {
192192
this.autoScale();
193193
}
194194

195195
if (!noComputeAxisOnNextDraw) {
196-
this.axisRendererLeft.computeAxis(axisLeft.mAxisMinimum, axisLeft.mAxisMaximum, axisLeft.inverted);
197-
this.axisRendererRight.computeAxis(axisRight.mAxisMinimum, axisRight.mAxisMaximum, axisRight.inverted);
198-
this.xAxisRenderer.computeAxis(this.xAxis.mAxisMinimum, this.xAxis.mAxisMaximum, false);
196+
this.axisRendererLeft?.computeAxis(axisLeft.axisMinimum, axisLeft.axisMaximum, axisLeft.inverted);
197+
this.axisRendererRight?.computeAxis(axisRight.axisMinimum, axisRight.axisMaximum, axisRight.inverted);
198+
this.xAxisRenderer?.computeAxis(this.xAxis.axisMinimum, this.xAxis.axisMaximum, false);
199199
}
200200

201201
if (!this.offsetsCalculated) {
@@ -205,19 +205,19 @@ export abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatte
205205

206206
if (xAxis.drawGridLinesBehindData) this.xAxisRenderer.renderGridLines(canvas);
207207
if (axisLeft.drawGridLinesBehindData) this.axisRendererLeft.renderGridLines(canvas);
208-
if (axisRight.drawGridLinesBehindData) this.axisRendererRight.renderGridLines(canvas);
208+
if (axisRight?.drawGridLinesBehindData) this.axisRendererRight.renderGridLines(canvas);
209209

210210
if (xAxis.drawLimitLinesBehindData) this.xAxisRenderer.renderLimitLines(canvas);
211211
if (axisLeft.drawLimitLinesBehindData) this.axisRendererLeft.renderLimitLines(canvas);
212-
if (axisRight.drawLimitLinesBehindData) this.axisRendererRight.renderLimitLines(canvas);
212+
if (axisRight?.drawLimitLinesBehindData) this.axisRendererRight.renderLimitLines(canvas);
213213

214214
this.xAxisRenderer.renderAxisLine(canvas);
215215
this.axisRendererLeft.renderAxisLine(canvas);
216-
this.axisRendererRight.renderAxisLine(canvas);
216+
this.axisRendererRight?.renderAxisLine(canvas);
217217

218218
if (xAxis.drawLabelsBehindData) this.xAxisRenderer.renderAxisLabels(canvas);
219219
if (axisLeft.drawLabelsBehindData) this.axisRendererLeft.renderAxisLabels(canvas);
220-
if (axisRight.drawLabelsBehindData) this.axisRendererRight.renderAxisLabels(canvas);
220+
if (axisRight?.drawLabelsBehindData) this.axisRendererRight.renderAxisLabels(canvas);
221221

222222
// make sure the data cannot be drawn outside the content-rect
223223
if (this.clipDataToContent) {
@@ -230,7 +230,7 @@ export abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatte
230230

231231
if (!xAxis.drawGridLinesBehindData) this.xAxisRenderer.renderGridLines(canvas);
232232
if (!axisLeft.drawGridLinesBehindData) this.axisRendererLeft.renderGridLines(canvas);
233-
if (!axisRight.drawGridLinesBehindData) this.axisRendererRight.renderGridLines(canvas);
233+
if (axisRight?.drawGridLinesBehindData === false) this.axisRendererRight.renderGridLines(canvas);
234234

235235
if (!this.clipHighlightToContent && this.clipDataToContent) {
236236
// restore before drawing highlight
@@ -249,11 +249,11 @@ export abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatte
249249

250250
if (!xAxis.drawLimitLinesBehindData) this.xAxisRenderer.renderLimitLines(canvas);
251251
if (!axisLeft.drawLimitLinesBehindData) this.axisRendererLeft.renderLimitLines(canvas);
252-
if (!axisRight.drawLimitLinesBehindData) this.axisRendererRight.renderLimitLines(canvas);
252+
if (axisRight?.drawLimitLinesBehindData === false) this.axisRendererRight.renderLimitLines(canvas);
253253

254254
if (!xAxis.drawLabelsBehindData) this.xAxisRenderer.renderAxisLabels(canvas);
255255
if (!axisLeft.drawLabelsBehindData) this.axisRendererLeft.renderAxisLabels(canvas);
256-
if (!axisRight.drawLabelsBehindData) this.axisRendererRight.renderAxisLabels(canvas);
256+
if (axisRight?.drawLabelsBehindData === false) this.axisRendererRight.renderAxisLabels(canvas);
257257

258258
if (this.clipValuesToContent) {
259259
canvas.save();
@@ -291,13 +291,13 @@ export abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatte
291291

292292
protected prepareValuePxMatrix() {
293293
if (Trace.isEnabled()) {
294-
CLog(CLogTypes.info, LOG_TAG, 'Preparing Value-Px Matrix, xmin: ' + this.xAxis.mAxisMinimum + ', xmax: ' + this.xAxis.mAxisMaximum + ', xdelta: ' + this.xAxis.mAxisRange);
294+
CLog(CLogTypes.info, LOG_TAG, 'Preparing Value-Px Matrix, xmin: ' + this.xAxis.axisMinimum + ', xmax: ' + this.xAxis.axisMaximum + ', xdelta: ' + this.xAxis.axisRange);
295295
}
296296
if (this.mAxisRight?.enabled) {
297-
this.rightAxisTransformer.prepareMatrixValuePx(this.xAxis.mAxisMinimum, this.xAxis.mAxisRange, this.mAxisRight.mAxisRange, this.mAxisRight.mAxisMinimum);
297+
this.rightAxisTransformer.prepareMatrixValuePx(this.xAxis.axisMinimum, this.xAxis.axisRange, this.mAxisRight.axisRange, this.mAxisRight.axisMinimum);
298298
}
299299
if (this.mAxisLeft?.enabled || this.xAxis.enabled) {
300-
this.leftAxisTransformer.prepareMatrixValuePx(this.xAxis.mAxisMinimum, this.xAxis.mAxisRange, this.mAxisLeft.mAxisRange, this.mAxisLeft.mAxisMinimum);
300+
this.leftAxisTransformer.prepareMatrixValuePx(this.xAxis.axisMinimum, this.xAxis.axisRange, this.mAxisLeft.axisRange, this.mAxisLeft.axisMinimum);
301301
}
302302
}
303303

@@ -332,13 +332,13 @@ export abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatte
332332
this.calcMinMax();
333333

334334
if (this.mAxisLeft?.enabled) {
335-
this.axisRendererLeft.computeAxis(this.mAxisLeft.mAxisMinimum, this.mAxisLeft.mAxisMaximum, this.mAxisLeft.inverted);
335+
this.axisRendererLeft.computeAxis(this.mAxisLeft.axisMinimum, this.mAxisLeft.axisMaximum, this.mAxisLeft.inverted);
336336
}
337337
if (this.mAxisRight?.enabled) {
338-
this.axisRendererRight.computeAxis(this.mAxisRight.mAxisMinimum, this.mAxisRight.mAxisMaximum, this.mAxisRight.inverted);
338+
this.axisRendererRight.computeAxis(this.mAxisRight.axisMinimum, this.mAxisRight.axisMaximum, this.mAxisRight.inverted);
339339
}
340340
if (this.xAxis.enabled) {
341-
this.xAxisRenderer.computeAxis(this.xAxis.mAxisMinimum, this.xAxis.mAxisMaximum, false);
341+
this.xAxisRenderer.computeAxis(this.xAxis.axisMinimum, this.xAxis.axisMaximum, false);
342342
}
343343

344344
if (this.mLegend != null && this.mLegend.enabled) {
@@ -667,7 +667,7 @@ export abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatte
667667
this,
668668
this.getTransformer(axis),
669669
this.getAxis(axis),
670-
this.xAxis.mAxisRange,
670+
this.xAxis.axisRange,
671671
scaleX,
672672
scaleY,
673673
this.viewPortHandler.getScaleX(),
@@ -698,7 +698,7 @@ export abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatte
698698
this,
699699
this.getTransformer(axis),
700700
this.getAxis(axis),
701-
this.xAxis.mAxisRange,
701+
this.xAxis.axisRange,
702702
scaleX,
703703
scaleY,
704704
this.viewPortHandler.getScaleX(),
@@ -759,7 +759,7 @@ export abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatte
759759
* @param maxXRange The maximum visible range of x-values.
760760
*/
761761
public set visibleXRangeMaximum(maxXRange) {
762-
const xScale = this.xAxis.mAxisRange / maxXRange;
762+
const xScale = this.xAxis.axisRange / maxXRange;
763763
this.viewPortHandler.setMinimumScaleX(xScale);
764764
}
765765

@@ -772,7 +772,7 @@ export abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatte
772772
* @param minXRange The minimum visible range of x-values.
773773
*/
774774
public set visibleXRangeMinimum(minXRange) {
775-
const xScale = this.xAxis.mAxisRange / minXRange;
775+
const xScale = this.xAxis.axisRange / minXRange;
776776
this.viewPortHandler.setMaximumScaleX(xScale);
777777
}
778778

@@ -785,8 +785,8 @@ export abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatte
785785
* @param maxXRange
786786
*/
787787
public setVisibleXRange(minXRange, maxXRange) {
788-
const minScale = this.xAxis.mAxisRange / minXRange;
789-
const maxScale = this.xAxis.mAxisRange / maxXRange;
788+
const minScale = this.xAxis.axisRange / minXRange;
789+
const maxScale = this.xAxis.axisRange / maxXRange;
790790
this.viewPortHandler.setMinMaxScaleX(minScale, maxScale);
791791
}
792792

@@ -902,7 +902,7 @@ export abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatte
902902
*/
903903
public centerViewTo(xValue, yValue, axis) {
904904
const yInView = this.getAxisRange(axis) / this.viewPortHandler.getScaleY();
905-
const xInView = this.xAxis.mAxisRange / this.viewPortHandler.getScaleX();
905+
const xInView = this.xAxis.axisRange / this.viewPortHandler.getScaleX();
906906

907907
const job = MoveViewJob.getInstance(this.viewPortHandler, xValue - xInView / 2, yValue + yInView / 2, this.getTransformer(axis), this);
908908

@@ -922,7 +922,7 @@ export abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatte
922922
const bounds = this.getValuesByTouchPoint(this.viewPortHandler.contentLeft, this.viewPortHandler.contentTop, axis);
923923

924924
const yInView = this.getAxisRange(axis) / this.viewPortHandler.getScaleY();
925-
const xInView = this.xAxis.mAxisRange / this.viewPortHandler.getScaleX();
925+
const xInView = this.xAxis.axisRange / this.viewPortHandler.getScaleX();
926926

927927
const job = AnimatedMoveViewJob.getInstance(this.viewPortHandler, xValue - xInView / 2, yValue + yInView / 2, this.getTransformer(axis), this, bounds.x, bounds.y, duration);
928928

@@ -982,8 +982,8 @@ export abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatte
982982
* @return
983983
*/
984984
protected getAxisRange(axis) {
985-
if (axis === AxisDependency.LEFT) return this.mAxisLeft.mAxisRange;
986-
else return this.mAxisRight && this.mAxisRight.mAxisRange;
985+
if (axis === AxisDependency.LEFT) return this.mAxisLeft.axisRange;
986+
else return this.mAxisRight && this.mAxisRight.axisRange;
987987
}
988988

989989
/**
@@ -1231,7 +1231,7 @@ export abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatte
12311231
*/
12321232
public get lowestVisibleX() {
12331233
this.transformer.getValuesByTouchPoint(this.viewPortHandler.contentLeft, this.viewPortHandler.contentBottom, this.posForGetLowestVisibleX);
1234-
const result = Math.max(this.xAxis.mAxisMinimum, this.posForGetLowestVisibleX.x);
1234+
const result = Math.max(this.xAxis.axisMinimum, this.posForGetLowestVisibleX.x);
12351235
return result;
12361236
}
12371237

@@ -1246,7 +1246,7 @@ export abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatte
12461246
*/
12471247
public get highestVisibleX() {
12481248
this.transformer.getValuesByTouchPoint(this.viewPortHandler.contentRight, this.viewPortHandler.contentBottom, this.posForGetHighestVisibleX);
1249-
const result = Math.min(this.xAxis.mAxisMaximum, this.posForGetHighestVisibleX.x);
1249+
const result = Math.min(this.xAxis.axisMaximum, this.posForGetHighestVisibleX.x);
12501250
return result;
12511251
}
12521252

@@ -1398,21 +1398,21 @@ export abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatte
13981398
public get yChartMax() {
13991399
let max = -Infinity;
14001400
if (this.mAxisLeft.enabled) {
1401-
max = Math.max(this.mAxisLeft.mAxisMaximum, max);
1401+
max = Math.max(this.mAxisLeft.axisMaximum, max);
14021402
}
14031403
if (this.mAxisRight?.enabled) {
1404-
max = Math.max(this.mAxisRight.mAxisMaximum, max);
1404+
max = Math.max(this.mAxisRight.axisMaximum, max);
14051405
}
14061406
return max;
14071407
}
14081408

14091409
public get yChartMin() {
14101410
let min = Infinity;
14111411
if (this.mAxisLeft.enabled) {
1412-
min = Math.min(this.mAxisLeft.mAxisMinimum, min);
1412+
min = Math.min(this.mAxisLeft.axisMinimum, min);
14131413
}
14141414
if (this.mAxisRight?.enabled) {
1415-
min = Math.min(this.mAxisRight.mAxisMinimum, min);
1415+
min = Math.min(this.mAxisRight.axisMinimum, min);
14161416
}
14171417
return min;
14181418
}

src/ui-chart/charts/Chart.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,14 @@ export abstract class Chart<U extends Entry, D extends IDataSet<U>, T extends Ch
258258
return this.mData;
259259
}
260260

261+
get viewPortScaleX() {
262+
return this.viewPortHandler.scaleX;
263+
}
264+
265+
get viewPortScaleY() {
266+
return this.viewPortHandler.scaleY;
267+
}
268+
261269
/**
262270
* Clears the chart from all data (sets it to null) and refreshes it (by
263271
* calling invalidate()).
@@ -706,15 +714,15 @@ export abstract class Chart<U extends Entry, D extends IDataSet<U>, T extends Ch
706714
}
707715

708716
public get xChartMax() {
709-
return this.xAxis.mAxisMaximum;
717+
return this.xAxis.axisMaximum;
710718
}
711719

712720
public get xChartMin() {
713-
return this.xAxis.mAxisMinimum;
721+
return this.xAxis.axisMinimum;
714722
}
715723

716724
public get xRange() {
717-
return this.xAxis.mAxisRange;
725+
return this.xAxis.axisRange;
718726
}
719727

720728
/**

src/ui-chart/charts/HorizontalBarChart.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ export class HorizontalBarChart extends BarChart {
9393

9494
protected prepareValuePxMatrix() {
9595
if (this.mAxisRight?.enabled) {
96-
this.rightAxisTransformer.prepareMatrixValuePx(this.mAxisRight.mAxisMinimum, this.mAxisRight.mAxisRange, this.xAxis.mAxisRange, this.xAxis.mAxisMinimum);
96+
this.rightAxisTransformer.prepareMatrixValuePx(this.mAxisRight.axisMinimum, this.mAxisRight.axisRange, this.xAxis.axisRange, this.xAxis.axisMinimum);
9797
}
9898
if (this.mAxisLeft.enabled) {
99-
this.leftAxisTransformer.prepareMatrixValuePx(this.mAxisLeft.mAxisMinimum, this.mAxisLeft.mAxisRange, this.xAxis.mAxisRange, this.xAxis.mAxisMinimum);
99+
this.leftAxisTransformer.prepareMatrixValuePx(this.mAxisLeft.axisMinimum, this.mAxisLeft.axisRange, this.xAxis.axisRange, this.xAxis.axisMinimum);
100100
}
101101
}
102102

@@ -185,30 +185,30 @@ export class HorizontalBarChart extends BarChart {
185185

186186
public get lowestVisibleX() {
187187
this.transformer.getValuesByTouchPoint(this.viewPortHandler.contentLeft, this.viewPortHandler.contentBottom, this.posForGetLowestVisibleX);
188-
return Math.max(this.xAxis.mAxisMinimum, this.posForGetLowestVisibleX.y);
188+
return Math.max(this.xAxis.axisMinimum, this.posForGetLowestVisibleX.y);
189189
}
190190

191191
public get highestVisibleX() {
192192
this.transformer.getValuesByTouchPoint(this.viewPortHandler.contentLeft, this.viewPortHandler.contentTop, this.posForGetHighestVisibleX);
193-
return Math.min(this.xAxis.mAxisMaximum, this.posForGetHighestVisibleX.y);
193+
return Math.min(this.xAxis.axisMaximum, this.posForGetHighestVisibleX.y);
194194
}
195195

196196
/**
197197
* ###### VIEWPORT METHODS BELOW THIS ######
198198
*/
199199
public set visibleXRangeMaximum(maxXRange) {
200-
const xScale = this.xAxis.mAxisRange / maxXRange;
200+
const xScale = this.xAxis.axisRange / maxXRange;
201201
this.viewPortHandler.setMinimumScaleY(xScale);
202202
}
203203

204204
public set visibleXRangeMinimum(minXRange) {
205-
const xScale = this.xAxis.mAxisRange / minXRange;
205+
const xScale = this.xAxis.axisRange / minXRange;
206206
this.viewPortHandler.setMaximumScaleY(xScale);
207207
}
208208

209209
public setVisibleXRange(minXRange, maxXRange) {
210-
const minScale = this.xAxis.mAxisRange / minXRange;
211-
const maxScale = this.xAxis.mAxisRange / maxXRange;
210+
const minScale = this.xAxis.axisRange / minXRange;
211+
const maxScale = this.xAxis.axisRange / maxXRange;
212212
this.viewPortHandler.setMinMaxScaleY(minScale, maxScale);
213213
}
214214

src/ui-chart/charts/PieRadarChartBase.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export abstract class PieRadarChartBase<U extends Entry, D extends IDataSet<U>,
5858
}
5959

6060
protected calcMinMax() {
61-
//mXAxis.mAxisRange = this.mData.getXVals().length - 1;
61+
//mXAxis.axisRange = this.mData.getXVals().length - 1;
6262
}
6363

6464
get maxVisibleValueCount() {

src/ui-chart/charts/RadarChart.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ export class RadarChart extends PieRadarChartBase<Entry, RadarDataSet, RadarData
9797

9898
this.calcMinMax();
9999

100-
this.yAxisRenderer.computeAxis(this.yAxis.mAxisMinimum, this.yAxis.mAxisMaximum, this.yAxis.inverted);
101-
this.xAxisRenderer.computeAxis(this.xAxis.mAxisMinimum, this.xAxis.mAxisMaximum, false);
100+
this.yAxisRenderer.computeAxis(this.yAxis.axisMinimum, this.yAxis.axisMaximum, this.yAxis.inverted);
101+
this.xAxisRenderer.computeAxis(this.xAxis.axisMinimum, this.xAxis.axisMaximum, false);
102102

103103
if (this.mLegend != null && !this.mLegend.isLegendCustom()) this.legendRenderer.computeLegend(this.mData);
104104

@@ -112,7 +112,7 @@ export class RadarChart extends PieRadarChartBase<Entry, RadarDataSet, RadarData
112112
if (this.mData == null) return;
113113

114114
if (this.xAxis.enabled) {
115-
this.xAxisRenderer.computeAxis(this.xAxis.mAxisMinimum, this.xAxis.mAxisMaximum, false);
115+
this.xAxisRenderer.computeAxis(this.xAxis.axisMinimum, this.xAxis.axisMaximum, false);
116116
this.xAxisRenderer.renderAxisLabels(c);
117117
}
118118

@@ -150,7 +150,7 @@ export class RadarChart extends PieRadarChartBase<Entry, RadarDataSet, RadarData
150150
*/
151151
public get factor() {
152152
const content = this.viewPortHandler.contentRect;
153-
return Math.min(content.width() / 2, content.height() / 2) / this.yAxis.mAxisRange;
153+
return Math.min(content.width() / 2, content.height() / 2) / this.yAxis.axisRange;
154154
}
155155

156156
/**
@@ -216,21 +216,21 @@ export class RadarChart extends PieRadarChartBase<Entry, RadarDataSet, RadarData
216216
* Returns the maximum value this chart can display on it's y-axis.
217217
*/
218218
public get yChartMax() {
219-
return this.yAxis.mAxisMaximum;
219+
return this.yAxis.axisMaximum;
220220
}
221221

222222
/**
223223
* Returns the minimum value this chart can display on it's y-axis.
224224
*/
225225
public get yChartMin() {
226-
return this.yAxis.mAxisMinimum;
226+
return this.yAxis.axisMinimum;
227227
}
228228

229229
/**
230230
* Returns the range of y-values this chart can display.
231231
*/
232232
public get yRange() {
233-
return this.yAxis.mAxisRange;
233+
return this.yAxis.axisRange;
234234
}
235235

236236
customRenderer: CustomRenderer;

0 commit comments

Comments
 (0)