Browse Source

Merge branch 'better-is-series-available' into 'main'

isSeriesAvailable: check for datapoints emptiness

See merge request chartwerk/core!22
merge-requests/22/merge
rozetko 2 years ago
parent
commit
9fda8a4405
  1. 2
      package.json
  2. 21
      src/models/series.ts

2
package.json

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

21
src/models/series.ts

@ -9,6 +9,8 @@ import lodashMin from 'lodash/min';
import lodashMinBy from 'lodash/minBy';
import lodashMax from 'lodash/max';
import lodashMaxBy from 'lodash/maxBy';
import lodashIsNil from 'lodash/isNil';
import lodashIncludes from 'lodash/includes';
const SERIE_DEFAULTS = {
@ -61,8 +63,25 @@ export class CoreSeries<T extends Serie> {
return this._coreDefaults;
}
private _isSerieEmpty(serie: T): boolean {
if(serie.datapoints.length > 0) {
for(const datapoint of serie.datapoints) {
// TODO: axis-related
if(!lodashIsNil(datapoint[1])) {
return false;
}
}
}
return true;
}
get isSeriesAvailable(): boolean {
return this.visibleSeries.length > 0;
if(this.visibleSeries.length > 0) {
const seriesEmptiness = lodashMap(this.visibleSeries, this._isSerieEmpty.bind(this));
return lodashIncludes(seriesEmptiness, false);
}
return false;
}
get visibleSeries(): Array<T> {

Loading…
Cancel
Save