@eox/chart 0.1.0 → 0.3.0
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.
- package/README.md +4 -0
- package/dist/eox-chart.js +11287 -11271
- package/dist/eox-chart.umd.cjs +29 -29
- package/package.json +19 -14
- package/src/enums/default-spec.js +11 -0
- package/src/enums/index.js +3 -0
- package/src/enums/test.js +31 -0
- package/src/main.js +88 -0
- package/src/methods/render/index.js +1 -0
- package/src/methods/render/render-chart.js +28 -0
- package/src/style.eox.js +5 -0
- package/src/style.js +9 -0
- package/types/enums/default-spec.d.ts +5 -0
- package/types/enums/default-spec.d.ts.map +1 -0
- package/types/enums/index.d.ts +3 -0
- package/types/enums/index.d.ts.map +1 -0
- package/types/enums/test.d.ts +37 -0
- package/types/enums/test.d.ts.map +1 -0
- package/types/main.d.ts +65 -0
- package/types/main.d.ts.map +1 -0
- package/types/methods/render/index.d.ts +2 -0
- package/types/methods/render/index.d.ts.map +1 -0
- package/types/methods/render/render-chart.d.ts +11 -0
- package/types/methods/render/render-chart.d.ts.map +1 -0
- package/types/style.d.ts +2 -0
- package/types/style.d.ts.map +1 -0
- package/types/style.eox.d.ts +2 -0
- package/types/style.eox.d.ts.map +1 -0
- package/test/cases/index.js +0 -2
- package/test/cases/load-chart.js +0 -26
- package/test/cases/set-data-values.js +0 -51
- package/test/general.cy.js +0 -26
package/package.json
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eox/chart",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"devDependencies": {
|
|
6
|
-
"@eox/eslint-config": "^1.0.0",
|
|
7
|
-
"@typescript-eslint/eslint-plugin": "^7.0.1",
|
|
8
|
-
"@typescript-eslint/parser": "^7.0.1",
|
|
9
|
-
"eslint-plugin-typescript": "^0.14.0",
|
|
10
|
-
"lit": "^3.0.2",
|
|
11
|
-
"typescript": "^5.2.2",
|
|
12
6
|
"vite": "^5.0.2"
|
|
13
7
|
},
|
|
14
8
|
"engines": {
|
|
@@ -16,20 +10,31 @@
|
|
|
16
10
|
"node": ">=18.0.0"
|
|
17
11
|
},
|
|
18
12
|
"files": [
|
|
13
|
+
"types",
|
|
19
14
|
"dist",
|
|
20
|
-
"
|
|
15
|
+
"src"
|
|
21
16
|
],
|
|
22
|
-
"main": "./
|
|
17
|
+
"main": "./src/main.js",
|
|
18
|
+
"types": "./types/main.d.ts",
|
|
19
|
+
"typesVersions": {
|
|
20
|
+
"*": {
|
|
21
|
+
".": [
|
|
22
|
+
"./types/main.d.ts"
|
|
23
|
+
],
|
|
24
|
+
"src/*": [
|
|
25
|
+
"./types/*"
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
},
|
|
23
29
|
"scripts": {
|
|
30
|
+
"prepack": "tsc --project tsconfig.build.json || true",
|
|
24
31
|
"build": "vite build",
|
|
25
|
-
"watch": "vite build --watch"
|
|
26
|
-
"format": "prettier --write .",
|
|
27
|
-
"lint": "eslint --ext .js,.ts .",
|
|
28
|
-
"lint:fix": "eslint --ext .js,.ts . --fix",
|
|
29
|
-
"typecheck": "tsc"
|
|
32
|
+
"watch": "vite build --watch"
|
|
30
33
|
},
|
|
31
34
|
"dependencies": {
|
|
35
|
+
"@eox/elements-utils": "^0.0.1",
|
|
32
36
|
"deepmerge-ts": "^7.1.3",
|
|
37
|
+
"lit": "^3.2.0",
|
|
33
38
|
"vega": "^5.30.0",
|
|
34
39
|
"vega-embed": "^6.26.0",
|
|
35
40
|
"vega-lite": "^5.21.0"
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @type {import("vega-embed").VisualizationSpec}
|
|
3
|
+
*/
|
|
4
|
+
export const DEFAULT_SPEC = {
|
|
5
|
+
// @ts-expect-error see https://vega.github.io/vega-lite/docs/size.html#specifying-responsive-width-and-height
|
|
6
|
+
width: "container",
|
|
7
|
+
// @ts-expect-error see https://vega.github.io/vega-lite/docs/size.html#specifying-responsive-width-and-height
|
|
8
|
+
height: "container",
|
|
9
|
+
autosize: "fit",
|
|
10
|
+
resize: true,
|
|
11
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export const TEST_SELECTORS = {
|
|
2
|
+
chart: "eox-chart",
|
|
3
|
+
vegaContainer: "#vis",
|
|
4
|
+
vegaCanvas: "canvas",
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export const TEST_VALUES = {
|
|
8
|
+
chartHeight: 300,
|
|
9
|
+
chartSpec: {
|
|
10
|
+
$schema: "https://vega.github.io/schema/vega-lite/v5.json",
|
|
11
|
+
description: "A simple bar chart with embedded data.",
|
|
12
|
+
data: {
|
|
13
|
+
values: [
|
|
14
|
+
{ a: "A", b: 28 },
|
|
15
|
+
{ a: "B", b: 55 },
|
|
16
|
+
{ a: "C", b: 43 },
|
|
17
|
+
{ a: "D", b: 91 },
|
|
18
|
+
{ a: "E", b: 81 },
|
|
19
|
+
{ a: "F", b: 53 },
|
|
20
|
+
{ a: "G", b: 19 },
|
|
21
|
+
{ a: "H", b: 87 },
|
|
22
|
+
{ a: "I", b: 52 },
|
|
23
|
+
],
|
|
24
|
+
},
|
|
25
|
+
mark: { type: "bar", tooltip: true, fill: "#004170" },
|
|
26
|
+
encoding: {
|
|
27
|
+
x: { field: "a", type: "ordinal" },
|
|
28
|
+
y: { field: "b", type: "quantitative" },
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
};
|
package/src/main.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { LitElement, html } from "lit";
|
|
2
|
+
import { style } from "./style";
|
|
3
|
+
import { styleEOX } from "./style.eox";
|
|
4
|
+
import allStyle from "@eox/elements-utils/styles/dist/all.style";
|
|
5
|
+
import { renderChartMethod } from "./methods/render";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Chart component based on [Vega-Lite](https://vega.github.io/vega-lite/)/[Vega-Embed](https://github.com/vega/vega-embed).
|
|
9
|
+
* Pass a valid Vega spec as `spec` property in order to render a chart.
|
|
10
|
+
*
|
|
11
|
+
* The `eox-chart` provides some default `spec` settings (merged with the provided `spec` property) and helper functionalities on top of Vega-Lite.
|
|
12
|
+
*
|
|
13
|
+
* @element eox-chart
|
|
14
|
+
*/
|
|
15
|
+
export class EOxChart extends LitElement {
|
|
16
|
+
static properties = {
|
|
17
|
+
dataValues: { attribute: false, type: Object },
|
|
18
|
+
spec: { attribute: false, type: Object },
|
|
19
|
+
noShadow: { attribute: "no-shadow", type: Boolean },
|
|
20
|
+
unstyled: { type: Boolean },
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
constructor() {
|
|
24
|
+
super();
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* [Vega-Lite spec](https://vega.github.io/vega-lite/docs/spec.html)
|
|
28
|
+
*
|
|
29
|
+
* @type {import("vega-embed").VisualizationSpec}
|
|
30
|
+
*/
|
|
31
|
+
this.spec = undefined;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Data values passed on runtime. Requires a [named data source](https://vega.github.io/vega-lite/docs/data.html#named) in the provided `spec`
|
|
35
|
+
*
|
|
36
|
+
* @type {{[dataSourceName: string]: import("vega-lite/build/src/data").InlineData}}
|
|
37
|
+
*/
|
|
38
|
+
this.dataValues = undefined;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Renders the element without a shadow root
|
|
42
|
+
*
|
|
43
|
+
* @type {Boolean}
|
|
44
|
+
*/
|
|
45
|
+
this.noShadow = false;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Render the element without additional styles
|
|
49
|
+
*
|
|
50
|
+
* @type {Boolean}
|
|
51
|
+
*/
|
|
52
|
+
this.unstyled = false;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Lifecycle method called when the element is updated
|
|
57
|
+
*
|
|
58
|
+
* @param {import("lit").PropertyValues} changedProperties
|
|
59
|
+
*/
|
|
60
|
+
async updated(changedProperties) {
|
|
61
|
+
if (changedProperties.has("spec") || changedProperties.has("dataValues")) {
|
|
62
|
+
renderChartMethod(this, this.spec, this.dataValues);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Overrides createRenderRoot to handle shadow DOM creation based on the noShadow property.
|
|
68
|
+
*/
|
|
69
|
+
createRenderRoot() {
|
|
70
|
+
return this.noShadow ? this : super.createRenderRoot();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Renders the component's HTML and CSS
|
|
75
|
+
*/
|
|
76
|
+
render() {
|
|
77
|
+
return html`
|
|
78
|
+
<style>
|
|
79
|
+
${style}
|
|
80
|
+
${!this.unstyled && allStyle}
|
|
81
|
+
${!this.unstyled && styleEOX}
|
|
82
|
+
</style>
|
|
83
|
+
<div id="vis"></div>
|
|
84
|
+
`;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
customElements.define("eox-chart", EOxChart);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as renderChartMethod } from "./render-chart";
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { default as vegaEmbed } from "vega-embed";
|
|
2
|
+
import { deepmerge } from "deepmerge-ts";
|
|
3
|
+
import { DEFAULT_SPEC } from "../../enums";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Render the Vega-Lite chart using vega-embed with a spec and (optionally) dataValues
|
|
7
|
+
*
|
|
8
|
+
* @param {import("../../main").EOxChart} EOxChart The eox-chart instance
|
|
9
|
+
* @param {import("vega-embed").VisualizationSpec} spec
|
|
10
|
+
* @param {Object=} dataValues
|
|
11
|
+
*
|
|
12
|
+
*/
|
|
13
|
+
const renderChartMethod = (EOxChart, spec, dataValues) => {
|
|
14
|
+
const mergedSpec = deepmerge(DEFAULT_SPEC, spec);
|
|
15
|
+
vegaEmbed(
|
|
16
|
+
/** @type {HTMLElement} */ (EOxChart.renderRoot.querySelector("#vis")),
|
|
17
|
+
mergedSpec,
|
|
18
|
+
).then((res) => {
|
|
19
|
+
if (dataValues) {
|
|
20
|
+
Object.keys(dataValues).forEach((dataSourceName) => {
|
|
21
|
+
res.view.insert(dataSourceName, dataValues[dataSourceName]);
|
|
22
|
+
});
|
|
23
|
+
res.view.run();
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export default renderChartMethod;
|
package/src/style.eox.js
ADDED
package/src/style.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default-spec.d.ts","sourceRoot":"","sources":["../../src/enums/default-spec.js"],"names":[],"mappings":"AAAA;;GAEG;AACH,+BAOE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/enums/index.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export namespace TEST_SELECTORS {
|
|
2
|
+
let chart: string;
|
|
3
|
+
let vegaContainer: string;
|
|
4
|
+
let vegaCanvas: string;
|
|
5
|
+
}
|
|
6
|
+
export namespace TEST_VALUES {
|
|
7
|
+
let chartHeight: number;
|
|
8
|
+
namespace chartSpec {
|
|
9
|
+
let $schema: string;
|
|
10
|
+
let description: string;
|
|
11
|
+
namespace data {
|
|
12
|
+
let values: {
|
|
13
|
+
a: string;
|
|
14
|
+
b: number;
|
|
15
|
+
}[];
|
|
16
|
+
}
|
|
17
|
+
namespace mark {
|
|
18
|
+
let type: string;
|
|
19
|
+
let tooltip: boolean;
|
|
20
|
+
let fill: string;
|
|
21
|
+
}
|
|
22
|
+
namespace encoding {
|
|
23
|
+
namespace x {
|
|
24
|
+
export let field: string;
|
|
25
|
+
let type_1: string;
|
|
26
|
+
export { type_1 as type };
|
|
27
|
+
}
|
|
28
|
+
namespace y {
|
|
29
|
+
let field_1: string;
|
|
30
|
+
export { field_1 as field };
|
|
31
|
+
let type_2: string;
|
|
32
|
+
export { type_2 as type };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../../src/enums/test.js"],"names":[],"mappings":""}
|
package/types/main.d.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chart component based on [Vega-Lite](https://vega.github.io/vega-lite/)/[Vega-Embed](https://github.com/vega/vega-embed).
|
|
3
|
+
* Pass a valid Vega spec as `spec` property in order to render a chart.
|
|
4
|
+
*
|
|
5
|
+
* The `eox-chart` provides some default `spec` settings (merged with the provided `spec` property) and helper functionalities on top of Vega-Lite.
|
|
6
|
+
*
|
|
7
|
+
* @element eox-chart
|
|
8
|
+
*/
|
|
9
|
+
export class EOxChart extends LitElement {
|
|
10
|
+
static properties: {
|
|
11
|
+
dataValues: {
|
|
12
|
+
attribute: boolean;
|
|
13
|
+
type: ObjectConstructor;
|
|
14
|
+
};
|
|
15
|
+
spec: {
|
|
16
|
+
attribute: boolean;
|
|
17
|
+
type: ObjectConstructor;
|
|
18
|
+
};
|
|
19
|
+
noShadow: {
|
|
20
|
+
attribute: string;
|
|
21
|
+
type: BooleanConstructor;
|
|
22
|
+
};
|
|
23
|
+
unstyled: {
|
|
24
|
+
type: BooleanConstructor;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* [Vega-Lite spec](https://vega.github.io/vega-lite/docs/spec.html)
|
|
29
|
+
*
|
|
30
|
+
* @type {import("vega-embed").VisualizationSpec}
|
|
31
|
+
*/
|
|
32
|
+
spec: any;
|
|
33
|
+
/**
|
|
34
|
+
* Data values passed on runtime. Requires a [named data source](https://vega.github.io/vega-lite/docs/data.html#named) in the provided `spec`
|
|
35
|
+
*
|
|
36
|
+
* @type {{[dataSourceName: string]: import("vega-lite/build/src/data").InlineData}}
|
|
37
|
+
*/
|
|
38
|
+
dataValues: {
|
|
39
|
+
[dataSourceName: string]: import("vega-lite/build/src/data").InlineData;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Renders the element without a shadow root
|
|
43
|
+
*
|
|
44
|
+
* @type {Boolean}
|
|
45
|
+
*/
|
|
46
|
+
noShadow: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Render the element without additional styles
|
|
49
|
+
*
|
|
50
|
+
* @type {Boolean}
|
|
51
|
+
*/
|
|
52
|
+
unstyled: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Lifecycle method called when the element is updated
|
|
55
|
+
*
|
|
56
|
+
* @param {import("lit").PropertyValues} changedProperties
|
|
57
|
+
*/
|
|
58
|
+
updated(changedProperties: import("lit").PropertyValues): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Renders the component's HTML and CSS
|
|
61
|
+
*/
|
|
62
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
63
|
+
}
|
|
64
|
+
import { LitElement } from "lit";
|
|
65
|
+
//# sourceMappingURL=main.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.js"],"names":[],"mappings":"AAMA;;;;;;;GAOG;AACH;IACE;;;;;;;;;;;;;;;;MAKE;IAKA;;;;OAIG;IACH,UAAqB;IAErB;;;;OAIG;IACH,YAFU;QAAC,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,0BAA0B,EAAE,UAAU,CAAA;KAAC,CAExD;IAE3B;;;;OAIG;IACH,kBAAqB;IAErB;;;;OAIG;IACH,kBAAqB;IAGvB;;;;OAIG;IACH,2BAFW,OAAO,KAAK,EAAE,cAAc,iBAMtC;IASD;;OAEG;IACH,+CASC;CACF;2BArFgC,KAAK"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/methods/render/index.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export default renderChartMethod;
|
|
2
|
+
/**
|
|
3
|
+
* Render the Vega-Lite chart using vega-embed with a spec and (optionally) dataValues
|
|
4
|
+
*
|
|
5
|
+
* @param {import("../../main").EOxChart} EOxChart The eox-chart instance
|
|
6
|
+
* @param {import("vega-embed").VisualizationSpec} spec
|
|
7
|
+
* @param {Object=} dataValues
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
declare function renderChartMethod(EOxChart: import("../../main").EOxChart, spec: any, dataValues?: any | undefined): void;
|
|
11
|
+
//# sourceMappingURL=render-chart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-chart.d.ts","sourceRoot":"","sources":["../../../src/methods/render/render-chart.js"],"names":[],"mappings":";AAIA;;;;;;;GAOG;AACH,6CALW,OAAO,YAAY,EAAE,QAAQ,iDAkBvC"}
|
package/types/style.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"style.d.ts","sourceRoot":"","sources":["../src/style.js"],"names":[],"mappings":"AAAA,oIAQE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"style.eox.d.ts","sourceRoot":"","sources":["../src/style.eox.js"],"names":[],"mappings":"AAAA,sFAIE"}
|
package/test/cases/index.js
DELETED
package/test/cases/load-chart.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { TEST_SELECTORS, TEST_VALUES } from "../../src/enums";
|
|
2
|
-
|
|
3
|
-
// Destructure TEST_SELECTORS object
|
|
4
|
-
const { chart, vegaContainer, vegaCanvas } = TEST_SELECTORS;
|
|
5
|
-
|
|
6
|
-
// Destructuring TEST_VALUES object
|
|
7
|
-
const { chartHeight, chartSpec } = TEST_VALUES;
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Test to verify if the chart component loads successfully.
|
|
11
|
-
*/
|
|
12
|
-
const loadChartTest = () => {
|
|
13
|
-
cy.get(chart).and(($el) => {
|
|
14
|
-
const eoxChart = $el[0];
|
|
15
|
-
eoxChart.spec = chartSpec;
|
|
16
|
-
});
|
|
17
|
-
// Find the chart element and access its shadow DOM
|
|
18
|
-
cy.get(chart)
|
|
19
|
-
.shadow()
|
|
20
|
-
.within(() => {
|
|
21
|
-
cy.get(vegaContainer);
|
|
22
|
-
cy.get(vegaCanvas).invoke("outerHeight").should("eq", chartHeight);
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export default loadChartTest;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { TEST_SELECTORS, TEST_VALUES } from "../../src/enums";
|
|
2
|
-
|
|
3
|
-
// Destructure TEST_SELECTORS object
|
|
4
|
-
const { chart } = TEST_SELECTORS;
|
|
5
|
-
|
|
6
|
-
// Destructuring TEST_VALUES object
|
|
7
|
-
const { chartSpec } = TEST_VALUES;
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Test to verify if the chart component loads successfully.
|
|
11
|
-
*/
|
|
12
|
-
const setDataValuesTest = () => {
|
|
13
|
-
return new Cypress.Promise((resolve) => {
|
|
14
|
-
cy.get(chart).and(($el) => {
|
|
15
|
-
const eoxChart = $el[0];
|
|
16
|
-
|
|
17
|
-
const dataValueTestKey = "myData";
|
|
18
|
-
const chartSpecDataValues = chartSpec.data.values;
|
|
19
|
-
const chartSpecWithoutData = {
|
|
20
|
-
...chartSpec,
|
|
21
|
-
data: {
|
|
22
|
-
name: dataValueTestKey,
|
|
23
|
-
},
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
// Set the spec with a data placeholder
|
|
27
|
-
eoxChart.spec = chartSpecWithoutData;
|
|
28
|
-
|
|
29
|
-
// Wait some time and set the data values afterwards
|
|
30
|
-
setTimeout(() => {
|
|
31
|
-
eoxChart.dataValues = {
|
|
32
|
-
[dataValueTestKey]: chartSpecDataValues,
|
|
33
|
-
};
|
|
34
|
-
setTimeout(() => {
|
|
35
|
-
const canvas = eoxChart.shadowRoot.querySelector("canvas");
|
|
36
|
-
const context = canvas.getContext("2d");
|
|
37
|
-
const pixel = context.getImageData(150, 150, 1, 1).data;
|
|
38
|
-
const red = pixel[0];
|
|
39
|
-
const green = pixel[1];
|
|
40
|
-
const blue = pixel[2];
|
|
41
|
-
expect(red).to.eq(0);
|
|
42
|
-
expect(green).to.eq(65);
|
|
43
|
-
expect(blue).to.eq(112);
|
|
44
|
-
resolve();
|
|
45
|
-
});
|
|
46
|
-
}, 100);
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
export default setDataValuesTest;
|
package/test/general.cy.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
// Importing necessary modules, test cases, and enums
|
|
2
|
-
import "../src/main";
|
|
3
|
-
import { loadChartTest, setDataValuesTest } from "./cases";
|
|
4
|
-
import { TEST_SELECTORS, TEST_VALUES } from "../src/enums";
|
|
5
|
-
|
|
6
|
-
// Destructuring TEST_SELECTORS object
|
|
7
|
-
const { chart } = TEST_SELECTORS;
|
|
8
|
-
|
|
9
|
-
// Destructuring TEST_VALUES object
|
|
10
|
-
const { chartHeight } = TEST_VALUES;
|
|
11
|
-
|
|
12
|
-
// Test suite for Chart
|
|
13
|
-
describe("Chart", () => {
|
|
14
|
-
// Setting up the environment before each test
|
|
15
|
-
beforeEach(() => {
|
|
16
|
-
// Mounting eox-chart element
|
|
17
|
-
cy.mount(
|
|
18
|
-
`<eox-chart style="width: ${chartHeight}px; height: ${chartHeight}px"></eox-chart>`
|
|
19
|
-
).as(chart);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
// Test case to ensure the chart component loads successfully
|
|
23
|
-
it("loads the chart", () => loadChartTest());
|
|
24
|
-
|
|
25
|
-
it("allows setting data values asynchronously", () => setDataValuesTest());
|
|
26
|
-
});
|