MCPcopy Create free account
hub / github.com/Make-md/makemd / parseVisualizationData

Function parseVisualizationData

src/core/utils/visualization/visualizationUtils.ts:12–150  ·  view source on GitHub ↗
(frame: MDBFrame)

Source from the content-addressed store, hash-verified

10 * Handles both old format (nested visualizationConfig) and new format (separate rows)
11 */
12export const parseVisualizationData = (frame: MDBFrame): VisualizationConfig => {
13 // Get data source and path from schema.def
14
15 // Find main row
16 const mainRow = frame.rows?.find(row => row.name === 'main');
17
18 if (!mainRow?.props) {
19 // Return default config if no main row
20 return createDefaultVisualizationConfig()
21 }
22
23 try {
24 const parsedProps = JSON.parse(mainRow.props);
25
26
27 // New format - build config from separate rows
28 const titleRow = frame.rows?.find(row => row.name === 'title');
29 const gridRow = frame.rows?.find(row => row.name === 'grid');
30 const xAxisRow = frame.rows?.find(row => row.name === 'x-axis');
31 const yAxisRow = frame.rows?.find(row => row.name === 'y-axis');
32 const legendRow = frame.rows?.find(row => row.name === 'legend');
33 const tooltipRow = frame.rows?.find(row => row.name === 'tooltip');
34
35
36 const config: VisualizationConfig = {
37 id: frame.schema?.id || '',
38 name: parsedProps.name || i18n.labels.visualization,
39 chartType: parsedProps.chartType || 'bar',
40 mark: {
41 type: parsedProps.chartType === 'line' ? 'line' :
42 parsedProps.chartType === 'scatter' ? 'circle' :
43 parsedProps.chartType === 'pie' ? 'arc' :
44 parsedProps.chartType === 'area' ? 'area' : 'rect',
45 fill: parsedProps.fill,
46 stroke: parsedProps.stroke,
47 strokeWidth: parsedProps.strokeWidth,
48 interpolate: parsedProps.interpolate,
49 innerRadius: parsedProps.innerRadius,
50 ...(parsedProps.pointShow !== undefined && {
51 point: {
52 show: parsedProps.pointShow,
53 size: parsedProps.pointSize || 4
54 }
55 })
56 },
57 encoding: {
58 x: parsedProps.xFields && parsedProps.xFields.length > 1
59 ? parsedProps.xFields.map((field: string) => ({
60 field,
61 type: parsedProps.xType || 'nominal',
62 ...(parsedProps.xAggregate && { aggregate: parsedProps.xAggregate }),
63 ...(parsedProps.xTimeUnit && { timeUnit: parsedProps.xTimeUnit })
64 }))
65 : {
66 field: parsedProps.xField || '',
67 type: parsedProps.xType || 'nominal',
68 ...(parsedProps.xAggregate && { aggregate: parsedProps.xAggregate }),
69 ...(parsedProps.xTimeUnit && { timeUnit: parsedProps.xTimeUnit })

Callers 2

VisualizationFunction · 0.90
FrameNodeEditorFunction · 0.90

Calls 3

parseMethod · 0.80
mapMethod · 0.45

Tested by

no test coverage detected