Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/theme converter #62

Merged
merged 17 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
301 changes: 242 additions & 59 deletions common/config/rush/pnpm-lock.yaml

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions packages/vchart-theme-converter/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require('@rushstack/eslint-patch/modern-module-resolution');

module.exports = {
extends: ['@internal/eslint-config/profile/lib'],
overrides: [
{
files: ['**/demo/**', '**/*.test.ts'],
plugins: ['react'],
// 测试文件允许以下规则
rules: {
'@typescript-eslint/no-empty-function': 'off',
'no-console': 'off',
'dot-notation': 'off',
'promise/catch-or-return': 'off'
}
}
],
parserOptions: { tsconfigRootDir: __dirname, project: './tsconfig.eslint.json' },
ignorePatterns: ['demo/**', 'bundler.config.js']
};
44 changes: 44 additions & 0 deletions packages/vchart-theme-converter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# @visactor/vchart-theme-converter

## Description

This plugin currently supports the mutual conversion between VChart themes and ECharts themes.
Currently supported features include():

- series theme config: line/area/bar/pie/funnel
- component theme config: axis/crosshair/tooltip/title/discreteLegend

It is important to note that the theme conversion tool cannot completely cover the visual differences between the two chart libraries.

## Usage

```typescript
import { echartsToVChart, vchartToEcharts } from '@visactor/vchart-theme-converter';
import { VChart } from '@visactor/vchart';


// convert echarts theme to vchart theme
{
const echartsTheme = {...}
const vchartTheme = echartsToVChart(echartsTheme);
}

// convert vchart runtime theme to echarts theme
{
const vchartTheme = VChart.ThemeManager.getCurrentTheme()
const echartsTheme = vchartToEcharts(echartsTheme);
}

// convert custom vchart theme to echarts theme
{
/**
* When registering a custom VChart theme, it merges with the default theme to form a complete theme
* configuration;
* Therefore, it is recommended to register the custom theme first and obtain the complete theme configuration
* before converting a custom VChart theme.
*/
const vchartTheme = {...};
VChart.ThemeManager.registerTheme('myTheme', vchartTheme);
const echartsTheme = vchartToEcharts(VChart.ThemeManager.getTheme('myTheme'));
}
```
13 changes: 13 additions & 0 deletions packages/vchart-theme-converter/bundler.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* @type {Partial<import('@dp/bundler').Config>}
*/
module.exports = {
formats: ['cjs', 'es', 'umd'],
outputDir: {
es: 'esm',
cjs: 'cjs',
umd: 'build'
},
name: 'VChartThemeConverter',
umdOutputFilename: 'index'
};
13 changes: 13 additions & 0 deletions packages/vchart-theme-converter/demo/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>VChart Theme Converter</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
Loading
Loading