@eox/chart 0.1.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 +33 -0
- package/dist/eox-chart.js +39851 -0
- package/dist/eox-chart.umd.cjs +238 -0
- package/package.json +37 -0
- package/test/cases/index.js +2 -0
- package/test/cases/load-chart.js +26 -0
- package/test/cases/set-data-values.js +51 -0
- package/test/general.cy.js +26 -0
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@eox/chart",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
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
|
+
"vite": "^5.0.2"
|
|
13
|
+
},
|
|
14
|
+
"engines": {
|
|
15
|
+
"npm": ">=8.0.0",
|
|
16
|
+
"node": ">=18.0.0"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"test"
|
|
21
|
+
],
|
|
22
|
+
"main": "./dist/eox-chart.js",
|
|
23
|
+
"scripts": {
|
|
24
|
+
"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"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"deepmerge-ts": "^7.1.3",
|
|
33
|
+
"vega": "^5.30.0",
|
|
34
|
+
"vega-embed": "^6.26.0",
|
|
35
|
+
"vega-lite": "^5.21.0"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
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;
|
|
@@ -0,0 +1,51 @@
|
|
|
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;
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
});
|