Skip to content

Commit 7eec038

Browse files
committed
fix: refactor to expose getCurrentMinMax
1 parent 0e2632e commit 7eec038

File tree

2 files changed

+43
-16
lines changed

2 files changed

+43
-16
lines changed

src/charting/renderer/AxisRenderer.ts

+29-11
Original file line numberDiff line numberDiff line change
@@ -118,16 +118,19 @@ export abstract class AxisRenderer extends Renderer {
118118
return this.mTrans;
119119
}
120120

121-
/**
122-
* Computes the axis values.
123-
*
124-
* @param min - the minimum value in the data object for this axis
125-
* @param max - the maximum value in the data object for this axis
126-
*/
127-
@profile
128-
public computeAxis(min, max, inverted) {
129-
// calculate the starting and entry polet of the y-labels (depending on
130-
// zoom / contentrect bounds)
121+
public getCurrentMinMax(min?, max?, inverted?) {
122+
if (min === undefined || max === undefined || inverted === undefined) {
123+
const axis = this.mAxis;
124+
if (min === undefined) {
125+
min = axis.mAxisMinimum;
126+
}
127+
if (max === undefined) {
128+
max = axis.mAxisMaximum;
129+
}
130+
if (inverted === undefined) {
131+
inverted = axis['isInverted'] ? axis['isInverted']() : false;
132+
}
133+
}
131134
if (this.mViewPortHandler != null && this.mViewPortHandler.getContentRect().width() > 10 && !this.mViewPortHandler.isFullyZoomedOutY()) {
132135
const rect = this.mAxis.isIgnoringOffsets() ? this.mViewPortHandler.getChartRect() : this.mViewPortHandler.getContentRect();
133136
const p1 = this.mTrans.getValuesByTouchPoint(rect.left, rect.top);
@@ -141,7 +144,22 @@ export abstract class AxisRenderer extends Renderer {
141144
max = p2.y;
142145
}
143146
}
144-
this.computeAxisValues(min, max);
147+
return { min, max };
148+
}
149+
150+
/**
151+
* Computes the axis values.
152+
*
153+
* @param min - the minimum value in the data object for this axis
154+
* @param max - the maximum value in the data object for this axis
155+
*/
156+
@profile
157+
public computeAxis(min, max, inverted) {
158+
// calculate the starting and entry polet of the y-labels (depending on
159+
// zoom / contentrect bounds)
160+
161+
const result = this.getCurrentMinMax(min, max, inverted);
162+
this.computeAxisValues(result.min, result.max);
145163
}
146164

147165
/**

src/charting/renderer/XAxisRenderer.ts

+14-5
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,19 @@ export class XAxisRenderer extends AxisRenderer {
2525
return paint;
2626
}
2727

28-
public computeAxis(min, max, inverted) {
29-
// calculate the starting and entry polet of the y-labels (depending on
30-
// zoom / contentrect bounds)
28+
public getCurrentMinMax(min?, max?, inverted?) {
29+
if (min === undefined || max === undefined || inverted === undefined) {
30+
const axis = this.mAxis;
31+
if (min === undefined) {
32+
min = axis.mAxisMinimum;
33+
}
34+
if (max === undefined) {
35+
max = axis.mAxisMaximum;
36+
}
37+
if (inverted === undefined) {
38+
inverted = axis['isInverted'] ? axis['isInverted']() : false;
39+
}
40+
}
3141
const rect = this.mAxis.isIgnoringOffsets() ? this.mViewPortHandler.getChartRect() : this.mViewPortHandler.getContentRect();
3242
if (rect.width() > 10 && !this.mViewPortHandler.isFullyZoomedOutX()) {
3343
const p1 = this.mTrans.getValuesByTouchPoint(rect.left, rect.top);
@@ -41,8 +51,7 @@ export class XAxisRenderer extends AxisRenderer {
4151
max = p2.x;
4252
}
4353
}
44-
45-
this.computeAxisValues(min, max);
54+
return { min, max };
4655
}
4756

4857
protected computeAxisValues(min, max) {

0 commit comments

Comments
 (0)