Skip to content

Commit

Permalink
fix: 调研Echarts插件
Browse files Browse the repository at this point in the history
  • Loading branch information
ldq1220 committed Dec 13, 2024
1 parent d39f4d9 commit d6b00d5
Show file tree
Hide file tree
Showing 23 changed files with 813 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/plugins/@gemel/plugin-add-custom-charts/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/node_modules
/src
1 change: 1 addition & 0 deletions packages/plugins/@gemel/plugin-add-custom-charts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# @gemel/plugin-add-custom-charts
2 changes: 2 additions & 0 deletions packages/plugins/@gemel/plugin-add-custom-charts/client.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './dist/client';
export { default } from './dist/client';
1 change: 1 addition & 0 deletions packages/plugins/@gemel/plugin-add-custom-charts/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./dist/client/index.js');
19 changes: 19 additions & 0 deletions packages/plugins/@gemel/plugin-add-custom-charts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "@gemel/plugin-add-custom-charts",
"version": "1.4.0-alpha.15",
"main": "dist/server/index.js",
"displayName": "Add Custom Charts",
"displayName.zh-CN": "添加自定义图表",
"description": "Add custom charts",
"description.zh-CN": "添加自定义图表",
"peerDependencies": {
"@nocobase/client": "1.x",
"@nocobase/server": "1.x",
"@nocobase/test": "1.x"
},
"devDependencies": {
"deepmerge": "^4.3.1",
"echarts": "^5.5.1",
"echarts-for-react": "^3.0.2"
}
}
2 changes: 2 additions & 0 deletions packages/plugins/@gemel/plugin-add-custom-charts/server.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './dist/server';
export { default } from './dist/server';
1 change: 1 addition & 0 deletions packages/plugins/@gemel/plugin-add-custom-charts/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./dist/server/index.js');
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
/**
* This file is part of the NocoBase (R) project.
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
* Authors: NocoBase Team.
*
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
* For more information, please refer to: https://www.nocobase.com/agreement.
*/

// CSS modules
type CSSModuleClasses = { readonly [key: string]: string };

declare module '*.module.css' {
const classes: CSSModuleClasses;
export default classes;
}
declare module '*.module.scss' {
const classes: CSSModuleClasses;
export default classes;
}
declare module '*.module.sass' {
const classes: CSSModuleClasses;
export default classes;
}
declare module '*.module.less' {
const classes: CSSModuleClasses;
export default classes;
}
declare module '*.module.styl' {
const classes: CSSModuleClasses;
export default classes;
}
declare module '*.module.stylus' {
const classes: CSSModuleClasses;
export default classes;
}
declare module '*.module.pcss' {
const classes: CSSModuleClasses;
export default classes;
}
declare module '*.module.sss' {
const classes: CSSModuleClasses;
export default classes;
}

// CSS
declare module '*.css' { }
declare module '*.scss' { }
declare module '*.sass' { }
declare module '*.less' { }
declare module '*.styl' { }
declare module '*.stylus' { }
declare module '*.pcss' { }
declare module '*.sss' { }

// Built-in asset types
// see `src/node/constants.ts`

// images
declare module '*.apng' {
const src: string;
export default src;
}
declare module '*.png' {
const src: string;
export default src;
}
declare module '*.jpg' {
const src: string;
export default src;
}
declare module '*.jpeg' {
const src: string;
export default src;
}
declare module '*.jfif' {
const src: string;
export default src;
}
declare module '*.pjpeg' {
const src: string;
export default src;
}
declare module '*.pjp' {
const src: string;
export default src;
}
declare module '*.gif' {
const src: string;
export default src;
}
declare module '*.svg' {
const src: string;
export default src;
}
declare module '*.ico' {
const src: string;
export default src;
}
declare module '*.webp' {
const src: string;
export default src;
}
declare module '*.avif' {
const src: string;
export default src;
}

// media
declare module '*.mp4' {
const src: string;
export default src;
}
declare module '*.webm' {
const src: string;
export default src;
}
declare module '*.ogg' {
const src: string;
export default src;
}
declare module '*.mp3' {
const src: string;
export default src;
}
declare module '*.wav' {
const src: string;
export default src;
}
declare module '*.flac' {
const src: string;
export default src;
}
declare module '*.aac' {
const src: string;
export default src;
}
declare module '*.opus' {
const src: string;
export default src;
}
declare module '*.mov' {
const src: string;
export default src;
}
declare module '*.m4a' {
const src: string;
export default src;
}
declare module '*.vtt' {
const src: string;
export default src;
}

// fonts
declare module '*.woff' {
const src: string;
export default src;
}
declare module '*.woff2' {
const src: string;
export default src;
}
declare module '*.eot' {
const src: string;
export default src;
}
declare module '*.ttf' {
const src: string;
export default src;
}
declare module '*.otf' {
const src: string;
export default src;
}

// other
declare module '*.webmanifest' {
const src: string;
export default src;
}
declare module '*.pdf' {
const src: string;
export default src;
}
declare module '*.txt' {
const src: string;
export default src;
}

// wasm?init
declare module '*.wasm?init' {
const initWasm: (options?: WebAssembly.Imports) => Promise<WebAssembly.Instance>;
export default initWasm;
}

// web worker
declare module '*?worker' {
const workerConstructor: {
new(options?: { name?: string }): Worker;
};
export default workerConstructor;
}

declare module '*?worker&inline' {
const workerConstructor: {
new(options?: { name?: string }): Worker;
};
export default workerConstructor;
}

declare module '*?worker&url' {
const src: string;
export default src;
}

declare module '*?sharedworker' {
const sharedWorkerConstructor: {
new(options?: { name?: string }): SharedWorker;
};
export default sharedWorkerConstructor;
}

declare module '*?sharedworker&inline' {
const sharedWorkerConstructor: {
new(options?: { name?: string }): SharedWorker;
};
export default sharedWorkerConstructor;
}

declare module '*?sharedworker&url' {
const src: string;
export default src;
}

declare module '*?raw' {
const src: string;
export default src;
}

declare module '*?url' {
const src: string;
export default src;
}

declare module '*?inline' {
const src: string;
export default src;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* This file is part of the NocoBase (R) project.
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
* Authors: NocoBase Team.
*
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
* For more information, please refer to: https://www.nocobase.com/agreement.
*/

import React, { useEffect } from 'react';
import ReactEChartsComponent, { EChartsInstance, EChartsReactProps } from 'echarts-for-react';

export const ReactECharts = (props: EChartsReactProps['option']) => {
const echartRef = React.useRef<EChartsInstance>();
useEffect(() => {
echartRef.current?.resize();
});
return <ReactEChartsComponent option={props} ref={(e) => (echartRef.current = e)} />;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* This file is part of the NocoBase (R) project.
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
* Authors: NocoBase Team.
*
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
* For more information, please refer to: https://www.nocobase.com/agreement.
*/

import { RenderProps } from '@nocobase/plugin-data-visualization/client';
import { ECharts } from './echarts';

export class Bar extends ECharts {
constructor() {
super({
name: 'bar',
title: 'Bar Chart',
series: { type: 'bar' },
});
this.config = [
{
configType: 'field',
title: 'xField',
},
{
configType: 'field',
title: 'yField',
},
'seriesField',
];
}

getProps({ data, general, advanced, fieldProps }: RenderProps) {
const props = super.getProps({ data, general, advanced, fieldProps });
const xLabel = fieldProps[general.xField]?.label;
const yLabel = fieldProps[general.yField]?.label;
props.xAxis = {
...props.xAxis,
type: 'value',
name: xLabel,
};
props.yAxis = {
...props.yAxis,
name: yLabel,
};

return props;
}
}

new Bar();
Loading

0 comments on commit d6b00d5

Please sign in to comment.