Browse Source

use options in chartwerk

merge-requests/2/head
vargburz 3 years ago
parent
commit
7c0b9cd5b9
  1. 12
      src/components/Panel.tsx
  2. 30
      src/module.ts
  3. 8
      src/types.ts

12
src/components/Panel.tsx

@ -11,13 +11,16 @@ interface Props extends PanelProps<PanelOptions> {}
export function Panel({ options, data, width, height, timeZone, timeRange, onChangeTimeRange }: Props) { export function Panel({ options, data, width, height, timeZone, timeRange, onChangeTimeRange }: Props) {
let chartContainer = useRef(null); let chartContainer = useRef(null);
// TODO: use models to parse options and series
// we request animation frame here because at the moment we need an existing DOM-element at the moment we render the pod // we request animation frame here because at the moment we need an existing DOM-element at the moment we render the pod
window.requestAnimationFrame(() => { window.requestAnimationFrame(() => {
// TODO: pass datapoints // TODO: pass datapoints
// TODO: pass options // TODO: pass options
// TODO: switch / case pod type // TODO: switch / case pod type
const pod = new ChartwerkGaugePod((chartContainer as any).current, [ const pod = new ChartwerkGaugePod(
(chartContainer as any).current,
[
{ {
target: 'test', target: 'test',
datapoints: [ datapoints: [
@ -28,7 +31,12 @@ export function Panel({ options, data, width, height, timeZone, timeRange, onCha
[17, 25], [17, 25],
], ],
}, },
]); ],
{
maxValue: options.gauge.max,
minValue: options.gauge.min,
}
);
pod.render(); pod.render();
}); });
return ( return (

30
src/module.ts

@ -32,13 +32,39 @@ export const plugin = new PanelPlugin<PanelOptions>(Panel).setPanelOptions((buil
.addNumberInput({ .addNumberInput({
path: 'gauge.min', path: 'gauge.min',
name: 'Min', name: 'Min',
category: ['Gauge'], category: ['Extremum'],
showIf: (config) => config.visualizationType === Pod.GAUGE && !config.gauge.useMetricForMin,
})
.addFieldNamePicker({
name: 'Min',
path: 'gauge.minMetricName',
category: ['Extremum'],
showIf: (config) => config.visualizationType === Pod.GAUGE && config.gauge.useMetricForMin,
})
.addBooleanSwitch({
path: 'gauge.useMetricForMin',
name: 'Use metric',
defaultValue: false,
category: ['Extremum'],
showIf: (config) => config.visualizationType === Pod.GAUGE, showIf: (config) => config.visualizationType === Pod.GAUGE,
}) })
.addNumberInput({ .addNumberInput({
path: 'gauge.max', path: 'gauge.max',
name: 'Max', name: 'Max',
category: ['Gauge'], category: ['Extremum'],
showIf: (config) => config.visualizationType === Pod.GAUGE && !config.gauge.useMetricForMax,
})
.addFieldNamePicker({
name: 'Max',
path: 'gauge.maxMetricName',
category: ['Extremum'],
showIf: (config) => config.visualizationType === Pod.GAUGE && config.gauge.useMetricForMax,
})
.addBooleanSwitch({
path: 'gauge.useMetricForMax',
name: 'Use metric',
defaultValue: false,
category: ['Extremum'],
showIf: (config) => config.visualizationType === Pod.GAUGE, showIf: (config) => config.visualizationType === Pod.GAUGE,
}); });
}); });

8
src/types.ts

@ -1,8 +1,12 @@
export interface PanelOptions { export interface PanelOptions {
visualizationType: Pod; visualizationType: Pod;
gauge: { gauge: {
min: number | null; min?: number;
max: number | null; useMetricForMin: boolean;
minMetricName: string;
max?: number;
useMetricForMax: boolean;
maxMetricName: string;
}; };
} }

Loading…
Cancel
Save