@triptease/tt-bar-chart 0.0.1

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/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@triptease/tt-bar-chart",
3
+ "description": "Webcomponent tt-bar-chart following open-wc recommendations",
4
+ "license": "MIT",
5
+ "author": "tt-bar-chart",
6
+ "version": "0.0.1",
7
+ "type": "module",
8
+ "main": "dist/src/index.js",
9
+ "module": "dist/src/index.js",
10
+ "exports": {
11
+ ".": "./dist/src/index.js",
12
+ "./tt-bar-chart.js": "./dist/src/tt-bar-chart.js"
13
+ },
14
+ "scripts": {
15
+ "analyze": "cem analyze --litelement",
16
+ "start": "tsc && concurrently -k -r \"tsc --watch --preserveWatchOutput\" \"web-dev-server\"",
17
+ "build": "yarn build:node && yarn build:web && npm run analyze -- --exclude dist",
18
+ "build:node": "tsc",
19
+ "build:node:watch": "tsc --watch",
20
+ "build:web": "node ../../scripts/esbuild.mjs",
21
+ "prepublish": "tsc && npm run analyze -- --exclude dist",
22
+ "test": "tsc && wtr",
23
+ "test:watch": "tsc && concurrently -k -r \"tsc --watch --preserveWatchOutput\" \"wtr --watch\""
24
+ },
25
+ "dependencies": {
26
+ "chart.js": "^4.5.1",
27
+ "echarts": "^6.0.0",
28
+ "lit": "^3.1.4"
29
+ },
30
+ "devDependencies": {
31
+ "@custom-elements-manifest/analyzer": "^0.10.3",
32
+ "@open-wc/testing": "^4.0.0",
33
+ "@types/mocha": "^10.0.7",
34
+ "@web/dev-server": "^0.4.6",
35
+ "@web/test-runner": "^0.18.2",
36
+ "concurrently": "^8.2.2",
37
+ "tslib": "^2.6.3",
38
+ "typescript": "^5.5.3"
39
+ },
40
+ "customElements": "custom-elements.json"
41
+ }
@@ -0,0 +1,82 @@
1
+ import { html, LitElement } from 'lit';
2
+ // @ts-expect-error Known error - https://github.com/apache/echarts/issues/21250
3
+ import * as echarts from 'echarts';
4
+ import { property } from 'lit/decorators.js';
5
+
6
+ interface Dataset {
7
+ label: string;
8
+ data: number[];
9
+ color?: string;
10
+ }
11
+
12
+ const jsonConvertor = (value: string | null) => (value ? JSON.parse(value) : undefined);
13
+ export class TtBarChart extends LitElement {
14
+ @property({ type: Array, converter: jsonConvertor, attribute: 'categories' })
15
+ labels?: string[];
16
+
17
+ @property({ type: Array, converter: jsonConvertor })
18
+ datasets?: Dataset[];
19
+
20
+ @property({ type: String })
21
+ direction?: 'horizontal' | 'vertical' = 'horizontal';
22
+
23
+ @property({ type: Boolean, attribute: 'show-grid' })
24
+ showGrid: boolean = false;
25
+
26
+ @property({ type: Boolean, attribute: 'show-legend' })
27
+ showLegend: boolean = false;
28
+
29
+ @property({ type: String })
30
+ width: string = '600px';
31
+
32
+ @property({ type: String })
33
+ height: string = '400px';
34
+
35
+ private getSeriesColor = (dataset: Dataset) => {
36
+ if (this.datasets && this.datasets.length > 1) return undefined;
37
+ if (dataset.color) return dataset.color;
38
+
39
+ return '#4d35a1';
40
+ };
41
+
42
+ render() {
43
+ return html` <div>
44
+ <div id=${this.id} style="width: ${this.width}; height:${this.height};"></div>
45
+ </div>`;
46
+ }
47
+
48
+ protected firstUpdated() {
49
+ const divElement = this.renderRoot.querySelector(`#${this.id}`) as HTMLDivElement;
50
+
51
+ if (!divElement) {
52
+ throw new Error('No div element');
53
+ }
54
+
55
+ const chart = echarts.init(divElement);
56
+
57
+ const series: echarts.SeriesOption[] = (this.datasets || []).map((dataset) => ({
58
+ name: dataset.label,
59
+ type: 'bar',
60
+ data: dataset.data,
61
+ color: this.getSeriesColor(dataset),
62
+ }));
63
+ const option: echarts.EChartsOption = {
64
+ legend: {
65
+ show: this.showLegend,
66
+ },
67
+ xAxis: {
68
+ type: this.direction === 'horizontal' ? 'value' : 'category',
69
+ data: this.direction === 'horizontal' ? undefined : this.labels,
70
+ splitLine: { show: this.showGrid },
71
+ },
72
+ yAxis: {
73
+ type: this.direction === 'horizontal' ? 'category' : 'value',
74
+ data: this.direction === 'horizontal' ? this.labels : undefined,
75
+ splitLine: { show: this.showGrid },
76
+ },
77
+ series,
78
+ };
79
+
80
+ chart.setOption(option);
81
+ }
82
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export { TtBarChart } from './tt-bar-chart.js';
@@ -0,0 +1,9 @@
1
+ import { TtBarChart } from './TtBarChart.js';
2
+
3
+ if (typeof window !== 'undefined') {
4
+ if (!window.customElements.get('tt-bar-chart')) {
5
+ window.customElements.define('tt-bar-chart', TtBarChart);
6
+ }
7
+ }
8
+
9
+ export { TtBarChart };
File without changes
package/tsconfig.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2021",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "noEmitOnError": true,
7
+ "lib": ["es2021", "dom", "DOM.Iterable"],
8
+ "strict": true,
9
+ "esModuleInterop": false,
10
+ "allowSyntheticDefaultImports": true,
11
+ "experimentalDecorators": true,
12
+ "importHelpers": true,
13
+ "outDir": "dist",
14
+ "sourceMap": true,
15
+ "inlineSources": true,
16
+ "rootDir": "./",
17
+ "declaration": true,
18
+ "incremental": true,
19
+ "skipLibCheck": true
20
+ },
21
+ "include": ["**/*.ts"]
22
+ }
@@ -0,0 +1,27 @@
1
+ // import { hmrPlugin, presets } from '@open-wc/dev-server-hmr';
2
+
3
+ /** Use Hot Module replacement by adding --hmr to the start command */
4
+ const hmr = process.argv.includes('--hmr');
5
+
6
+ export default /** @type {import('@web/dev-server').DevServerConfig} */ ({
7
+ open: '/demo/',
8
+ /** Use regular watch mode if HMR is not enabled. */
9
+ watch: !hmr,
10
+ /** Resolve bare module imports */
11
+ nodeResolve: {
12
+ exportConditions: ['browser', 'development'],
13
+ },
14
+
15
+ /** Compile JS for older browsers. Requires @web/dev-server-esbuild plugin */
16
+ // esbuildTarget: 'auto'
17
+
18
+ /** Set appIndex to enable SPA routing */
19
+ // appIndex: 'demo/index.html',
20
+
21
+ plugins: [
22
+ /** Use Hot Module Replacement by uncommenting. Requires @open-wc/dev-server-hmr plugin */
23
+ // hmr && hmrPlugin({ exclude: ['**/*/node_modules/**/*'], presets: [presets.lit] }),
24
+ ],
25
+
26
+ // See documentation for all available options
27
+ });
@@ -0,0 +1,41 @@
1
+ // import { playwrightLauncher } from '@web/test-runner-playwright';
2
+
3
+ const filteredLogs = ['Running in dev mode', 'Lit is in dev mode'];
4
+
5
+ export default /** @type {import("@web/test-runner").TestRunnerConfig} */ ({
6
+ /** Test files to run */
7
+ files: 'dist/test/**/*.test.js',
8
+
9
+ /** Resolve bare module imports */
10
+ nodeResolve: {
11
+ exportConditions: ['browser', 'development'],
12
+ },
13
+
14
+ /** Filter out lit dev mode logs */
15
+ filterBrowserLogs(log) {
16
+ for (const arg of log.args) {
17
+ if (typeof arg === 'string' && filteredLogs.some(l => arg.includes(l))) {
18
+ return false;
19
+ }
20
+ }
21
+ return true;
22
+ },
23
+
24
+ /** Compile JS for older browsers. Requires @web/dev-server-esbuild plugin */
25
+ // esbuildTarget: 'auto',
26
+
27
+ /** Amount of browsers to run concurrently */
28
+ // concurrentBrowsers: 2,
29
+
30
+ /** Amount of test files per browser to test concurrently */
31
+ // concurrency: 1,
32
+
33
+ /** Browsers to run tests on */
34
+ // browsers: [
35
+ // playwrightLauncher({ product: 'chromium' }),
36
+ // playwrightLauncher({ product: 'firefox' }),
37
+ // playwrightLauncher({ product: 'webkit' }),
38
+ // ],
39
+
40
+ // See documentation for all available options
41
+ });