Skip to content

Commit

Permalink
[add] Vue 3 quick start of Read Me document
Browse files Browse the repository at this point in the history
[fix] Children Event & Preview Page failed
  • Loading branch information
TechQuery committed Apr 9, 2024
1 parent 204df2c commit 19708fb
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 33 deletions.
41 changes: 32 additions & 9 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,45 +20,68 @@ A real [JSX][1] wrapper for [ECharts][2] based on [TypeScript][3] & [Web compone
| `>=1` | `main` | ✅developing | Web components |
| `<1` | `master` | ❌deprecated | React |

## Quick start
## Installation

### Installation

#### Core package
### Core package

```shell
npm i echarts-jsx
```

#### View renderer
### View renderer

Any kinds of Render engines that you like can be used to render ECharts JSX tags.

##### React 19+
#### React 19+

Old versions have a property bug of Custom elements: https://github.com/facebook/react/issues/11347

```shell
npm i react@^19 react-dom@^19
```

##### Preact
#### Preact

```shell
npm i preact
```

then configure your tool-chain: https://preactjs.com/guide/v10/getting-started#integrating-into-an-existing-pipeline

##### DOM Renderer v2 & WebCell v3
#### DOM Renderer v2 & WebCell v3

```shell
npm i dom-renderer@^2
```

then configure your project as [the demo code](preview/).

### Simple example
#### Vue 3

```shell
npm create vite vue-echarts-app -- --template vue-ts
```

then configure your Vite as following code:

```js
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';

export default defineConfig({
plugins: [
vue({
template: {
compilerOptions: {
isCustomElement: tag => tag.startsWith('ec-')
}
}
})
]
});
```

## Simple example

Origin: [ECharts official example][9]

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "echarts-jsx",
"version": "1.0.0",
"version": "1.0.1",
"license": "LGPL-3.0",
"author": "[email protected]",
"description": "A real JSX wrapper for ECharts based on TypeScript & Web components",
Expand Down Expand Up @@ -46,7 +46,7 @@
"parcel": "~2.12.0",
"prettier": "^3.2.5",
"rimraf": "^5.0.5",
"typedoc": "^0.25.12",
"typedoc": "^0.25.13",
"typedoc-plugin-mdn-links": "^3.1.19",
"typescript": "~5.4.4"
},
Expand Down
14 changes: 7 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions preview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import '../source/components/y-axis';
import '../source/charts/line';

new DOMRenderer().render(
<ec-svg-chart style={{ height: '75vh' }}>
<ec-svg-renderer style={{ height: '75vh' }}>
<ec-title text="ECharts Getting Started Example" />

<ec-x-axis
Expand All @@ -19,6 +19,6 @@ new DOMRenderer().render(
data={[150, 230, 224, 218, 135, 147, 260]}
onClick={console.log}
/>
</ec-svg-chart>,
</ec-svg-renderer>,
document.querySelector('main')
);
29 changes: 16 additions & 13 deletions source/Option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,24 @@ export abstract class ECOptionElement
}

get eventSelector() {
return [this.chartName || this.chartTagName, this['type']]
return [
this.isSeries && 'series',
this.chartName || this.chartTagName,
this['type']
]
.filter(Boolean)
.join('.');
}

get renderer() {
for (
let parent = this.parentElement;
parent;
parent = parent.parentElement
)
if (parent instanceof EChartsElement) return parent;
}

connectedCallback() {
for (const [key, value] of Object.entries(this.toJSON()))
if (EventKeyPattern.test(key) && typeof value === 'function')
Expand Down Expand Up @@ -61,21 +74,11 @@ export abstract class ECOptionElement
}

listen(event: ZRElementEventName, handler: ZRElementEventHandler) {
if (this.isConnected)
this.closest<EChartsElement>('ec-chart')?.onChild(
event,
this.eventSelector,
handler
);
this.renderer?.onChild(event, this.eventSelector, handler);
}

forget(event: ZRElementEventName, handler: ZRElementEventHandler) {
if (this.isConnected)
this.closest<EChartsElement>('ec-chart')?.offChild(
event,
this.eventSelector,
handler
);
this.renderer?.offChild(event, this.eventSelector, handler);
}

setAttribute(name: string, value: string) {
Expand Down

1 comment on commit 19708fb

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for echarts-jsx ready!

✅ Preview
https://echarts-ask7q1hgx-techquerys-projects.vercel.app

Built with commit 19708fb.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.