Browse Source

time/value order in TimeSerie.datapoints; Timestamp type; version 0.2.0

merge-requests/5/head
Alexey Velikiy 3 years ago
parent
commit
5f62655067
  1. 4
      CHANGELOG.md
  2. 2
      package-lock.json
  3. 2
      package.json
  4. 18
      src/index.ts
  5. 4
      src/types.ts

4
CHANGELOG.md

@ -0,0 +1,4 @@
# Changelog
## 0.2.0
* Change order of time\value in `TimeSerie` : now it's `[time, value][]` instead of `[value, time][]`

2
package-lock.json generated

@ -1,6 +1,6 @@
{ {
"name": "@chartwerk/core", "name": "@chartwerk/core",
"version": "0.1.0", "version": "0.1.1",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

2
package.json

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

18
src/index.ts

@ -938,7 +938,7 @@ abstract class ChartwerkPod<T extends TimeSerie, O extends Options> {
this.series this.series
.filter(serie => serie.visible !== false && this.filterSerieByYAxisOrientation(serie, yAxisOrientation.LEFT)) .filter(serie => serie.visible !== false && this.filterSerieByYAxisOrientation(serie, yAxisOrientation.LEFT))
.map( .map(
serie => minBy<number[]>(serie.datapoints, dp => dp[0])[0] serie => minBy<number[]>(serie.datapoints, dp => dp[1])[1]
) )
); );
return minValue; return minValue;
@ -956,7 +956,7 @@ abstract class ChartwerkPod<T extends TimeSerie, O extends Options> {
this.series this.series
.filter(serie => serie.visible !== false && this.filterSerieByYAxisOrientation(serie, yAxisOrientation.LEFT)) .filter(serie => serie.visible !== false && this.filterSerieByYAxisOrientation(serie, yAxisOrientation.LEFT))
.map( .map(
serie => maxBy<number[]>(serie.datapoints, dp => dp[0])[0] serie => maxBy<number[]>(serie.datapoints, dp => dp[1])[1]
) )
); );
return maxValue; return maxValue;
@ -974,7 +974,7 @@ abstract class ChartwerkPod<T extends TimeSerie, O extends Options> {
this.series this.series
.filter(serie => serie.visible !== false && this.filterSerieByYAxisOrientation(serie, yAxisOrientation.RIGHT)) .filter(serie => serie.visible !== false && this.filterSerieByYAxisOrientation(serie, yAxisOrientation.RIGHT))
.map( .map(
serie => minBy<number[]>(serie.datapoints, dp => dp[0])[0] serie => minBy<number[]>(serie.datapoints, dp => dp[1])[1]
) )
); );
return minValue; return minValue;
@ -991,7 +991,7 @@ abstract class ChartwerkPod<T extends TimeSerie, O extends Options> {
this.series this.series
.filter(serie => serie.visible !== false && this.filterSerieByYAxisOrientation(serie, yAxisOrientation.RIGHT)) .filter(serie => serie.visible !== false && this.filterSerieByYAxisOrientation(serie, yAxisOrientation.RIGHT))
.map( .map(
serie => maxBy<number[]>(serie.datapoints, dp => dp[0])[0] serie => maxBy<number[]>(serie.datapoints, dp => dp[1])[1]
) )
); );
return maxValue; return maxValue;
@ -1009,7 +1009,7 @@ abstract class ChartwerkPod<T extends TimeSerie, O extends Options> {
this.series this.series
.filter(serie => serie.visible !== false) .filter(serie => serie.visible !== false)
.map( .map(
serie => minBy<number[]>(serie.datapoints, dp => dp[1])[1] serie => minBy<number[]>(serie.datapoints, dp => dp[0])[0]
) )
); );
return minValue; return minValue;
@ -1026,7 +1026,7 @@ abstract class ChartwerkPod<T extends TimeSerie, O extends Options> {
this.series this.series
.filter(serie => serie.visible !== false) .filter(serie => serie.visible !== false)
.map( .map(
serie => maxBy<number[]>(serie.datapoints, dp => dp[1])[1] serie => maxBy<number[]>(serie.datapoints, dp => dp[0])[0]
) )
); );
return maxValue; return maxValue;
@ -1058,8 +1058,8 @@ abstract class ChartwerkPod<T extends TimeSerie, O extends Options> {
if(this.series.length === 0) { if(this.series.length === 0) {
return undefined; return undefined;
} }
const startTimestamp = first(this.series[0].datapoints)[1]; const startTimestamp = first(this.series[0].datapoints)[0];
const endTimestamp = last(this.series[0].datapoints)[1]; const endTimestamp = last(this.series[0].datapoints)[0];
return (endTimestamp - startTimestamp) / 1000; return (endTimestamp - startTimestamp) / 1000;
} }
@ -1095,7 +1095,7 @@ abstract class ChartwerkPod<T extends TimeSerie, O extends Options> {
get timeInterval(): number { get timeInterval(): number {
if(this.series !== undefined && this.series.length > 0 && this.series[0].datapoints.length > 1) { if(this.series !== undefined && this.series.length > 0 && this.series[0].datapoints.length > 1) {
const interval = this.series[0].datapoints[1][1] - this.series[0].datapoints[0][1]; const interval = this.series[0].datapoints[1][0] - this.series[0].datapoints[0][0];
return interval; return interval;
} }
if(this.options.timeInterval !== undefined && this.options.timeInterval.count !== undefined) { if(this.options.timeInterval !== undefined && this.options.timeInterval.count !== undefined) {

4
src/types.ts

@ -1,8 +1,10 @@
export type Margin = { top: number, right: number, bottom: number, left: number }; export type Margin = { top: number, right: number, bottom: number, left: number };
export type Timestamp = number;
// TODO: Pods can render not only "time" series // TODO: Pods can render not only "time" series
export type TimeSerie = { export type TimeSerie = {
target: string, target: string,
datapoints: [number, number][], datapoints: [Timestamp, number][],
alias?: string, alias?: string,
visible?: boolean, visible?: boolean,
color?: string, color?: string,

Loading…
Cancel
Save