Dashboard final version, TODO: update main sidebar menu
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
// Chart interface and context helpers
|
||||
// This is a fresh, original implementation inspired conceptually by patterns
|
||||
// observed in external registries. No code copied.
|
||||
|
||||
import { inject, provide, reactive } from 'vue';
|
||||
|
||||
/**
|
||||
* @typedef {Object} ChartSeriesConfig
|
||||
* @property {string|import('vue').Component} [label] Display label or component
|
||||
* @property {import('vue').Component} [icon] Optional icon component
|
||||
* @property {string} [color] Static CSS color value (e.g. 'var(--chart-1)')
|
||||
* @property {Object} [theme] Optional theme map: { light: string, dark: string }
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object.<string, ChartSeriesConfig>} ChartConfig
|
||||
* Keys are series identifiers. Each value declares label/icon and either a
|
||||
* static color or a theme object with light/dark variants.
|
||||
*/
|
||||
|
||||
const ChartContextSymbol = Symbol('ChartContext');
|
||||
let _idCounter = 0;
|
||||
|
||||
/**
|
||||
* Provide chart context for descendants.
|
||||
* @param {ChartConfig} config Reactive or plain config object.
|
||||
* @param {string} [explicitId] Optional id override.
|
||||
* @returns {{ id: string, config: ChartConfig }}
|
||||
*/
|
||||
export function provideChartContext(config, explicitId) {
|
||||
const id = explicitId || `c${Date.now().toString(36)}${(++_idCounter).toString(36)}`;
|
||||
const ctx = { id, config: reactive(config) };
|
||||
provide(ChartContextSymbol, ctx);
|
||||
return ctx;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inject previously provided chart context.
|
||||
* @returns {{ id: string, config: ChartConfig }}
|
||||
*/
|
||||
export function useChartContext() {
|
||||
const ctx = inject(ChartContextSymbol, null);
|
||||
if (!ctx) {
|
||||
throw new Error('useChartContext() called without a provider. Wrap in <ChartContainer>.');
|
||||
}
|
||||
return ctx;
|
||||
}
|
||||
|
||||
export {}; // preserve module boundaries
|
||||
Reference in New Issue
Block a user