This is an automated email from the ASF dual-hosted git repository.
ovilia pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/echarts-from-mermaid.git
The following commit(s) were added to refs/heads/main by this push:
new 8e8fabe fix: pie
8e8fabe is described below
commit 8e8fabe9c0943708d606ae1599b38fe81779bde7
Author: Ovilia <[email protected]>
AuthorDate: Fri Feb 28 18:40:25 2025 +0800
fix: pie
---
src/index.ts | 6 +++---
src/mermaid/pie/PieParser.ts | 10 ++++++++--
src/types.ts | 16 +++++++++++-----
3 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/src/index.ts b/src/index.ts
index 0215cfa..b451bc4 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,11 +1,9 @@
import { PieParser } from './mermaid/pie/PieParser';
import { PieChart } from './mermaid/pie/PieChart';
-import type { ChartDefinition } from './types';
+import type { ChartDefinition, ChartType } from './types';
import { XYChartParser } from './mermaid/xy/XYChartParser';
import { XYChart } from './mermaid/xy/XYChart';
-type ChartType = 'pie' | 'xychart-beta';
-
export class EChartsFromMermaid {
static getOption(definition: string) {
// 1. Parse mermaid text
@@ -22,6 +20,7 @@ export class EChartsFromMermaid {
private static getParser(type: ChartType) {
const parsers: Record<ChartType, PieParser | XYChartParser> = {
pie: new PieParser(),
+ xychart: new XYChartParser(),
'xychart-beta': new XYChartParser(),
};
return parsers[type];
@@ -30,6 +29,7 @@ export class EChartsFromMermaid {
private static getChart(type: ChartType, chartDef: ChartDefinition) {
const charts: Record<ChartType, PieChart | XYChart> = {
pie: new PieChart(chartDef),
+ xychart: new XYChart(chartDef),
'xychart-beta': new XYChart(chartDef),
};
return charts[type];
diff --git a/src/mermaid/pie/PieParser.ts b/src/mermaid/pie/PieParser.ts
index ca5f385..8817ce9 100644
--- a/src/mermaid/pie/PieParser.ts
+++ b/src/mermaid/pie/PieParser.ts
@@ -4,16 +4,22 @@ import type { ChartDefinition } from '../../types';
export class PieParser extends BaseParser {
parse(definition: string): ChartDefinition {
const lines = definition.trim().split('\n');
- const { type, title } = this.parseFirstLine(lines[0]);
+ const { title } = this.parseFirstLine(lines[0]);
const data = lines.slice(1).map((line) => {
const [name, value] = line.split(':').map((s) => s.trim());
return {
+ seriesType: 'pie',
name: name.replace(/"/g, ''),
value: Number(value),
};
});
- return { type, title, data };
+ return {
+ type: 'pie',
+ series: [{ type: 'pie', data }],
+ title,
+ data,
+ };
}
}
diff --git a/src/types.ts b/src/types.ts
index c3360cf..2f0e149 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -1,10 +1,16 @@
-export type ChartType = 'xychart-beta' | 'pie';
+import type {
+ SeriesOption,
+ XAXisComponentOption,
+ YAXisComponentOption,
+} from 'echarts';
+
+export type ChartType = 'pie' | 'xychart' | 'xychart-beta';
export interface ChartDefinition {
type: string;
title?: string;
- data: Array<{
- name: string;
- value: number;
- }>;
+ data: any[];
+ series: SeriesOption[];
+ xAxis?: XAXisComponentOption;
+ yAxis?: YAXisComponentOption;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]