Browse Source

fix minby / max by

pull/2/head
vargburz 3 years ago
parent
commit
3176f1ee66
  1. 2
      package.json
  2. 56
      src/models/series.ts
  3. 8
      src/models/state.ts

2
package.json

@ -1,6 +1,6 @@
{ {
"name": "@chartwerk/core", "name": "@chartwerk/core",
"version": "0.6.5", "version": "0.6.6",
"description": "Chartwerk core", "description": "Chartwerk core",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",

56
src/models/series.ts

@ -25,6 +25,12 @@ export const CORE_SERIE_DEFAULTS = {
color: undefined, color: undefined,
}; };
export enum Extremum {
MIN = 'min',
MAX = 'max',
}
export class CoreSeries<T extends Serie> { export class CoreSeries<T extends Serie> {
_series: Array<T> = []; _series: Array<T> = [];
@ -99,50 +105,76 @@ export class CoreSeries<T extends Serie> {
return this.visibleSeries.filter(serie => serie.yOrientation = yAxisOrientation.RIGHT); return this.visibleSeries.filter(serie => serie.yOrientation = yAxisOrientation.RIGHT);
} }
get minValueY(): number { get areSeriesForY1Exist(): boolean {
return this.rightYRelatedSeries.length > 0;
}
get areSeriesForYExist(): boolean {
return this.leftYRelatedSeries.length > 0;
}
get minValueY(): number | undefined {
return lodashMin( return lodashMin(
this.leftYRelatedSeries.map( this.leftYRelatedSeries.map(
serie => lodashMinBy<number[]>(serie.datapoints, dp => dp[1])[1] serie => {
const mins = lodashMinBy<number[]>(serie.datapoints, dp => dp[1]);
return !lodashIsNil(mins) ? mins[1] : undefined;
}
) )
); );
} }
get maxValueY(): number { get maxValueY(): number | undefined {
return lodashMax( return lodashMax(
this.leftYRelatedSeries.map( this.leftYRelatedSeries.map(
serie => lodashMaxBy<number[]>(serie.datapoints, dp => dp[1])[1] serie => {
const maxs = lodashMaxBy<number[]>(serie.datapoints, dp => dp[1]);
return !lodashIsNil(maxs) ? maxs[1] : undefined;
}
) )
); );
} }
get minValueX(): number { get minValueX(): number | undefined {
return lodashMin( return lodashMin(
this.visibleSeries.map( this.visibleSeries.map(
serie => lodashMinBy<number[]>(serie.datapoints, dp => dp[0])[0] serie => {
const mins = lodashMinBy<number[]>(serie.datapoints, dp => dp[0]);
return !lodashIsNil(mins) ? mins[0] : undefined;
}
) )
); );
} }
get maxValueX(): number { get maxValueX(): number | undefined {
return lodashMax( return lodashMax(
this.visibleSeries.map( this.visibleSeries.map(
serie => lodashMaxBy<number[]>(serie.datapoints, dp => dp[0])[0] serie => {
const maxs = lodashMaxBy<number[]>(serie.datapoints, dp => dp[0]);
return !lodashIsNil(maxs) ? maxs[0] : undefined;
}
) )
); );
} }
get minValueY1(): number { get minValueY1(): number | undefined {
return lodashMin( return lodashMin(
this.rightYRelatedSeries.map( this.rightYRelatedSeries.map(
serie => lodashMinBy<number[]>(serie.datapoints, dp => dp[1])[1] serie => {
const mins = lodashMinBy<number[]>(serie.datapoints, dp => dp[1]);
return !lodashIsNil(mins) ? mins[1] : undefined;
}
) )
); );
} }
get maxValueY1(): number { get maxValueY1(): number | undefined {
return lodashMax( return lodashMax(
this.rightYRelatedSeries.map( this.rightYRelatedSeries.map(
serie => lodashMaxBy<number[]>(serie.datapoints, dp => dp[1])[1] serie => {
const maxs = lodashMaxBy<number[]>(serie.datapoints, dp => dp[1]);
return !lodashIsNil(maxs) ? maxs[1] : undefined;
}
) )
); );
} }

8
src/models/state.ts

@ -139,7 +139,7 @@ export class PodState<T extends Serie, O extends Options> {
} }
public getMinValueY(): number { public getMinValueY(): number {
if(!this.coreSeries.isSeriesAvailable) { if(!this.coreSeries.areSeriesForYExist) {
return DEFAULT_AXIS_RANGE[0]; return DEFAULT_AXIS_RANGE[0];
} }
if(this.coreOptions.axis.y.range !== undefined) { if(this.coreOptions.axis.y.range !== undefined) {
@ -149,7 +149,7 @@ export class PodState<T extends Serie, O extends Options> {
} }
public getMaxValueY(): number { public getMaxValueY(): number {
if(!this.coreSeries.isSeriesAvailable) { if(!this.coreSeries.areSeriesForYExist) {
return DEFAULT_AXIS_RANGE[1]; return DEFAULT_AXIS_RANGE[1];
} }
if(this.coreOptions.axis.y.range !== undefined) { if(this.coreOptions.axis.y.range !== undefined) {
@ -181,7 +181,7 @@ export class PodState<T extends Serie, O extends Options> {
} }
public getMinValueY1(): number { public getMinValueY1(): number {
if(!this.coreSeries.isSeriesAvailable) { if(!this.coreSeries.areSeriesForY1Exist) {
return DEFAULT_AXIS_RANGE[0]; return DEFAULT_AXIS_RANGE[0];
} }
if(this.coreOptions.axis.y1.range !== undefined) { if(this.coreOptions.axis.y1.range !== undefined) {
@ -191,7 +191,7 @@ export class PodState<T extends Serie, O extends Options> {
} }
public getMaxValueY1(): number { public getMaxValueY1(): number {
if(!this.coreSeries.isSeriesAvailable) { if(!this.coreSeries.areSeriesForY1Exist) {
return DEFAULT_AXIS_RANGE[1]; return DEFAULT_AXIS_RANGE[1];
} }
if(this.coreOptions.axis.y1.range !== undefined) { if(this.coreOptions.axis.y1.range !== undefined) {

Loading…
Cancel
Save