Files
dees-catalog/ts_web/elements/00group-chart/dees-chart-radar/component.ts

131 lines
3.1 KiB
TypeScript
Raw Normal View History

2026-04-04 11:05:01 +00:00
import {
customElement,
property,
type TemplateResult,
} from '@design.estate/dees-element';
import { DeesChartEchartsBase } from '../dees-chart-echarts-base.js';
import { demoFunc } from './demo.js';
import { radarStyles } from './styles.js';
import { renderChartRadar } from './template.js';
import { getEchartsSeriesColors, getThemeColors } from '../dees-chart-echarts-theme.js';
2026-04-04 11:05:01 +00:00
export interface IRadarIndicator {
name: string;
max: number;
}
export interface IRadarSeriesItem {
name: string;
values: number[];
color?: string;
}
declare global {
interface HTMLElementTagNameMap {
'dees-chart-radar': DeesChartRadar;
}
}
@customElement('dees-chart-radar')
export class DeesChartRadar extends DeesChartEchartsBase {
public static demo = demoFunc;
public static demoGroups = ['Chart'];
@property({ type: Array })
accessor indicators: IRadarIndicator[] = [];
@property({ type: Array })
accessor series: IRadarSeriesItem[] = [];
@property({ type: Boolean })
accessor showLegend: boolean = true;
@property({ type: Boolean })
accessor fillArea: boolean = true;
public static styles = radarStyles;
public render(): TemplateResult {
return renderChartRadar(this);
}
public async updated(changedProperties: Map<string, any>) {
super.updated(changedProperties);
if (
this.chartInstance &&
(changedProperties.has('indicators') ||
changedProperties.has('series') ||
changedProperties.has('showLegend') ||
changedProperties.has('fillArea'))
) {
this.updateChart();
}
}
protected buildOption(): Record<string, any> {
const colors = getThemeColors(this.goBright);
2026-04-04 11:05:01 +00:00
const seriesColors = getEchartsSeriesColors(this.goBright);
const seriesData = this.series.map((s, index) => {
const color = s.color || seriesColors[index % seriesColors.length];
return {
name: s.name,
value: s.values,
itemStyle: { color },
lineStyle: { color, width: 2 },
areaStyle: this.fillArea ? { color, opacity: 0.15 } : undefined,
symbol: 'circle',
symbolSize: 6,
};
});
return {
tooltip: {
trigger: 'item',
},
legend: this.showLegend && this.series.length > 1
? { bottom: 8, itemWidth: 10, itemHeight: 10 }
: { show: false },
radar: {
indicator: this.indicators.map((ind) => ({
name: ind.name,
max: ind.max,
})),
shape: 'polygon',
splitNumber: 4,
axisName: {
color: colors.textSecondary,
2026-04-04 11:05:01 +00:00
fontSize: 11,
},
splitArea: {
areaStyle: {
color: [colors.bgTertiary, colors.bgSecondary],
2026-04-04 11:05:01 +00:00
},
},
splitLine: {
lineStyle: {
color: colors.borderDefault,
2026-04-04 11:05:01 +00:00
},
},
axisLine: {
lineStyle: {
color: colors.borderDefault,
2026-04-04 11:05:01 +00:00
},
},
},
series: [
{
type: 'radar',
data: seriesData,
emphasis: {
lineStyle: {
width: 3,
},
},
},
],
};
}
}