Skip to content

Commit 5cb3c01

Browse files
committed
fix: dont calcuate min/max for hidden sets
1 parent f92c167 commit 5cb3c01

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

src/charting/data/ChartData.ts

+18-11
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,12 @@ export abstract class ChartData<U extends Entry, T extends IDataSet<U>> {
117117
this.mXMax = -Number.MAX_VALUE;
118118
this.mXMin = Number.MAX_VALUE;
119119

120-
for (let set of this.mDataSets) {
121-
this.calcMinMaxForDataSet(set);
120+
const visibleDatasets = this.mDataSets.filter(s => s.isVisible());
121+
122+
for (let set of visibleDatasets) {
123+
if (set.isVisible()) {
124+
this.calcMinMaxForDataSet(set);
125+
}
122126
}
123127

124128
this.mLeftAxisMax = -Number.MAX_VALUE;
@@ -127,13 +131,13 @@ export abstract class ChartData<U extends Entry, T extends IDataSet<U>> {
127131
this.mRightAxisMin = Number.MAX_VALUE;
128132

129133
// left axis
130-
const firstLeft = this.getFirstLeft(this.mDataSets);
134+
const firstLeft = this.getFirstLeft(visibleDatasets);
131135

132136
if (firstLeft != null) {
133137
this.mLeftAxisMax = firstLeft.getYMax();
134138
this.mLeftAxisMin = firstLeft.getYMin();
135139

136-
for (let dataSet of this.mDataSets) {
140+
for (let dataSet of visibleDatasets) {
137141
if (dataSet.getAxisDependency() == AxisDependency.LEFT) {
138142
if (dataSet.getYMin() < this.mLeftAxisMin) this.mLeftAxisMin = dataSet.getYMin();
139143

@@ -143,13 +147,13 @@ export abstract class ChartData<U extends Entry, T extends IDataSet<U>> {
143147
}
144148

145149
// right axis
146-
const firstRight = this.getFirstRight(this.mDataSets);
150+
const firstRight = this.getFirstRight(visibleDatasets);
147151

148152
if (firstRight != null) {
149153
this.mRightAxisMax = firstRight.getYMax();
150154
this.mRightAxisMin = firstRight.getYMin();
151155

152-
for (let dataSet of this.mDataSets) {
156+
for (let dataSet of visibleDatasets) {
153157
if (dataSet.getAxisDependency() == AxisDependency.RIGHT) {
154158
if (dataSet.getYMin() < this.mRightAxisMin) this.mRightAxisMin = dataSet.getYMin();
155159

@@ -308,7 +312,7 @@ export abstract class ChartData<U extends Entry, T extends IDataSet<U>> {
308312
else return this.mDataSets[index];
309313
}
310314

311-
public getDataSetByIndex(index:number) {
315+
public getDataSetByIndex(index: number) {
312316
if (this.mDataSets == null || index < 0 || index >= this.mDataSets.length) return null;
313317

314318
return this.mDataSets[index];
@@ -321,8 +325,9 @@ export abstract class ChartData<U extends Entry, T extends IDataSet<U>> {
321325
*/
322326
public addDataSet(d: T) {
323327
if (d == null) return;
324-
325-
this.calcMinMaxForDataSet(d);
328+
if (d.isVisible()) {
329+
this.calcMinMaxForDataSet(d);
330+
}
326331

327332
this.mDataSets.push(d);
328333
}
@@ -376,7 +381,9 @@ export abstract class ChartData<U extends Entry, T extends IDataSet<U>> {
376381
// add the entry to the dataset
377382
if (!set.addEntry(e)) return;
378383

379-
this.calcMinMaxForEntry(set, e, set.getAxisDependency());
384+
if (set.isVisible()) {
385+
this.calcMinMaxForEntry(set, e, set.getAxisDependency());
386+
}
380387
} else {
381388
console.error('addEntry', 'Cannot add Entry because dataSetIndex too high or too low.');
382389
}
@@ -388,7 +395,7 @@ export abstract class ChartData<U extends Entry, T extends IDataSet<U>> {
388395
* @param e
389396
* @param axis
390397
*/
391-
protected calcMinMaxForEntry(set:IDataSet<Entry>, e: Entry, axis) {
398+
protected calcMinMaxForEntry(set: IDataSet<Entry>, e: Entry, axis) {
392399
const xProperty = set.xProperty;
393400
const yProperty = set.yProperty;
394401
if (this.mYMax < e[yProperty]) this.mYMax = e[yProperty];

src/charting/listener/BarLineChartTouchListener.ts

-1
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,6 @@ export class BarLineChartTouchListener extends ChartTouchListener<BarLineChartBa
614614
if (event.data.state === GestureState.END && event.data.prevState === GestureState.ACTIVE) {
615615
this.mLastGesture = ChartGesture.SINGLE_TAP;
616616
const chart = this.mChart;
617-
console.log('onTapGesture', chart.isHighlightPerTapEnabled(), event.data.extraData.x, event.data.extraData.y, event.data.extraData);
618617

619618
// OnChartGestureListener l = this.mChart.getOnChartGestureListener();
620619
const h = chart.getHighlightByTouchPoint(event.data.extraData.x, event.data.extraData.y);

0 commit comments

Comments
 (0)