MCPcopy Index your code
hub / github.com/chartbrew/chartbrew / createChart

Function createChart

server/modules/ai/orchestrator/tools/createChart.js:25–196  ·  view source on GitHub ↗
(payload)

Source from the content-addressed store, hash-verified

23}
24
25async function createChart(payload) {
26 let {
27 project_id, dataset_id, spec, team_id,
28 name, legend, type, subType, displayLegend, pointRadius,
29 dataLabels, includeZeros, timeInterval, stacked, horizontal,
30 xLabelTicks, showGrowth, invertGrowth, mode, maxValue, minValue, ranges,
31 xAxis, xAxisOperation, yAxis, yAxisOperation, dateField, dateFormat,
32 conditions, formula, seriesConfiguration,
33 } = payload;
34
35 if (!project_id) {
36 throw new Error("project_id is required to create a chart");
37 }
38
39 if (!name) {
40 throw new Error("name is required to create a chart");
41 }
42
43 if (!team_id) {
44 throw new Error("team_id is required to create a chart");
45 }
46
47 // Provide default chart spec if not provided
48 const defaultSpec = {
49 type: "line",
50 title: "AI Generated Chart",
51 timeInterval: "day",
52 chartSize: 2,
53 displayLegend: true,
54 pointRadius: 0,
55 dataLabels: false,
56 includeZeros: true,
57 stacked: false,
58 horizontal: false,
59 xLabelTicks: "default",
60 showGrowth: false,
61 invertGrowth: false,
62 mode: "chart",
63 options: {}
64 };
65
66 let chartSpec = spec || defaultSpec;
67
68 try {
69 // Get the dataset to get its legend for default values
70 const normalizedTeamId = normalizeTeamId(team_id);
71 const dataset = await requireDatasetForTeam(dataset_id, normalizedTeamId);
72 let dataRequest = null;
73 if (Array.isArray(dataset.DataRequests) && dataset.DataRequests.length > 0) {
74 dataRequest = dataset.DataRequests[0];
75 } else if (dataset.main_dr_id) {
76 dataRequest = await db.DataRequest.findByPk(dataset.main_dr_id);
77 } else {
78 dataRequest = await db.DataRequest.findOne({ where: { dataset_id } });
79 }
80 const chartSanitization = removeCompiledMetricAccumulation({
81 configuration: dataRequest?.configuration,
82 type,

Callers 1

callToolFunction · 0.50

Calls 9

normalizeTeamIdFunction · 0.85
requireDatasetForTeamFunction · 0.85
requireProjectForTeamFunction · 0.85
getDatasetNameFunction · 0.85
resolveXAxisFunction · 0.70
updateMethod · 0.45
takeSnapshotMethod · 0.45

Tested by

no test coverage detected