Skip to content

Commit

Permalink
[add] Radar component & View Engine document
Browse files Browse the repository at this point in the history
[optimize] export Chart & Component Element classes
[fix] some detail bugs
  • Loading branch information
TechQuery committed Apr 7, 2024
1 parent 2d52fb0 commit c5fdc25
Show file tree
Hide file tree
Showing 49 changed files with 242 additions and 179 deletions.
38 changes: 34 additions & 4 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,52 @@ A real [JSX][1] wrapper for [ECharts][2] based on [TypeScript][3] & [Web compone

### Installation

#### Core package

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

#### View renderer

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

##### 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

```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

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

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

### Simple example

Origin: [ECharts official example][9]

[![Edit ECharts-JSX-demo](https://codesandbox.io/static/img/play-codesandbox.svg)][10]
[![Edit ECharts-JSX-1.0-demo](https://codesandbox.io/static/img/play-codesandbox.svg)][10]

```tsx
import { render } from 'react-dom';
import 'echarts-jsx';

render(
<ec-svg-chart theme="dark" style={{ width: '100%', height: '75vh' }}>
<ec-svg-renderer theme="dark" style={{ width: '100%', height: '75vh' }}>
<ec-title text="ECharts Getting Started Example" />

<ec-legend data={['sales']} />
Expand All @@ -63,7 +93,7 @@ render(
data={[5, 20, 36, 10, 10, 20]}
onClick={console.log}
/>
</ec-svg-chart>,
</ec-svg-renderer>,
document.body
);
```
Expand All @@ -88,4 +118,4 @@ render(
[7]: https://github.com/ecomfe/awesome-echarts
[8]: https://nodei.co/npm/echarts-jsx/
[9]: https://echarts.apache.org/handbook/en/get-started/
[10]: https://codesandbox.io/p/devbox/5lknyg?migrateFrom=bouwsf&embed=1&file=%2Fsrc%2Fbar.tsx&showConsole=true
[10]: https://codesandbox.io/p/devbox/echarts-jsx-1-0-demo-h2dz8t?file=%2Fsrc%2FBar.tsx&embed=1
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-rc.5",
"version": "1.0.0",
"license": "LGPL-3.0",
"author": "[email protected]",
"description": "A real JSX wrapper for ECharts based on TypeScript & Web components",
Expand Down Expand Up @@ -66,7 +66,7 @@
"clean": "rimraf .parcel-cache/ dist/ docs/",
"preview": "npm run clean && cd preview/ && parcel --dist-dir=../docs/preview/",
"pack-preview": "rimraf .parcel-cache/ docs/preview/ && cd preview/ && parcel build --public-url=. --dist-dir=../docs/preview/",
"pack-dist": "rm -rf dist/ && tsc && microbundle --name EChartsJSX --globals lodash=_,echarts/core=echarts,echarts/charts=echarts,echarts/components=echarts,web-utility=WebUtility",
"pack-dist": "rm -rf dist/ && tsc && microbundle --name EChartsJSX --globals lodash=_,echarts/core=echarts,echarts/renderers=echarts,echarts/charts=echarts,echarts/components=echarts,web-utility=WebUtility",
"pack-docs": "rm -rf docs/ && typedoc source/",
"build": "npm run pack-dist && npm run pack-docs && npm run pack-preview",
"start": "npm run pack-docs && open-cli docs/index.html",
Expand Down
8 changes: 7 additions & 1 deletion source/Proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ export abstract class ProxyElement<T extends object> extends HTMLElement {
if (EventKeyPattern.test(key)) this.listen(eventName, value);
break;
default:
if (value != null) super.setAttribute(name, value + '');
if (value != null)
super.setAttribute(
name,
typeof value === 'string'
? value
: JSON.stringify(value)
);
else if (
EventKeyPattern.test(key) &&
typeof oldValue === 'function'
Expand Down
8 changes: 4 additions & 4 deletions source/charts/bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { use } from 'echarts/core';

import { ECOptionElement } from '../Option';

globalThis.customElements?.define(
'ec-bar-chart',
class ECBarElement extends ECOptionElement {}
);
use(BarChart);

export class ECBarChart extends ECOptionElement {}

globalThis.customElements?.define('ec-bar-chart', ECBarChart);

declare global {
namespace JSX {
interface IntrinsicElements {
Expand Down
8 changes: 4 additions & 4 deletions source/charts/boxplot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { use } from 'echarts/core';

import { ECOptionElement } from '../Option';

globalThis.customElements?.define(
'ec-boxplot-chart',
class ECBoxplotElement extends ECOptionElement {}
);
use(BoxplotChart);

export class ECBoxplotChart extends ECOptionElement {}

globalThis.customElements?.define('ec-boxplot-chart', ECBoxplotChart);

declare global {
namespace JSX {
interface IntrinsicElements {
Expand Down
8 changes: 4 additions & 4 deletions source/charts/candlestick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { use } from 'echarts/core';

import { ECOptionElement } from '../Option';

globalThis.customElements?.define(
'ec-candlestick-chart',
class ECCandlestickElement extends ECOptionElement {}
);
use(CandlestickChart);

export class ECCandlestickChart extends ECOptionElement {}

globalThis.customElements?.define('ec-candlestick-chart', ECCandlestickChart);

declare global {
namespace JSX {
interface IntrinsicElements {
Expand Down
8 changes: 4 additions & 4 deletions source/charts/custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { use } from 'echarts/core';

import { ECOptionElement } from '../Option';

globalThis.customElements?.define(
'ec-custom-chart',
class ECCustomElement extends ECOptionElement {}
);
use(CustomChart);

export class ECCustomChart extends ECOptionElement {}

globalThis.customElements?.define('ec-custom-chart', ECCustomChart);

declare global {
namespace JSX {
interface IntrinsicElements {
Expand Down
7 changes: 5 additions & 2 deletions source/charts/effect-scatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import { use } from 'echarts/core';

import { ECOptionElement } from '../Option';

use(EffectScatterChart);

export class ECEffectScatterChart extends ECOptionElement {}

globalThis.customElements?.define(
'ec-effect-scatter-chart',
class ECEffectScatterElement extends ECOptionElement {}
ECEffectScatterChart
);
use(EffectScatterChart);

declare global {
namespace JSX {
Expand Down
8 changes: 4 additions & 4 deletions source/charts/funnel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { use } from 'echarts/core';

import { ECOptionElement } from '../Option';

globalThis.customElements?.define(
'ec-funnel-chart',
class ECFunnelElement extends ECOptionElement {}
);
use(FunnelChart);

export class ECFunnelChart extends ECOptionElement {}

globalThis.customElements?.define('ec-funnel-chart', ECFunnelChart);

declare global {
namespace JSX {
interface IntrinsicElements {
Expand Down
8 changes: 4 additions & 4 deletions source/charts/gauge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { use } from 'echarts/core';

import { ECOptionElement } from '../Option';

globalThis.customElements?.define(
'ec-gauge-chart',
class ECGaugeElement extends ECOptionElement {}
);
use(GaugeChart);

export class ECGaugeChart extends ECOptionElement {}

globalThis.customElements?.define('ec-gauge-chart', ECGaugeChart);

declare global {
namespace JSX {
interface IntrinsicElements {
Expand Down
8 changes: 4 additions & 4 deletions source/charts/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { use } from 'echarts/core';

import { ECOptionElement } from '../Option';

globalThis.customElements?.define(
'ec-graph-chart',
class ECGraphElement extends ECOptionElement {}
);
use(GraphChart);

export class ECGraphChart extends ECOptionElement {}

globalThis.customElements?.define('ec-graph-chart', ECGraphChart);

declare global {
namespace JSX {
interface IntrinsicElements {
Expand Down
8 changes: 4 additions & 4 deletions source/charts/heatmap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { use } from 'echarts/core';

import { ECOptionElement } from '../Option';

globalThis.customElements?.define(
'ec-heatmap-chart',
class ECHeatmapElement extends ECOptionElement {}
);
use(HeatmapChart);

export class ECHeatmapChart extends ECOptionElement {}

globalThis.customElements?.define('ec-heatmap-chart', ECHeatmapChart);

declare global {
namespace JSX {
interface IntrinsicElements {
Expand Down
8 changes: 4 additions & 4 deletions source/charts/line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { use } from 'echarts/core';

import { ECOptionElement } from '../Option';

globalThis.customElements?.define(
'ec-line-chart',
class ECLineElement extends ECOptionElement {}
);
use(LineChart);

export class ECLineChart extends ECOptionElement {}

globalThis.customElements?.define('ec-line-chart', ECLineChart);

declare global {
namespace JSX {
interface IntrinsicElements {
Expand Down
8 changes: 4 additions & 4 deletions source/charts/lines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { use } from 'echarts/core';

import { ECOptionElement } from '../Option';

globalThis.customElements?.define(
'ec-lines-chart',
class ECLinesElement extends ECOptionElement {}
);
use(LinesChart);

export class ECLinesChart extends ECOptionElement {}

globalThis.customElements?.define('ec-lines-chart', ECLinesChart);

declare global {
namespace JSX {
interface IntrinsicElements {
Expand Down
8 changes: 4 additions & 4 deletions source/charts/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { use } from 'echarts/core';

import { ECOptionElement } from '../Option';

globalThis.customElements?.define(
'ec-map-chart',
class ECMapElement extends ECOptionElement {}
);
use(MapChart);

export class ECMapChart extends ECOptionElement {}

globalThis.customElements?.define('ec-map-chart', ECMapChart);

declare global {
namespace JSX {
interface IntrinsicElements {
Expand Down
8 changes: 4 additions & 4 deletions source/charts/parallel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { use } from 'echarts/core';

import { ECOptionElement } from '../Option';

globalThis.customElements?.define(
'ec-parallel-chart',
class ECParallelElement extends ECOptionElement {}
);
use(ParallelChart);

export class ECParallelChart extends ECOptionElement {}

globalThis.customElements?.define('ec-parallel-chart', ECParallelChart);

declare global {
namespace JSX {
interface IntrinsicElements {
Expand Down
7 changes: 5 additions & 2 deletions source/charts/pictorial-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import { use } from 'echarts/core';

import { ECOptionElement } from '../Option';

use(PictorialBarChart);

export class ECPictorialBarChart extends ECOptionElement {}

globalThis.customElements?.define(
'ec-pictorial-bar-chart',
class ECPictorialBarElement extends ECOptionElement {}
ECPictorialBarChart
);
use(PictorialBarChart);

declare global {
namespace JSX {
Expand Down
8 changes: 4 additions & 4 deletions source/charts/pie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { use } from 'echarts/core';

import { ECOptionElement } from '../Option';

globalThis.customElements?.define(
'ec-pie-chart',
class ECPieElement extends ECOptionElement {}
);
use(PieChart);

export class ECPieChart extends ECOptionElement {}

globalThis.customElements?.define('ec-pie-chart', ECPieChart);

declare global {
namespace JSX {
interface IntrinsicElements {
Expand Down
8 changes: 4 additions & 4 deletions source/charts/radar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { use } from 'echarts/core';

import { ECOptionElement } from '../Option';

globalThis.customElements?.define(
'ec-radar-chart',
class ECRadarElement extends ECOptionElement {}
);
use(RadarChart);

export class ECRadarChart extends ECOptionElement {}

globalThis.customElements?.define('ec-radar-chart', ECRadarChart);

declare global {
namespace JSX {
interface IntrinsicElements {
Expand Down
8 changes: 4 additions & 4 deletions source/charts/sankey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { use } from 'echarts/core';

import { ECOptionElement } from '../Option';

globalThis.customElements?.define(
'ec-sankey-chart',
class ECSankeyElement extends ECOptionElement {}
);
use(SankeyChart);

export class ECSankeyChart extends ECOptionElement {}

globalThis.customElements?.define('ec-sankey-chart', ECSankeyChart);

declare global {
namespace JSX {
interface IntrinsicElements {
Expand Down
Loading

1 comment on commit c5fdc25

@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-yai17fdq4-techquerys-projects.vercel.app

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

Please sign in to comment.