@gisce/ooui 0.5.1 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,10 @@
1
1
  export declare type Axis = "x" | "y";
2
2
  export declare type Operator = "count" | "+" | "-" | "*" | "min" | "max" | "avg";
3
3
  export declare class GraphAxis {
4
- _name: string | undefined;
5
- get name(): string | undefined;
6
- _axis: Axis | undefined;
7
- get axis(): Axis | undefined;
4
+ _name: string;
5
+ get name(): string;
6
+ _axis: Axis;
7
+ get axis(): Axis;
8
8
  _operator: Operator | undefined;
9
9
  get operator(): Operator | undefined;
10
10
  _label: string | undefined;
@@ -13,6 +13,6 @@ export declare class GraphAxis {
13
13
  name: string;
14
14
  axis: Axis;
15
15
  operator?: Operator;
16
- label: string | undefined;
16
+ label?: string;
17
17
  });
18
18
  }
@@ -1,9 +1,9 @@
1
1
  import { GraphAxis } from ".";
2
2
  import { Graph, GraphType } from "./Graph";
3
3
  export declare class GraphChart extends Graph {
4
- _x: GraphAxis | undefined;
5
- get x(): GraphAxis | undefined;
6
- _y: GraphAxis[] | undefined;
7
- get y(): GraphAxis[] | undefined;
4
+ _x: GraphAxis;
5
+ get x(): GraphAxis;
6
+ _y: GraphAxis[];
7
+ get y(): GraphAxis[];
8
8
  constructor(type: GraphType, element: HTMLElement);
9
9
  }
@@ -2,9 +2,9 @@ import { Operator } from ".";
2
2
  import { GraphType } from "./Graph";
3
3
  import { GraphIndicator } from "./GraphIndicator";
4
4
  export declare class GraphIndicatorField extends GraphIndicator {
5
- _field: string | null;
6
- get field(): string | null;
7
- _operator: Operator | null;
8
- get operator(): Operator | null;
5
+ _field: string | undefined;
6
+ get field(): string | undefined;
7
+ _operator: Operator | undefined;
8
+ get operator(): Operator | undefined;
9
9
  constructor(type: GraphType, element: HTMLElement);
10
10
  }
@@ -16,13 +16,11 @@ var GraphIndicatorField = /** @class */ (function (_super) {
16
16
  __extends(GraphIndicatorField, _super);
17
17
  function GraphIndicatorField(type, element) {
18
18
  var _this = _super.call(this, type, element) || this;
19
- _this._field = null;
20
- _this._operator = null;
21
19
  Array.prototype.forEach.call(element.childNodes, function (child) {
22
20
  if (child.nodeType === child.ELEMENT_NODE && child.nodeName === "field") {
23
21
  var name_1 = child.getAttribute("name");
24
22
  var operator = child.getAttribute("operator");
25
- _this._field = name_1;
23
+ _this._field = name_1 || undefined;
26
24
  _this._operator = operator;
27
25
  }
28
26
  });
@@ -1 +1 @@
1
- {"version":3,"file":"GraphIndicatorField.js","sourceRoot":"","sources":["../../src/Graph/GraphIndicatorField.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD;IAAyC,uCAAc;IAWrD,6BAAY,IAAe,EAAE,OAAoB;QAAjD,YACE,kBAAM,IAAI,EAAE,OAAO,CAAC,SAUrB;QArBD,YAAM,GAAkB,IAAI,CAAC;QAK7B,eAAS,GAAoB,IAAI,CAAC;QAQhC,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,UAAC,KAAc;YAC9D,IAAI,KAAK,CAAC,QAAQ,KAAK,KAAK,CAAC,YAAY,IAAI,KAAK,CAAC,QAAQ,KAAK,OAAO,EAAE;gBACvE,IAAM,MAAI,GAAG,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;gBACxC,IAAM,QAAQ,GAAG,KAAK,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;gBAChD,KAAI,CAAC,MAAM,GAAG,MAAI,CAAC;gBACnB,KAAI,CAAC,SAAS,GAAG,QAAoB,CAAC;aACvC;QACH,CAAC,CAAC,CAAC;;IACL,CAAC;IApBD,sBAAI,sCAAK;aAAT;YACE,OAAO,IAAI,CAAC,MAAM,CAAC;QACrB,CAAC;;;OAAA;IAGD,sBAAI,yCAAQ;aAAZ;YACE,OAAO,IAAI,CAAC,SAAS,CAAC;QACxB,CAAC;;;OAAA;IAcH,0BAAC;AAAD,CAAC,AAvBD,CAAyC,cAAc,GAuBtD"}
1
+ {"version":3,"file":"GraphIndicatorField.js","sourceRoot":"","sources":["../../src/Graph/GraphIndicatorField.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD;IAAyC,uCAAc;IAWrD,6BAAY,IAAe,EAAE,OAAoB;QAAjD,YACE,kBAAM,IAAI,EAAE,OAAO,CAAC,SAUrB;QARC,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,UAAC,KAAc;YAC9D,IAAI,KAAK,CAAC,QAAQ,KAAK,KAAK,CAAC,YAAY,IAAI,KAAK,CAAC,QAAQ,KAAK,OAAO,EAAE;gBACvE,IAAM,MAAI,GAAG,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;gBACxC,IAAM,QAAQ,GAAG,KAAK,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;gBAChD,KAAI,CAAC,MAAM,GAAG,MAAI,IAAI,SAAS,CAAC;gBAChC,KAAI,CAAC,SAAS,GAAG,QAAoB,CAAC;aACvC;QACH,CAAC,CAAC,CAAC;;IACL,CAAC;IApBD,sBAAI,sCAAK;aAAT;YACE,OAAO,IAAI,CAAC,MAAM,CAAC;QACrB,CAAC;;;OAAA;IAGD,sBAAI,yCAAQ;aAAZ;YACE,OAAO,IAAI,CAAC,SAAS,CAAC;QACxB,CAAC;;;OAAA;IAcH,0BAAC;AAAD,CAAC,AAvBD,CAAyC,cAAc,GAuBtD"}
@@ -1,6 +1,6 @@
1
1
  import { GraphAxis } from ".";
2
2
  export declare type XYAxis = {
3
- x: GraphAxis | undefined;
3
+ x: GraphAxis;
4
4
  y: GraphAxis[];
5
5
  };
6
6
  export declare const parseXYAxis: (nodes: NodeListOf<ChildNode>) => XYAxis;
@@ -1,6 +1,7 @@
1
1
  import { GraphAxis } from ".";
2
2
  export var parseXYAxis = function (nodes) {
3
- var xyAxis = { x: undefined, y: [] };
3
+ var yAxisElements = [];
4
+ var xAxis;
4
5
  Array.prototype.forEach.call(nodes, function (child) {
5
6
  if (child.nodeType === child.ELEMENT_NODE && child.nodeName === "field") {
6
7
  var axis = child.getAttribute("axis");
@@ -16,17 +17,26 @@ export var parseXYAxis = function (nodes) {
16
17
  var graphAxis = new GraphAxis({
17
18
  axis: axis,
18
19
  name: name_1,
19
- operator: operator,
20
+ operator: operator ? operator : undefined,
20
21
  label: label || undefined,
21
22
  });
22
23
  if (axis === "x") {
23
- xyAxis.x = graphAxis;
24
+ xAxis = graphAxis;
24
25
  }
25
26
  else if (axis === "y") {
26
- xyAxis.y.push(graphAxis);
27
+ yAxisElements.push(graphAxis);
27
28
  }
28
29
  }
29
30
  });
30
- return xyAxis;
31
+ if (!xAxis) {
32
+ throw new Error("No x axis found");
33
+ }
34
+ if (!yAxisElements.length) {
35
+ throw new Error("No y axis found. At least we need one y axis");
36
+ }
37
+ return {
38
+ x: xAxis,
39
+ y: yAxisElements,
40
+ };
31
41
  };
32
42
  //# sourceMappingURL=graphHelper.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"graphHelper.js","sourceRoot":"","sources":["../../src/Graph/graphHelper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,SAAS,EAAY,MAAM,GAAG,CAAC;AAO9C,MAAM,CAAC,IAAM,WAAW,GAAG,UAAC,KAA4B;IACtD,IAAM,MAAM,GAAW,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC;IAE/C,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,UAAC,KAAc;QACjD,IAAI,KAAK,CAAC,QAAQ,KAAK,KAAK,CAAC,YAAY,IAAI,KAAK,CAAC,QAAQ,KAAK,OAAO,EAAE;YACvE,IAAM,IAAI,GAAG,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC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version": "0.6.2",
4
4
  "dependencies": {},
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -2,13 +2,13 @@ export type Axis = "x" | "y";
2
2
  export type Operator = "count" | "+" | "-" | "*" | "min" | "max" | "avg";
3
3
 
4
4
  export class GraphAxis {
5
- _name: string | undefined;
6
- get name(): string | undefined {
5
+ _name: string;
6
+ get name(): string {
7
7
  return this._name;
8
8
  }
9
9
 
10
- _axis: Axis | undefined;
11
- get axis(): Axis | undefined {
10
+ _axis: Axis;
11
+ get axis(): Axis {
12
12
  return this._axis;
13
13
  }
14
14
 
@@ -31,7 +31,7 @@ export class GraphAxis {
31
31
  name: string;
32
32
  axis: Axis;
33
33
  operator?: Operator;
34
- label: string | undefined;
34
+ label?: string;
35
35
  }) {
36
36
  this._name = name;
37
37
  this._axis = axis;
@@ -3,13 +3,13 @@ import { Graph, GraphType } from "./Graph";
3
3
  import { parseXYAxis } from "./graphHelper";
4
4
 
5
5
  export class GraphChart extends Graph {
6
- _x: GraphAxis | undefined;
7
- get x(): GraphAxis | undefined {
6
+ _x: GraphAxis;
7
+ get x(): GraphAxis {
8
8
  return this._x;
9
9
  }
10
10
 
11
- _y: GraphAxis[] | undefined;
12
- get y(): GraphAxis[] | undefined {
11
+ _y: GraphAxis[];
12
+ get y(): GraphAxis[] {
13
13
  return this._y;
14
14
  }
15
15
  constructor(type: GraphType, element: HTMLElement) {
@@ -3,13 +3,13 @@ import { GraphType } from "./Graph";
3
3
  import { GraphIndicator } from "./GraphIndicator";
4
4
 
5
5
  export class GraphIndicatorField extends GraphIndicator {
6
- _field: string | null = null;
7
- get field(): string | null {
6
+ _field: string | undefined;
7
+ get field(): string | undefined {
8
8
  return this._field;
9
9
  }
10
10
 
11
- _operator: Operator | null = null;
12
- get operator(): Operator | null {
11
+ _operator: Operator | undefined;
12
+ get operator(): Operator | undefined {
13
13
  return this._operator;
14
14
  }
15
15
 
@@ -20,7 +20,7 @@ export class GraphIndicatorField extends GraphIndicator {
20
20
  if (child.nodeType === child.ELEMENT_NODE && child.nodeName === "field") {
21
21
  const name = child.getAttribute("name");
22
22
  const operator = child.getAttribute("operator");
23
- this._field = name;
23
+ this._field = name || undefined;
24
24
  this._operator = operator as Operator;
25
25
  }
26
26
  });
@@ -1,12 +1,13 @@
1
1
  import { Axis, GraphAxis, Operator } from ".";
2
2
 
3
3
  export type XYAxis = {
4
- x: GraphAxis | undefined;
4
+ x: GraphAxis;
5
5
  y: GraphAxis[];
6
6
  };
7
7
 
8
8
  export const parseXYAxis = (nodes: NodeListOf<ChildNode>): XYAxis => {
9
- const xyAxis: XYAxis = { x: undefined, y: [] };
9
+ const yAxisElements: GraphAxis[] = [];
10
+ let xAxis;
10
11
 
11
12
  Array.prototype.forEach.call(nodes, (child: Element) => {
12
13
  if (child.nodeType === child.ELEMENT_NODE && child.nodeName === "field") {
@@ -26,17 +27,28 @@ export const parseXYAxis = (nodes: NodeListOf<ChildNode>): XYAxis => {
26
27
  const graphAxis = new GraphAxis({
27
28
  axis: axis as Axis,
28
29
  name,
29
- operator: operator as Operator,
30
+ operator: operator ? (operator as Operator) : undefined,
30
31
  label: label || undefined,
31
32
  });
32
33
 
33
34
  if (axis === "x") {
34
- xyAxis.x = graphAxis;
35
+ xAxis = graphAxis;
35
36
  } else if (axis === "y") {
36
- xyAxis.y.push(graphAxis);
37
+ yAxisElements.push(graphAxis);
37
38
  }
38
39
  }
39
40
  });
40
41
 
41
- return xyAxis as XYAxis;
42
+ if (!xAxis) {
43
+ throw new Error("No x axis found");
44
+ }
45
+
46
+ if (!yAxisElements.length) {
47
+ throw new Error("No y axis found. At least we need one y axis");
48
+ }
49
+
50
+ return {
51
+ x: xAxis,
52
+ y: yAxisElements,
53
+ };
42
54
  };
@@ -1,4 +1,10 @@
1
- import { GraphIndicator, GraphChart, parseGraph, GraphAxis, GraphIndicatorField } from "..";
1
+ import {
2
+ GraphIndicator,
3
+ GraphChart,
4
+ parseGraph,
5
+ GraphAxis,
6
+ GraphIndicatorField,
7
+ } from "..";
2
8
 
3
9
  describe("A Graph", () => {
4
10
  it("should parse a basic XML title and type indicator", () => {
@@ -22,16 +28,16 @@ describe("A Graph", () => {
22
28
  `;
23
29
 
24
30
  const graph = parseGraph(xml) as GraphChart;
25
- const y: GraphAxis = graph.y![0];
31
+ const y: GraphAxis = graph.y[0];
26
32
 
27
33
  expect(graph.type).toBe("line");
28
34
  expect(graph.x).toBeDefined();
29
35
  expect(graph.y).toBeDefined();
30
- expect(graph.x?.name).toBe("data_alta");
36
+ expect(graph.x.name).toBe("data_alta");
31
37
  expect(y.name).toBe("data_alta");
32
- expect(graph.x?.axis).toBe("x");
38
+ expect(graph.x.axis).toBe("x");
33
39
  expect(y.axis).toBe("y");
34
- expect(graph.x?.operator).toBeNull();
40
+ expect(graph.x?.operator).toBeUndefined();
35
41
  expect(y.operator).toBe("+");
36
42
  });
37
43
  it("should parse a basic XML title and type indicator field", () => {