Skip to content

Commit e7879e8

Browse files
committed
fix: regressions fix
1 parent d42ad16 commit e7879e8

14 files changed

+95
-144
lines changed

src/ui-chart/charts/BarLineChartBase.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,7 @@ export abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatte
279279
} else {
280280
this.renderer.drawValues(canvas);
281281
}
282-
if (this.legendRenderer) {
283-
this.legendRenderer.renderLegend(canvas);
284-
}
282+
this.legendRenderer?.renderLegend(canvas);
285283

286284
this.drawDescription(canvas);
287285

@@ -764,6 +762,11 @@ export abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatte
764762
*/
765763
public setScale(scaleX, scaleY) {
766764
this.viewPortHandler.setScale(scaleX, scaleY);
765+
// Range might have changed, which means that Y-axis labels
766+
// could have changed in size, affecting Y-axis size.
767+
// So we need to recalculate offsets.
768+
this.calculateOffsets();
769+
this.invalidate();
767770
}
768771

769772
/**

src/ui-chart/charts/Chart.ts

-13
Original file line numberDiff line numberDiff line change
@@ -860,19 +860,6 @@ export abstract class Chart<U extends Entry, D extends IDataSet<U>, T extends Ch
860860
return this.center;
861861
}
862862

863-
/**
864-
* Flag that indicates if highlighting per tap (touch) is enabled
865-
*/
866-
get highlightPerTapEnabled() {
867-
return this.mHighlightPerTapEnabled;
868-
}
869-
/**
870-
* Flag that indicates if highlighting per tap (touch) is enabled
871-
*/
872-
set highlightPerTapEnabled(value: boolean) {
873-
this.mHighlightPerTapEnabled = value;
874-
}
875-
876863
/**
877864
* Returns the bitmap that represents the chart.
878865
*/

src/ui-chart/data/BaseDataSet.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export abstract class BaseDataSet<T extends Entry> implements IDataSet<T> {
6161
/**
6262
* List representing all colors that are used for drawing the actual values for this DataSet
6363
*/
64-
valueColors: (string | Color)[] = null;
64+
valueColors: (string | Color)[] = ['black'];
6565

6666
/**
6767
* label that describes the DataSet or the data the DataSet represents
@@ -129,8 +129,6 @@ export abstract class BaseDataSet<T extends Entry> implements IDataSet<T> {
129129
* @param label
130130
*/
131131
constructor(label, xProperty?, yProperty?) {
132-
this.colors = [];
133-
this.valueColors = [];
134132
// if (xProperty) {
135133
this.xProperty = xProperty;
136134
// }
@@ -146,7 +144,6 @@ export abstract class BaseDataSet<T extends Entry> implements IDataSet<T> {
146144
this.getEntryXValue = (e: T, entryIndex: number) => e[this.xProperty];
147145
}
148146

149-
this.valueColors.push('black');
150147
this.label = label;
151148
}
152149

@@ -234,8 +231,7 @@ export abstract class BaseDataSet<T extends Entry> implements IDataSet<T> {
234231
}
235232

236233
public set valueTextColor(color) {
237-
this.valueColors = [];
238-
this.valueColors.push(color);
234+
this.valueColors = [color];
239235
}
240236

241237
public set valueTextColors(colors) {

src/ui-chart/data/ChartData.ts

+35-59
Original file line numberDiff line numberDiff line change
@@ -112,57 +112,37 @@ export abstract class ChartData<U extends Entry, T extends IDataSet<U>> {
112112
* Calc minimum and maximum values (both x and y) over all DataSets.
113113
*/
114114
calcMinMax() {
115-
if (!this.mDataSets) return;
116-
117115
this.mYMax = -Infinity;
118116
this.mYMin = Infinity;
119117
this.mXMax = -Infinity;
120118
this.mXMin = Infinity;
121119

122-
const visibleDatasets = this.visibleDataSets;
123-
124-
for (const set of visibleDatasets) {
125-
if (set.visible) {
126-
this.calcMinMaxForDataSet(set);
127-
}
128-
}
129-
130120
this.mLeftAxisMax = -Infinity;
131121
this.mLeftAxisMin = Infinity;
132122
this.mRightAxisMax = -Infinity;
133123
this.mRightAxisMin = Infinity;
124+
if (!this.mDataSets || this.mDataSets.length === 0) return;
134125

135-
// left axis
136-
const firstLeft = this.getFirstLeft(visibleDatasets);
137-
138-
if (firstLeft) {
139-
this.mLeftAxisMax = firstLeft.yMax;
140-
this.mLeftAxisMin = firstLeft.yMin;
141-
142-
for (const dataSet of visibleDatasets) {
143-
if (dataSet.axisDependency === AxisDependency.LEFT) {
144-
if (dataSet.yMin < this.mLeftAxisMin) this.mLeftAxisMin = dataSet.yMin;
126+
const visibleDatasets = this.visibleDataSets;
145127

146-
if (dataSet.yMax > this.mLeftAxisMax) this.mLeftAxisMax = dataSet.yMax;
147-
}
148-
}
128+
for (const set of visibleDatasets) {
129+
this.calcMinMaxForDataSet(set);
149130
}
150131

151-
// right axis
152-
const firstRight = this.getFirstRight(visibleDatasets);
153-
154-
if (firstRight) {
155-
this.mRightAxisMax = firstRight.yMax;
156-
this.mRightAxisMin = firstRight.yMin;
157-
158-
for (const dataSet of visibleDatasets) {
159-
if (dataSet.axisDependency === AxisDependency.RIGHT) {
160-
if (dataSet.yMin < this.mRightAxisMin) this.mRightAxisMin = dataSet.yMin;
161-
162-
if (dataSet.yMax > this.mRightAxisMax) this.mRightAxisMax = dataSet.yMax;
163-
}
164-
}
165-
}
132+
// this.mLeftAxisMax = -Infinity;
133+
// this.mLeftAxisMin = Infinity;
134+
// this.mRightAxisMax = -Infinity;
135+
// this.mRightAxisMin = Infinity;
136+
// for (let i = 0; i < visibleDatasets.length; i++) {
137+
// const set = visibleDatasets[i];
138+
// if (set.axisDependency === AxisDependency.RIGHT) {
139+
// this.mRightAxisMin = Math.min(this.mRightAxisMin, set.yMin);
140+
// this.mRightAxisMax = Math.min(this.mRightAxisMax, set.yMax);
141+
// } else {
142+
// this.mLeftAxisMin = Math.min(this.mLeftAxisMin, set.yMin);
143+
// this.mLeftAxisMax = Math.min(this.mLeftAxisMax, set.yMax);
144+
// }
145+
// }
166146
}
167147

168148
/** ONLY GETTERS AND SETTERS BELOW THIS */
@@ -426,22 +406,19 @@ export abstract class ChartData<U extends Entry, T extends IDataSet<U>> {
426406
* @param axis
427407
*/
428408
protected calcMinMaxForEntry(set: IDataSet<Entry>, e: Entry, entryIndex: number, axis: AxisDependency) {
429-
const xKey = set.xProperty;
430-
const yKey = set.yProperty;
431409
const xValue = set.getEntryXValue(e, entryIndex);
432-
const yValue = e[yKey];
433-
if (this.mYMax < yValue) this.mYMax = yValue;
434-
if (this.mYMin > yValue) this.mYMin = yValue;
435-
436-
if (this.mXMax < xValue) this.mXMax = xValue;
437-
if (this.mXMin > xValue) this.mXMin = xValue;
410+
const yValue = e[set.yProperty];
411+
this.mYMin = Math.min(this.mYMin, yValue);
412+
this.mYMax = Math.max(this.mYMax, yValue);
413+
this.mXMin = Math.min(this.mXMin, xValue);
414+
this.mXMax = Math.max(this.mXMax, xValue);
438415

439416
if (axis === AxisDependency.LEFT) {
440-
if (this.mLeftAxisMax < yValue) this.mLeftAxisMax = yValue;
441-
if (this.mLeftAxisMin > yValue) this.mLeftAxisMin = yValue;
417+
this.mLeftAxisMin = Math.min(this.mLeftAxisMin, yValue);
418+
this.mLeftAxisMax = Math.max(this.mLeftAxisMax, yValue);
442419
} else {
443-
if (this.mRightAxisMax < yValue) this.mRightAxisMax = yValue;
444-
if (this.mRightAxisMin > yValue) this.mRightAxisMin = yValue;
420+
this.mRightAxisMin = Math.min(this.mRightAxisMin, yValue);
421+
this.mRightAxisMax = Math.max(this.mRightAxisMax, yValue);
445422
}
446423
}
447424

@@ -451,18 +428,17 @@ export abstract class ChartData<U extends Entry, T extends IDataSet<U>> {
451428
* @param d
452429
*/
453430
protected calcMinMaxForDataSet(d: T) {
454-
if (this.mYMax < d.yMax) this.mYMax = d.yMax;
455-
if (this.mYMin > d.yMin) this.mYMin = d.yMin;
456-
457-
if (this.mXMax < d.xMax) this.mXMax = d.xMax;
458-
if (this.mXMin > d.xMin) this.mXMin = d.xMin;
431+
this.mXMin = Math.min(this.mXMin, d.xMin);
432+
this.mXMax = Math.max(this.mXMax, d.xMax);
433+
this.mYMin = Math.min(this.mYMin, d.yMin);
434+
this.mYMax = Math.max(this.mYMax, d.yMax);
459435

460436
if (d.axisDependency === AxisDependency.LEFT) {
461-
if (this.mLeftAxisMax < d.yMax) this.mLeftAxisMax = d.yMax;
462-
if (this.mLeftAxisMin > d.yMin) this.mLeftAxisMin = d.yMin;
437+
this.mLeftAxisMin = Math.min(this.mLeftAxisMin, d.yMin);
438+
this.mLeftAxisMax = Math.max(this.mLeftAxisMax, d.yMax);
463439
} else {
464-
if (this.mRightAxisMax < d.yMax) this.mRightAxisMax = d.yMax;
465-
if (this.mRightAxisMin > d.yMin) this.mRightAxisMin = d.yMin;
440+
this.mRightAxisMin = Math.min(this.mRightAxisMin, d.yMin);
441+
this.mRightAxisMax = Math.max(this.mRightAxisMax, d.yMax);
466442
}
467443
}
468444

src/ui-chart/data/CombinedData.ts

+20-35
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ export class CombinedData extends BarLineScatterCandleBubbleData<Entry, BarLineS
3939
}
4040

4141
public calcMinMax() {
42-
if (!this.mDataSets) {
43-
this.mDataSets = [];
44-
}
4542
this.mDataSets = [];
4643

4744
this.mYMax = -Infinity;
@@ -55,31 +52,19 @@ export class CombinedData extends BarLineScatterCandleBubbleData<Entry, BarLineS
5552
this.mRightAxisMin = Infinity;
5653

5754
const allData = this.datasArray;
58-
// for (let index = 0; index < allData.length; index++) {
59-
// const element = array[index];
60-
61-
// }
62-
for (const data of allData) {
55+
for (let index = 0; index < allData.length; index++) {
56+
const data = allData[index];
57+
this.mDataSets.push(...data.dataSets);
6358
data.calcMinMax();
64-
65-
const sets = data.dataSets;
66-
this.mDataSets.push(...sets);
67-
68-
if (data.yMax > this.mYMax) this.mYMax = data.yMax;
69-
70-
if (data.yMin < this.mYMin) this.mYMin = data.yMin;
71-
72-
if (data.xMax > this.mXMax) this.mXMax = data.xMax;
73-
74-
if (data.xMin < this.mXMin) this.mXMin = data.xMin;
75-
76-
if (data.mLeftAxisMax > this.mLeftAxisMax) this.mLeftAxisMax = data.mLeftAxisMax;
77-
78-
if (data.mLeftAxisMin < this.mLeftAxisMin) this.mLeftAxisMin = data.mLeftAxisMin;
79-
80-
if (data.mRightAxisMax > this.mRightAxisMax) this.mRightAxisMax = data.mRightAxisMax;
81-
82-
if (data.mRightAxisMin < this.mRightAxisMin) this.mRightAxisMin = data.mRightAxisMin;
59+
this.mXMin = Math.min(this.mXMin, data.xMin);
60+
this.mXMax = Math.max(this.mXMax, data.xMax);
61+
this.mYMin = Math.min(this.mYMin, data.yMin);
62+
this.mYMax = Math.max(this.mYMax, data.yMax);
63+
64+
this.mLeftAxisMin = Math.min(this.mLeftAxisMin, data.mLeftAxisMin);
65+
this.mLeftAxisMax = Math.max(this.mLeftAxisMax, data.mLeftAxisMax);
66+
this.mRightAxisMin = Math.min(this.mRightAxisMin, data.mRightAxisMin);
67+
this.mRightAxisMax = Math.max(this.mRightAxisMax, data.mRightAxisMax);
8368
}
8469
}
8570

@@ -98,18 +83,18 @@ export class CombinedData extends BarLineScatterCandleBubbleData<Entry, BarLineS
9883
public get datas() {
9984
return { lineData: this.lineData, barData: this.barData, scatterData: this.scatterData, candleData: this.candleData, bubbleData: this.bubbleData };
10085
}
101-
102-
public getDataByIndex(index) {
86+
// get dataSetCount() {
87+
// return this.datasArray.reduce((acc, data) => acc + data.dataSetCount, 0);
88+
// }
89+
// get dataSets() {
90+
// return this.datasArray.reduce((acc, data) => acc.concat(data.dataSets), []);
91+
// }
92+
getDataByIndex(index) {
10393
return this.datasArray[index];
10494
}
10595

10696
public notifyDataChanged() {
107-
if (this.lineData) this.lineData.notifyDataChanged();
108-
if (this.barData) this.barData.notifyDataChanged();
109-
if (this.candleData) this.candleData.notifyDataChanged();
110-
if (this.scatterData) this.scatterData.notifyDataChanged();
111-
if (this.bubbleData) this.bubbleData.notifyDataChanged();
112-
97+
this.datasArray.forEach((d) => d.notifyDataChanged());
11398
this.calcMinMax(); // recalculate everything
11499
}
115100

src/ui-chart/data/DataSet.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -142,17 +142,15 @@ export abstract class DataSet<T extends Entry> extends BaseDataSet<T> {
142142
}
143143
} else {
144144
const x = this.getEntryXValue(e, index);
145-
if (x < this.mXMin) this.mXMin = x;
146-
147-
if (x > this.mXMax) this.mXMax = x;
145+
this.mXMin = Math.min(x, this.mXMin);
146+
this.mXMax = Math.max(x, this.mXMax);
148147
}
149148
}
150149

151150
protected calcMinMaxY(e: T, index?: number) {
152151
const y = e[this.yProperty] || 0;
153-
if (y < this.mYMin) this.mYMin = y;
154-
155-
if (y > this.mYMax) this.mYMax = y;
152+
this.mYMin = Math.min(y, this.mYMin);
153+
this.mYMax = Math.max(y, this.mYMax);
156154
}
157155

158156
protected getInternalValues() {

src/ui-chart/listener/BarLineChartTouchListener.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ export class BarLineChartTouchListener extends ChartTouchListener<BarLineChartBa
601601
if (!hasListener && !isHighlightPerTapEnabled) {
602602
return;
603603
}
604-
this.handleTouchHighlight(event, !isHighlightPerTapEnabled, false, hasListener ? 'tap' : undefined);
604+
this.handleTouchHighlight(event, isHighlightPerTapEnabled, false, hasListener ? 'tap' : undefined);
605605
// const h = chart.getHighlightByTouchPoint(event.data.extraData.x, event.data.extraData.y);
606606
// if (hasListener) {
607607
// chart.notify({ eventName: 'tap', data: event.data, object: chart, highlight: h });

src/ui-chart/renderer/AxisRenderer.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,9 @@ export abstract class AxisRenderer extends Renderer {
117117
inverted = axis['isInverted'] ? axis['isInverted']() : false;
118118
}
119119
}
120-
if (this.mViewPortHandler && this.mViewPortHandler.contentRect.width() > 10 && !this.mViewPortHandler.isFullyZoomedOutY()) {
121-
const rect = this.mAxis.ignoreOffsets ? this.mViewPortHandler.chartRect : this.mViewPortHandler.contentRect;
120+
const viewPortHandler = this.mViewPortHandler;
121+
if (viewPortHandler?.contentRect.width() > 10 && !viewPortHandler.isFullyZoomedOutY()) {
122+
const rect = this.mAxis.ignoreOffsets ? viewPortHandler.chartRect : viewPortHandler.contentRect;
122123
const p1 = this.transformer.getValuesByTouchPoint(rect.left, rect.top);
123124
const p2 = this.transformer.getValuesByTouchPoint(rect.left, rect.bottom);
124125

src/ui-chart/renderer/BarChartRenderer.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export class BarChartRenderer extends BarLineScatterCandleBubbleRenderer {
144144

145145
trans.pointValuesToPixel(buffer.buffer);
146146

147-
const isSingleColor = dataSet.colors.length === 1;
147+
const isSingleColor = !dataSet.colors || dataSet.colors.length === 1;
148148
// const isInverted = chart.isInverted(dataSet.axisDependency);
149149
const renderPaint = this.renderPaint;
150150
const previousShader = renderPaint.getShader();
@@ -471,7 +471,7 @@ export class BarChartRenderer extends BarLineScatterCandleBubbleRenderer {
471471
const x = set.getEntryXValue(entry, index);
472472
this.prepareBarHighlight(x, y1, y2, barData.barWidth / 2, trans, barRect);
473473

474-
// this.setHighlightDrawPos(high, barRect);
474+
this.setHighlightDrawPos(high, barRect);
475475
const customRender = this.mChart.customRenderer;
476476
if (customRender && customRender.drawHighlight) {
477477
const rect = barRect;

src/ui-chart/renderer/CandleStickChartRenderer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ export class CandleStickChartRenderer extends LineScatterCandleRadarRenderer {
312312
if (customRender && customRender.drawHighlight) {
313313
customRender.drawHighlight(c, high, set, paint);
314314
} else {
315-
this.drawHighlightLines(c, high.xPx, high.yPx, set);
315+
this.drawHighlightLines(c, high.drawX, high.drawY, set);
316316
}
317317
}
318318
}

src/ui-chart/renderer/HorizontalBarChartRenderer.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export class HorizontalBarChartRenderer extends BarChartRenderer {
8989

9090
trans.pointValuesToPixel(buffer.buffer);
9191

92-
const isSingleColor = dataSet.colors.length === 1;
92+
const isSingleColor = !dataSet.colors || dataSet.colors.length === 1;
9393
const renderPaint = this.renderPaint;
9494
const previousShader = renderPaint.getShader();
9595
const shader = dataSet.fillShader;
@@ -396,10 +396,10 @@ export class HorizontalBarChartRenderer extends BarChartRenderer {
396396
* @param high
397397
* @param bar
398398
*/
399-
// protected setHighlightDrawPos(high: Highlight, bar: RectF) {
400-
// high.drawX = bar.centerY();
401-
// high.drawY = bar.right;
402-
// }
399+
protected setHighlightDrawPos(high: Highlight, bar: RectF) {
400+
high.drawX = bar.centerY();
401+
high.drawY = bar.right;
402+
}
403403

404404
protected isDrawingValuesAllowed(chart: ChartInterface) {
405405
return chart.data.entryCount < chart.maxVisibleValueCount * this.mViewPortHandler.getScaleY();

0 commit comments

Comments
 (0)