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

2
package-lock.json generated

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

2
package.json

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

18
src/index.ts

@ -938,7 +938,7 @@ abstract class ChartwerkPod<T extends TimeSerie, O extends Options> {
this.series
.filter(serie => serie.visible !== false && this.filterSerieByYAxisOrientation(serie, yAxisOrientation.LEFT))
.map(
serie => minBy<number[]>(serie.datapoints, dp => dp[0])[0]
serie => minBy<number[]>(serie.datapoints, dp => dp[1])[1]
)
);
return minValue;
@ -956,7 +956,7 @@ abstract class ChartwerkPod<T extends TimeSerie, O extends Options> {
this.series
.filter(serie => serie.visible !== false && this.filterSerieByYAxisOrientation(serie, yAxisOrientation.LEFT))
.map(
serie => maxBy<number[]>(serie.datapoints, dp => dp[0])[0]
serie => maxBy<number[]>(serie.datapoints, dp => dp[1])[1]
)
);
return maxValue;
@ -974,7 +974,7 @@ abstract class ChartwerkPod<T extends TimeSerie, O extends Options> {
this.series
.filter(serie => serie.visible !== false && this.filterSerieByYAxisOrientation(serie, yAxisOrientation.RIGHT))
.map(
serie => minBy<number[]>(serie.datapoints, dp => dp[0])[0]
serie => minBy<number[]>(serie.datapoints, dp => dp[1])[1]
)
);
return minValue;
@ -991,7 +991,7 @@ abstract class ChartwerkPod<T extends TimeSerie, O extends Options> {
this.series
.filter(serie => serie.visible !== false && this.filterSerieByYAxisOrientation(serie, yAxisOrientation.RIGHT))
.map(
serie => maxBy<number[]>(serie.datapoints, dp => dp[0])[0]
serie => maxBy<number[]>(serie.datapoints, dp => dp[1])[1]
)
);
return maxValue;
@ -1009,7 +1009,7 @@ abstract class ChartwerkPod<T extends TimeSerie, O extends Options> {
this.series
.filter(serie => serie.visible !== false)
.map(
serie => minBy<number[]>(serie.datapoints, dp => dp[1])[1]
serie => minBy<number[]>(serie.datapoints, dp => dp[0])[0]
)
);
return minValue;
@ -1026,7 +1026,7 @@ abstract class ChartwerkPod<T extends TimeSerie, O extends Options> {
this.series
.filter(serie => serie.visible !== false)
.map(
serie => maxBy<number[]>(serie.datapoints, dp => dp[1])[1]
serie => maxBy<number[]>(serie.datapoints, dp => dp[0])[0]
)
);
return maxValue;
@ -1058,8 +1058,8 @@ abstract class ChartwerkPod<T extends TimeSerie, O extends Options> {
if(this.series.length === 0) {
return undefined;
}
const startTimestamp = first(this.series[0].datapoints)[1];
const endTimestamp = last(this.series[0].datapoints)[1];
const startTimestamp = first(this.series[0].datapoints)[0];
const endTimestamp = last(this.series[0].datapoints)[0];
return (endTimestamp - startTimestamp) / 1000;
}
@ -1095,7 +1095,7 @@ abstract class ChartwerkPod<T extends TimeSerie, O extends Options> {
get timeInterval(): number {
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;
}
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 Timestamp = number;
// TODO: Pods can render not only "time" series
export type TimeSerie = {
target: string,
datapoints: [number, number][],
datapoints: [Timestamp, number][],
alias?: string,
visible?: boolean,
color?: string,

Loading…
Cancel
Save