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';
|
2026-04-04 12:29:39 +00:00
|
|
|
import { getEchartsSeriesColors, getThemeColors, hexToRgba } 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> {
|
2026-04-04 11:25:19 +00:00
|
|
|
const colors = getThemeColors(this.goBright);
|
2026-04-04 11:05:01 +00:00
|
|
|
const seriesColors = getEchartsSeriesColors(this.goBright);
|
|
|
|
|
|
2026-04-04 12:29:39 +00:00
|
|
|
const fillAlpha = this.goBright ? 0.1 : 0.15;
|
|
|
|
|
|
2026-04-04 11:05:01 +00:00
|
|
|
const seriesData = this.series.map((s, index) => {
|
|
|
|
|
const color = s.color || seriesColors[index % seriesColors.length];
|
|
|
|
|
return {
|
|
|
|
|
name: s.name,
|
|
|
|
|
value: s.values,
|
2026-04-04 12:29:39 +00:00
|
|
|
itemStyle: { color, borderColor: color, borderWidth: 1 },
|
|
|
|
|
lineStyle: { color, width: 1.5 },
|
|
|
|
|
areaStyle: this.fillArea ? { color: hexToRgba(color, fillAlpha) } : undefined,
|
2026-04-04 11:05:01 +00:00
|
|
|
symbol: 'circle',
|
2026-04-04 12:29:39 +00:00
|
|
|
symbolSize: 5,
|
2026-04-04 11:05:01 +00:00
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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: {
|
2026-04-04 11:25:19 +00:00
|
|
|
color: colors.textSecondary,
|
2026-04-04 11:05:01 +00:00
|
|
|
fontSize: 11,
|
|
|
|
|
},
|
|
|
|
|
splitArea: {
|
|
|
|
|
areaStyle: {
|
2026-04-04 11:25:19 +00:00
|
|
|
color: [colors.bgTertiary, colors.bgSecondary],
|
2026-04-04 11:05:01 +00:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
splitLine: {
|
|
|
|
|
lineStyle: {
|
2026-04-04 11:25:19 +00:00
|
|
|
color: colors.borderDefault,
|
2026-04-04 11:05:01 +00:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
axisLine: {
|
|
|
|
|
lineStyle: {
|
2026-04-04 11:25:19 +00:00
|
|
|
color: colors.borderDefault,
|
2026-04-04 11:05:01 +00:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
series: [
|
|
|
|
|
{
|
|
|
|
|
type: 'radar',
|
|
|
|
|
data: seriesData,
|
|
|
|
|
emphasis: {
|
|
|
|
|
lineStyle: {
|
|
|
|
|
width: 3,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|