aboutsummaryrefslogtreecommitdiff
path: root/src/client/northstar/dash-fields
diff options
context:
space:
mode:
authorbob <bcz@cs.brown.edu>2019-03-29 13:18:35 -0400
committerbob <bcz@cs.brown.edu>2019-03-29 13:18:35 -0400
commit1bd678851632bbbb302363574eb5e3e19dc343e9 (patch)
tree8526a6c84303f1dc5a5e284ec03c97cf3b3a6bac /src/client/northstar/dash-fields
parentc3eea60fa586e8ff9cf59497c041044fd0143bb1 (diff)
reorganized and mostly working northstar histograms.
Diffstat (limited to 'src/client/northstar/dash-fields')
-rw-r--r--src/client/northstar/dash-fields/HistogramField.ts64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/client/northstar/dash-fields/HistogramField.ts b/src/client/northstar/dash-fields/HistogramField.ts
new file mode 100644
index 000000000..00912c595
--- /dev/null
+++ b/src/client/northstar/dash-fields/HistogramField.ts
@@ -0,0 +1,64 @@
+import { BasicField } from "../../../fields/BasicField";
+import { Field, FieldId } from "../../../fields/Field";
+import { Types } from "../../../server/Message";
+import { HistogramOperation } from "../../../client/northstar/operations/HistogramOperation";
+import { action } from "mobx";
+import { AttributeTransformationModel } from "../../../client/northstar/core/attribute/AttributeTransformationModel";
+import { ColumnAttributeModel } from "../../../client/northstar/core/attribute/AttributeModel";
+import { CurrentUserUtils } from "../../../server/authentication/models/current_user_utils";
+import { ArrayUtil } from "../utils/ArrayUtil";
+import { Schema } from "../model/idea/idea";
+
+
+export class HistogramField extends BasicField<HistogramOperation> {
+ constructor(data?: HistogramOperation, id?: FieldId, save: boolean = true) {
+ super(data ? data : HistogramOperation.Empty, save, id);
+ }
+
+ toString(): string {
+ return JSON.stringify(this.Data);
+ }
+
+ Copy(): Field {
+ return new HistogramField(this.Data);
+ }
+
+ ToScriptString(): string {
+ return `new HistogramField("${this.Data}")`;
+ }
+
+ ToJson(): { type: Types, data: string, _id: string } {
+ return {
+ type: Types.HistogramOp,
+ data: JSON.stringify(this.Data),
+ _id: this.Id
+ }
+ }
+
+ @action
+ static FromJson(id: string, data: any): HistogramField {
+ let jp = JSON.parse(data);
+ let X: AttributeTransformationModel | undefined;
+ let Y: AttributeTransformationModel | undefined;
+ let V: AttributeTransformationModel | undefined;
+
+ let schema = CurrentUserUtils.GetNorthstarSchema(jp.SchemaName);
+ if (schema) {
+ CurrentUserUtils.GetAllNorthstarColumnAttributes(schema).map(attr => {
+ if (attr.displayName == jp.X.AttributeModel.Attribute.DisplayName) {
+ X = new AttributeTransformationModel(new ColumnAttributeModel(attr), jp.X.AggregateFunction);
+ }
+ if (attr.displayName == jp.Y.AttributeModel.Attribute.DisplayName) {
+ Y = new AttributeTransformationModel(new ColumnAttributeModel(attr), jp.Y.AggregateFunction);
+ }
+ if (attr.displayName == jp.V.AttributeModel.Attribute.DisplayName) {
+ V = new AttributeTransformationModel(new ColumnAttributeModel(attr), jp.V.AggregateFunction);
+ }
+ });
+ if (X && Y && V) {
+ return new HistogramField(new HistogramOperation(jp.SchemaName, X, Y, V, jp.Normalization), id, false);
+ }
+ }
+ return new HistogramField(HistogramOperation.Empty, id, false);
+ }
+} \ No newline at end of file