diff --git a/src/components/charts/PlotConfigurator.vue b/src/components/charts/PlotConfigurator.vue
index 8fc560cc..86f9546e 100644
--- a/src/components/charts/PlotConfigurator.vue
+++ b/src/components/charts/PlotConfigurator.vue
@@ -73,7 +73,7 @@
@indicator-selected="addNewIndicatorSelected"
/>
-
+
-const { plotTemplateNames, applyPlotTemplate } = usePlotTemplates();
-
const visible = defineModel('visible');
+defineProps<{
+ columns: string[];
+}>();
+const { plotTemplateNames, applyPlotTemplate, getTemplateContent } = usePlotTemplates();
const plotStore = usePlotConfigStore();
function fromTemplateApply() {
if (selTemplateName.value) {
plotStore.editablePlotConfig = {
- ...applyPlotTemplate(selTemplateName.value, plotStore.editablePlotConfig),
+ ...applyPlotTemplate(selTemplateName.value, plotStore.editablePlotConfig, indicatorMap.value),
};
visible.value = false;
}
}
+
+function clickStartUseTemplate() {
+ showIndicatorMapping.value = !showIndicatorMapping.value;
+
+ indicatorMap.value = plotConfigColumns(getTemplateContent(selTemplateName.value)).reduce(
+ (acc, indicator) => {
+ acc[indicator] = indicator;
+ return acc;
+ },
+ {},
+ );
+}
+
const selTemplateName = ref('');
watch(
() => visible.value,
(v) => {
if (v) {
selTemplateName.value = '';
+ showIndicatorMapping.value = false;
}
},
);
+
+const indicatorMap = ref>({});
+const showIndicatorMapping = ref(false);
-
+
+
+
Re-map indicators
+
+
+ {{ indicator }}
+
+
+
+
+
+ Use Template
+
+
({
},
});
+function replaceTemplateColumns(template: Partial, nameMap: Record) {
+ // Replace column names in the template with the actual column names
+ // Replace the keys of all elements in main_plot
+ const newTemplate = deepClone(template);
+ if (!nameMap) {
+ return newTemplate;
+ }
+ const newMainPlot: Record = {};
+ for (const key in template.main_plot) {
+ const newKey = nameMap[key] || key;
+ newMainPlot[newKey] = template.main_plot[key];
+ }
+ newTemplate.main_plot = newMainPlot;
+
+ // Replace the keys of all elements in subplots
+ const newSubplots: Record = {};
+ for (const subplotKey in template.subplots) {
+ const newSubplot: Record = {};
+ for (const key in template.subplots[subplotKey]) {
+ const newKey = nameMap[key] || key;
+ newSubplot[newKey] = template.subplots[subplotKey][key];
+ }
+ newSubplots[subplotKey] = newSubplot;
+ }
+ newTemplate.subplots = newSubplots;
+ return newTemplate;
+}
+
export function usePlotTemplates() {
function getTemplateContent(templateName: string) {
return plotTemplates.value[templateName] || {};
}
- function applyPlotTemplate(templateName: string, currentConfig: PlotConfig) {
+ function applyPlotTemplate(
+ templateName: string,
+ currentConfig: PlotConfig,
+ nameMap: Record = {},
+ ) {
const template = getTemplateContent(templateName);
if (!template) {
return currentConfig;
}
- return deepMerge(currentConfig, template);
+ const newTemplate = replaceTemplateColumns(template, nameMap);
+ return deepMerge(currentConfig, newTemplate);
}
return {