MCPcopy Index your code
hub / github.com/zxlie/FeHelper / transformBubbleData

Function transformBubbleData

apps/chart-maker/chart-generator.js:1041–1064  ·  view source on GitHub ↗
(datasets)

Source from the content-addressed store, hash-verified

1039
1040// 辅助函数:转换气泡图数据
1041function transformBubbleData(datasets) {
1042 return datasets.map(dataset => {
1043 if (!dataset.data || !Array.isArray(dataset.data)) {
1044 return {
1045 ...dataset,
1046 data: []
1047 };
1048 }
1049
1050 return {
1051 ...dataset,
1052 data: dataset.data.map((value, index) => {
1053 // 确保value是一个有效的数值
1054 const y = parseFloat(value);
1055 if (isNaN(y)) {
1056 return { x: index + 1, y: 0, r: 5 };
1057 }
1058 // 气泡大小与值成比例
1059 const r = Math.max(5, Math.min(20, y / 10));
1060 return { x: index + 1, y: y, r: r };
1061 })
1062 };
1063 });
1064}
1065
1066/**
1067 * 初始化图表类型预览画廊

Callers 1

createChartFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected