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, hexToRgba } from '../dees-chart-echarts-theme.js'; 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) { super.updated(changedProperties); if ( this.chartInstance && (changedProperties.has('indicators') || changedProperties.has('series') || changedProperties.has('showLegend') || changedProperties.has('fillArea')) ) { this.updateChart(); } } protected buildOption(): Record { const colors = getThemeColors(this.goBright); const seriesColors = getEchartsSeriesColors(this.goBright); const fillAlpha = this.goBright ? 0.1 : 0.15; const seriesData = this.series.map((s, index) => { const color = s.color || seriesColors[index % seriesColors.length]; return { name: s.name, value: s.values, itemStyle: { color, borderColor: color, borderWidth: 1 }, lineStyle: { color, width: 1.5 }, areaStyle: this.fillArea ? { color: hexToRgba(color, fillAlpha) } : undefined, symbol: 'circle', symbolSize: 5, }; }); 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, fontSize: 11, }, splitArea: { areaStyle: { color: [colors.bgTertiary, colors.bgSecondary], }, }, splitLine: { lineStyle: { color: colors.borderDefault, }, }, axisLine: { lineStyle: { color: colors.borderDefault, }, }, }, series: [ { type: 'radar', data: seriesData, emphasis: { lineStyle: { width: 3, }, }, }, ], }; } }