feat: Add initial plotTemplates composable

This commit is contained in:
Matthias 2024-07-18 20:13:50 +02:00
parent c33655951b
commit c3764d1a73
3 changed files with 51 additions and 0 deletions

View File

@ -277,6 +277,7 @@ declare global {
const usePerformanceObserver: typeof import('@vueuse/core')['usePerformanceObserver'] const usePerformanceObserver: typeof import('@vueuse/core')['usePerformanceObserver']
const usePermission: typeof import('@vueuse/core')['usePermission'] const usePermission: typeof import('@vueuse/core')['usePermission']
const usePlotConfigStore: typeof import('./stores/plotConfig')['usePlotConfigStore'] const usePlotConfigStore: typeof import('./stores/plotConfig')['usePlotConfigStore']
const usePlotTemplates: typeof import('./composables/plotTemplates')['usePlotTemplates']
const usePointer: typeof import('@vueuse/core')['usePointer'] const usePointer: typeof import('@vueuse/core')['usePointer']
const usePointerLock: typeof import('@vueuse/core')['usePointerLock'] const usePointerLock: typeof import('@vueuse/core')['usePointerLock']
const usePointerSwipe: typeof import('@vueuse/core')['usePointerSwipe'] const usePointerSwipe: typeof import('@vueuse/core')['usePointerSwipe']
@ -645,6 +646,7 @@ declare module 'vue' {
readonly usePerformanceObserver: UnwrapRef<typeof import('@vueuse/core')['usePerformanceObserver']> readonly usePerformanceObserver: UnwrapRef<typeof import('@vueuse/core')['usePerformanceObserver']>
readonly usePermission: UnwrapRef<typeof import('@vueuse/core')['usePermission']> readonly usePermission: UnwrapRef<typeof import('@vueuse/core')['usePermission']>
readonly usePlotConfigStore: UnwrapRef<typeof import('./stores/plotConfig')['usePlotConfigStore']> readonly usePlotConfigStore: UnwrapRef<typeof import('./stores/plotConfig')['usePlotConfigStore']>
readonly usePlotTemplates: UnwrapRef<typeof import('./composables/plotTemplates')['usePlotTemplates']>
readonly usePointer: UnwrapRef<typeof import('@vueuse/core')['usePointer']> readonly usePointer: UnwrapRef<typeof import('@vueuse/core')['usePointer']>
readonly usePointerLock: UnwrapRef<typeof import('@vueuse/core')['usePointerLock']> readonly usePointerLock: UnwrapRef<typeof import('@vueuse/core')['usePointerLock']>
readonly usePointerSwipe: UnwrapRef<typeof import('@vueuse/core')['usePointerSwipe']> readonly usePointerSwipe: UnwrapRef<typeof import('@vueuse/core')['usePointerSwipe']>
@ -997,6 +999,7 @@ declare module '@vue/runtime-core' {
readonly usePerformanceObserver: UnwrapRef<typeof import('@vueuse/core')['usePerformanceObserver']> readonly usePerformanceObserver: UnwrapRef<typeof import('@vueuse/core')['usePerformanceObserver']>
readonly usePermission: UnwrapRef<typeof import('@vueuse/core')['usePermission']> readonly usePermission: UnwrapRef<typeof import('@vueuse/core')['usePermission']>
readonly usePlotConfigStore: UnwrapRef<typeof import('./stores/plotConfig')['usePlotConfigStore']> readonly usePlotConfigStore: UnwrapRef<typeof import('./stores/plotConfig')['usePlotConfigStore']>
readonly usePlotTemplates: UnwrapRef<typeof import('./composables/plotTemplates')['usePlotTemplates']>
readonly usePointer: UnwrapRef<typeof import('@vueuse/core')['usePointer']> readonly usePointer: UnwrapRef<typeof import('@vueuse/core')['usePointer']>
readonly usePointerLock: UnwrapRef<typeof import('@vueuse/core')['usePointerLock']> readonly usePointerLock: UnwrapRef<typeof import('@vueuse/core')['usePointerLock']>
readonly usePointerSwipe: UnwrapRef<typeof import('@vueuse/core')['usePointerSwipe']> readonly usePointerSwipe: UnwrapRef<typeof import('@vueuse/core')['usePointerSwipe']>

View File

@ -0,0 +1,44 @@
import { ChartType, PlotConfig, PlotConfigTemplate } from '@/types';
const plotTemplates: PlotConfigTemplate = {
RSI: {
subplots: {
RSI: {
rsi: {
color: 'orange',
type: ChartType.line,
},
},
},
},
MACD: {
subplots: {
MACD: {
macdsignal: {
color: 'orange',
type: ChartType.line,
},
macd: {
color: 'blue',
type: ChartType.line,
},
},
},
},
};
export function usePlotTemplates() {
function applyPlotTemplate(templateName: string, currentConfig: PlotConfig) {
const template = plotTemplates[templateName];
if (!template) {
return currentConfig;
}
return deepMerge(currentConfig, template);
}
return {
plotTemplates,
applyPlotTemplate,
plotTemplateNames: Object.keys(plotTemplates),
};
}

View File

@ -19,4 +19,8 @@ export interface PlotConfigStorage {
[key: string]: PlotConfig; [key: string]: PlotConfig;
} }
export interface PlotConfigTemplate {
[key: string]: Partial<PlotConfig>;
}
export const EMPTY_PLOTCONFIG: PlotConfig = { main_plot: {}, subplots: {} }; export const EMPTY_PLOTCONFIG: PlotConfig = { main_plot: {}, subplots: {} };