Skip to content

Commit b9bcf84

Browse files
authored
Merge pull request #290 from yatbfm/dev/optimize-generate-chart
feat: add prompt for waterfall and rangeColumn
2 parents c432f12 + c48858c commit b9bcf84

File tree

5 files changed

+30
-9
lines changed

5 files changed

+30
-9
lines changed

packages/generate-vchart/src/transformers/bar.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ export const colorBar = (context: GenerateChartInput) => {
5151
const colorThemes = COLOR_THEMES.default;
5252

5353
spec.color = colorThemes.slice();
54+
} else if ('palette' in context && context.palette) {
55+
spec.color = context.palette;
5456
} else {
5557
const colorThemes = COLOR_THEMES.default;
5658
//apply transparent gradient

packages/generate-vchart/src/transformers/cartesian.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ export const seriesField = (context: GenerateChartInput) => {
5050

5151
export const axis = (context: GenerateChartInput) => {
5252
const { spec, cell, fieldInfo, axes, transpose } = context;
53-
// 现在只有柱图和rangeColumn 支持了转置
54-
const validTranspose = transpose && (spec.type === 'bar' || spec.type === 'rangeColumn');
53+
// 现在只有柱图 rangeColumn 瀑布图 支持了转置
54+
const validTranspose = transpose && (spec.type === 'bar' || spec.type === 'rangeColumn' || spec.type === 'waterfall');
5555
const bandAxisOrient = validTranspose ? 'left' : 'bottom';
5656
const linearAxisOrient = validTranspose ? 'bottom' : 'left';
5757

packages/generate-vchart/src/transformers/waterfall.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ import { color, data, discreteLegend, formatXFields, labelForDefaultHide } from
55

66
export const waterfallField = (context: GenerateChartInput) => {
77
//assign field in spec according to cell
8-
const { cell, spec, waterfallTotal } = context;
9-
spec.xField = cell.x;
10-
spec.yField = cell.y;
8+
const { cell, spec, waterfallTotal, transpose } = context;
9+
spec.xField = transpose ? cell.y : cell.x;
10+
spec.yField = transpose ? cell.x : cell.y;
11+
if (transpose) {
12+
spec.direction = 'horizontal';
13+
}
1114

1215
if (waterfallTotal?.visible !== false) {
1316
spec.total = {

packages/vmind/src/atom/chartGenerator/rule/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@ const formatDataTable = (simpleVChartSpec: SimpleVChartSpec, data: DataTable) =>
7777
value1: arr[1]
7878
};
7979
});
80+
} else if (type === 'waterfall') {
81+
const finalData = [];
82+
for (let i = data.length - 1; i >= 0; i--) {
83+
if (i === 0 || i === data.length - 1) {
84+
finalData.push({ name: data[i].name, value: data[i].value });
85+
} else {
86+
finalData.push({ name: data[i].name, value: Number(data[i].value) - Number(data[i - 1].value) });
87+
}
88+
}
89+
finalData.reverse();
90+
return finalData;
8091
}
8192

8293
return data;
@@ -104,6 +115,8 @@ export const getContextBySimpleVChartSpec = (simpleVChartSpec: SimpleVChartSpec)
104115
: originalSeries?.[0]?.type === 'bar' && coordinate === 'polar'
105116
? 'rose'
106117
: originalSeries?.[0]?.type ?? type
118+
: type === 'bar' && 'value' in data[0] && 'value1' in data[0]
119+
? 'rangeColumn'
107120
: type;
108121

109122
let series = originalSeries;

packages/vmind/src/atom/imageReader/prompt.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ When executing the task, you need to meet the following requirements:
1010
1. You must first determine the type before proceeding, and the type must be one of the following:
1111
"common"|"area"|"line"|"bar"|"rangeColumn"|"rangeArea"|"map"|"pie"|"radar"|"rose"|"scatter"|"sequence"|"circularProgress"|"linearProgress"|"wordCloud"|"funnel"|"waterfall"|"boxPlot"|"gauge"|"sankey"|"treemap"|"sunburst"|"circlePacking"|"heatmap"|"liquid"|"venn"|"mosaic"|"bidirectionalBar"
1212
2. Only return JSON that can be used to recreate the chart
13-
3. If the image is a composite chart, return the type as 'common'. All data for composite charts must be returned through the series field, not placed in the top-level data field
14-
4. If all series in a composite chart are unidirectional bar charts, return the type as 'bar'; if the image is symmetrically distributed on both sides, must return the type as 'bidirectionalBar'
15-
5. You should pay attention to distinguish radar chart and rose chart
16-
6. If the type is treemap, the background color of each block needs to be used as the group value
13+
3. If this is a bar chart (type is 'bar'), with dashed lines connecting each bar, and different colors between bars indicating increase or decrease relationships, then the type should be returned as 'waterfall'.If the bars are arranged horizontally, return transpose as true.
14+
4. If the chart is a bar chart (type is 'bar') and the starting points of each bar are not aligned (i.e., not starting from 0), then each bar needs to return the corresponding starting and ending values, which are 'value' and 'value1' respectively.
15+
5. If the image is a composite chart, return the type as 'common'. All data for composite charts must be returned through the series field, not placed in the top-level data field
16+
6. If all series in a composite chart are unidirectional bar charts, return the type as 'bar'; if the image is symmetrically distributed on both sides, must return the type as 'bidirectionalBar'
17+
7. You should pay attention to distinguish radar chart and rose chart
18+
8. If the type is treemap, the background color of each block needs to be used as the group value
19+
9. For the type property of each element object in the axes field, it must be 'band' or 'linear'
1720
1821
# Answer
1922
\`\`\`

0 commit comments

Comments
 (0)