(
instruction: string,
mode: 'formulate' | 'ideate' = 'formulate',
overrideTableId?: string,
)
| 607 | |
| 608 | |
| 609 | let deriveNewData = async ( |
| 610 | instruction: string, |
| 611 | mode: 'formulate' | 'ideate' = 'formulate', |
| 612 | overrideTableId?: string, |
| 613 | ) => { |
| 614 | |
| 615 | if (actionTableIds.length == 0) return; |
| 616 | |
| 617 | // Short-circuit: if all fields exist in source table, just reference it |
| 618 | if (currentTable.derive == undefined && instruction == "" && |
| 619 | (activeFields.length > 0 && activeCustomFields.length == 0) && |
| 620 | tables.some(t => t.derive == undefined && |
| 621 | activeFields.every(f => currentTable.names.includes(f.name)))) { |
| 622 | let tempTable = getDataTable(chart, tables, allCharts, conceptShelfItems, true); |
| 623 | dispatch(dfActions.updateTableRef({chartId: chartId, tableRef: tempTable.id})); |
| 624 | dispatch(dfActions.changeChartRunningStatus({chartId, status: true})); |
| 625 | setTimeout(function(){ |
| 626 | dispatch(dfActions.changeChartRunningStatus({chartId, status: false})); |
| 627 | dispatch(dfActions.clearUnReferencedTables()); |
| 628 | }, 400); |
| 629 | return; |
| 630 | } |
| 631 | |
| 632 | dispatch(dfActions.clearUnReferencedTables()); |
| 633 | |
| 634 | let fieldNamesStr = activeFields.map(f => f.name).reduce( |
| 635 | (a: string, b: string, i, array) => a + (i == 0 ? "" : (i < array.length - 1 ? ', ' : ' and ')) + b, ""); |
| 636 | |
| 637 | const actionId = `deriveNewData_${String(Date.now())}`; |
| 638 | const originTableId = focusedTableId || currentTable.id; |
| 639 | const actionDescription = instruction || `Derive ${fieldNamesStr}`; |
| 640 | |
| 641 | // Build chart visualization context |
| 642 | let chartComplete = checkChartAvailability(chart, conceptShelfItems, currentTable.rows); |
| 643 | let chartSpec = (mode == 'formulate' && Object.keys(activeSimpleEncodings).length > 0) ? { |
| 644 | chart_type: chart.chartType, |
| 645 | encodings: activeSimpleEncodings, |
| 646 | ...(chart.config ? { config: chart.config } : {}) |
| 647 | } : undefined; |
| 648 | |
| 649 | let currentChartImage: string | null | undefined = undefined; |
| 650 | if (chartComplete && chartSpec) { |
| 651 | currentChartImage = await vegaLiteSpecToPng(assembleVegaChart( |
| 652 | chart.chartType, chart.encodingMap, activeFields, currentTable.rows, |
| 653 | currentTable.metadata, 100, 80, false, chart.config |
| 654 | )); |
| 655 | if (currentChartImage) { |
| 656 | currentChartImage = await downscaleImageForAgent(currentChartImage); |
| 657 | } |
| 658 | } |
| 659 | |
| 660 | let currentVisualization = (chartComplete && chartSpec) ? { |
| 661 | chart_spec: chartSpec, |
| 662 | ...(currentChartImage ? { chart_image: currentChartImage } : {}) |
| 663 | } : undefined; |
| 664 | let expectedVisualization = (!chartComplete && chartSpec) ? { chart_spec: chartSpec } : undefined; |
| 665 | |
| 666 | let triggerChartSpec = duplicateChart(chart); |
no test coverage detected