Browse Source

legend

pull/2/head
vargburz 2 years ago
parent
commit
6edc81df09
  1. 24
      src/components/Panel.tsx

24
src/components/Panel.tsx

@ -26,7 +26,6 @@ export function Panel({ options, data, width, height, timeRange, onChangeTimeRan
// we request animation frame here because we need an existing DOM-element at the moment we render the pod // we request animation frame here because we need an existing DOM-element at the moment we render the pod
window.requestAnimationFrame(() => { window.requestAnimationFrame(() => {
console.log('pod', options.visualizationType);
let pod; let pod;
switch (options.visualizationType) { switch (options.visualizationType) {
case Pod.GAUGE: case Pod.GAUGE:
@ -37,7 +36,6 @@ export function Panel({ options, data, width, height, timeRange, onChangeTimeRan
case Pod.BAR: case Pod.BAR:
const barSeries = new BarSeries(grafanaSeriesList).getChartwerkSeries(); const barSeries = new BarSeries(grafanaSeriesList).getChartwerkSeries();
const chartwerkBarOptions = new BarOptions(grafanaSeriesList, onChangeTimeRange).getChartwerkOptions(); const chartwerkBarOptions = new BarOptions(grafanaSeriesList, onChangeTimeRange).getChartwerkOptions();
console.log('data', barSeries, chartwerkBarOptions);
pod = new ChartwerkBarPod((chartContainer as any).current, barSeries, chartwerkBarOptions); pod = new ChartwerkBarPod((chartContainer as any).current, barSeries, chartwerkBarOptions);
break; break;
default: default:
@ -54,26 +52,28 @@ export function Panel({ options, data, width, height, timeRange, onChangeTimeRan
} }
window.open(options.gauge.link, '_self'); window.open(options.gauge.link, '_self');
}; };
const legendItems = [ const legendItems = _.map(grafanaSeriesList, (serie) => {
{ label: 'metric1', yAxis: 100, color: 'red' }, return {
{ label: 'metric2', yAxis: 200, color: 'green' }, label: serie.alias,
]; color: serie.color,
yAxis: 1,
};
});
const chartHeight = options.visualizationType !== Pod.GAUGE ? height - 20 : height;
return ( return (
<div> <div>
<div <div
ref={chartContainer} ref={chartContainer}
className={css` className={css`
width: ${width}px; width: ${width}px;
height: ${height- 20}px; height: ${chartHeight}px;
cursor: ${isLinkActive ? 'pointer' : 'default'}; cursor: ${isLinkActive ? 'pointer' : 'default'};
`} `}
onClick={chartClickHandler} onClick={chartClickHandler}
></div> ></div>
<VizLegend {options.visualizationType !== Pod.GAUGE && (
placement={'bottom'} <VizLegend placement={'bottom'} items={legendItems} displayMode={LegendDisplayMode.List} />
items={legendItems} )}
displayMode={LegendDisplayMode.List}
/>
</div> </div>
); );
} }

Loading…
Cancel
Save