Browse Source

Merge branch 'time-value-order-in-timeserie-#3' into 'main'

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

Closes #3

See merge request chartwerk/core!5
merge-requests/4/merge
Alexander Velikiy 3 years ago
parent
commit
30c3460a15
  1. 4
      CHANGELOG.md
  2. 2
      dist/index.js
  3. 25
      dist/types.d.ts
  4. 2
      package-lock.json
  5. 2
      package.json
  6. 18
      src/index.ts
  7. 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
dist/index.js vendored

File diff suppressed because one or more lines are too long

25
dist/types.d.ts vendored

@ -4,9 +4,10 @@ export declare type Margin = {
bottom: number; bottom: number;
left: number; left: number;
}; };
export declare type Timestamp = number;
export declare type TimeSerie = { export declare type TimeSerie = {
target: string; target: string;
datapoints: [number, number][]; datapoints: [Timestamp, number][];
alias?: string; alias?: string;
visible?: boolean; visible?: boolean;
color?: string; color?: string;
@ -16,23 +17,23 @@ export declare type Options = {
margin?: Margin; margin?: Margin;
confidence?: number; confidence?: number;
eventsCallbacks?: { eventsCallbacks?: {
zoomIn: (range: AxisRange[]) => void; zoomIn?: (range: AxisRange[]) => void;
panning: (event: { panning?: (event: {
ranges: AxisRange[]; ranges: AxisRange[];
d3Event: any; d3Event: any;
}) => void; }) => void;
panningEnd: (range: AxisRange[]) => void; panningEnd?: (range: AxisRange[]) => void;
zoomOut: (centers: { zoomOut?: (centers: {
x: number; x: number;
y: number; y: number;
}) => void; }) => void;
mouseMove: (evt: any) => void; mouseMove?: (evt: any) => void;
mouseOut: () => void; mouseOut?: () => void;
onLegendClick: (idx: number) => void; onLegendClick?: (idx: number) => void;
onLegendLabelClick: (idx: number) => void; onLegendLabelClick?: (idx: number) => void;
contextMenu: (evt: any) => void; contextMenu?: (evt: any) => void;
sharedCrosshairMove: (event: any) => void; sharedCrosshairMove?: (event: any) => void;
renderEnd: () => void; renderEnd?: () => void;
}; };
axis?: { axis?: {
x?: AxisOption; x?: AxisOption;

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