Skip to content

Commit aead8af

Browse files
committed
feat: setSuggestedAxisMinimum and setSuggestedAxisMaximum
1 parent d2e8bdd commit aead8af

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

src/charting/components/AxisBase.ts

+36-1
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,16 @@ export abstract class AxisBase extends ComponentBase {
157157
*/
158158
public mAxisMinimum = 0;
159159

160+
/**
161+
* don't touch this direclty, use setter
162+
*/
163+
public mAxisSuggestedMaximum = undefined;
164+
165+
/**
166+
* don't touch this directly, use setter
167+
*/
168+
public mAxisSuggestedMinimum = undefined;
169+
160170
/**
161171
* the total range of values this axis covers
162172
*/
@@ -714,6 +724,26 @@ export abstract class AxisBase extends ComponentBase {
714724
this.mAxisRange = Math.abs(this.mAxisMaximum - min);
715725
}
716726

727+
/**
728+
* Set a suggested minimum value for this axis. If set, this will be used
729+
* as minimum is no value is smaller than it.
730+
*
731+
* @param min
732+
*/
733+
public setSuggestedAxisMinimum(min) {
734+
this.mAxisSuggestedMinimum = min;
735+
}
736+
737+
/**
738+
* Set a suggested maximum value for this axis. If set, this will be used
739+
* as maximum is no value is greater than it.
740+
*
741+
* @param min
742+
*/
743+
public setSuggestedAxisMaximum(max) {
744+
this.mAxisSuggestedMaximum = max;
745+
}
746+
717747
/**
718748
* Use setAxisMinimum(...) instead.
719749
*
@@ -758,7 +788,12 @@ export abstract class AxisBase extends ComponentBase {
758788
// if custom, use value as is, else use data value
759789
let min = this.mCustomAxisMin ? this.mAxisMinimum : dataMin - this.mSpaceMin;
760790
let max = this.mCustomAxisMax ? this.mAxisMaximum : dataMax + this.mSpaceMax;
761-
791+
if (this.mAxisSuggestedMinimum !== undefined) {
792+
min = Math.min(min, this.mAxisSuggestedMinimum);
793+
}
794+
if (this.mAxisSuggestedMaximum !== undefined) {
795+
max = Math.max(max, this.mAxisSuggestedMaximum);
796+
}
762797
// temporary range (before calculations)
763798
const range = Math.abs(max - min);
764799

0 commit comments

Comments
 (0)