feat: use timestamp to put values in buckets

- fix rendering for spreaded values
- fix legend for spectrum and opacity
This commit is contained in:
Ivan Mikheykin
2020-03-04 17:17:05 +03:00
parent a3f1495680
commit 9463913189
30 changed files with 1448 additions and 596 deletions
+91 -41
View File
@@ -1,46 +1,96 @@
// A holder of a group of values
class Bucket {
// uniq id
id: number = 0;
// Array of values in this bucket
values: any[] = [];
columns: any[] = []; // From pr/86
// a bucket has multiple values
multipleValues: boolean = false;
// a bucket has values that has no mapped color
noColorDefined: boolean = false;
// y label
y: string = "";
yLabel: string = "";
// This value can be used to calculate a x coordinate on a graph
x: number = 0;
xid: number = 0;
// a time range of this bucket
from: number = 0;
to: number = 0;
// to and from relative to real "from"
relFrom: number = 0;
relTo: number = 0;
mostRecent: boolean = false;
// A holder of values
class Card {
// uniq
id: number = 0;
// Array of values in this bucket
values: any[] = [];
columns: any[] = [];
// card has multiple values
multipleValues: boolean = false;
// card has values that has no color
noColorDefined: boolean = false;
//
y: string = "";
//
x: number = 0;
//
minValue: number = 0;
maxValue: number = 0;
value: number = 0;
constructor() {
// Saved minimum and maximum of values in this bucket
minValue: number = 0;
maxValue: number = 0;
// A value if multiple values is not allowed
value: number = 0;
}
}
class CardsStorage {
cards: Card[] = [];
xBucketSize: number = 0;
yBucketSize: number = 0;
maxValue: number;
minValue: number;
multipleValues: boolean = false;
noColorDefined: boolean = false;
targets: string[] = [];
targetIndex: any;
constructor() {
this.maxValue = 0;
this.minValue = 0;
}
constructor() {
}
export {CardsStorage, Card};
belong(ts: number): boolean {
return ts >= this.from && ts <= this.to;
}
put(value: any) {
this.values.push(value);
}
done() {
// calculate min, max, value
}
isEmpty(): boolean {
return this.values.length == 0;
}
}
class BucketMatrix {
// buckets for each y label
buckets: {[yLabel: string]: Bucket[]} = {};
maxValue: number = 0;
minValue: number = 0;
multipleValues: boolean = false;
noColorDefined: boolean = false;
// a flag that indicate that buckets has stub values
noDatapoints: boolean = false;
targets: string[] = [];
rangeMs: number = 0;
intervalMs: number = 0;
xBucketSize: number = 0; // TODO remove: a transition from CardsData
constructor() {
}
get(yid: string, xid: number): Bucket {
if (yid in this.buckets) {
if (xid in this.buckets[yid]) {
return this.buckets[yid][xid];
}
}
return new Bucket();
}
hasData(): boolean {
let hasData = false;
if (this.targets.length > 0) {
this.targets.map((target:string) => {
if (this.buckets[target].length > 0) {
hasData = true;
}
});
}
return hasData;
}
}
export {Bucket, BucketMatrix };