This commit is contained in:
2026-04-04 11:05:01 +00:00
parent 4dba14060e
commit ff32470d8a
29 changed files with 1431 additions and 2 deletions

View File

@@ -0,0 +1,132 @@
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 } 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<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 isDark = !this.goBright;
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: isDark ? 'hsl(0 0% 63.9%)' : 'hsl(0 0% 35%)',
fontSize: 11,
},
splitArea: {
areaStyle: {
color: isDark
? ['hsl(0 0% 7%)', 'hsl(0 0% 9%)']
: ['hsl(0 0% 97%)', 'hsl(0 0% 95%)'],
},
},
splitLine: {
lineStyle: {
color: isDark ? 'hsl(0 0% 16%)' : 'hsl(0 0% 88%)',
},
},
axisLine: {
lineStyle: {
color: isDark ? 'hsl(0 0% 16%)' : 'hsl(0 0% 88%)',
},
},
},
series: [
{
type: 'radar',
data: seriesData,
emphasis: {
lineStyle: {
width: 3,
},
},
},
],
};
}
}

View File

@@ -0,0 +1,119 @@
import { html, css, cssManager } from '@design.estate/dees-element';
import type { DeesChartRadar } from './component.js';
import '@design.estate/dees-wcctools/demotools';
import './component.js';
export const demoFunc = () => {
const indicators = [
{ name: 'Latency', max: 100 },
{ name: 'Throughput', max: 100 },
{ name: 'Availability', max: 100 },
{ name: 'Error Rate', max: 100 },
{ name: 'Saturation', max: 100 },
{ name: 'Security', max: 100 },
];
const series = [
{ name: 'Service A', values: [85, 90, 99, 12, 45, 78] },
{ name: 'Service B', values: [70, 65, 95, 28, 60, 90] },
];
const singleIndicators = [
{ name: 'Speed', max: 10 },
{ name: 'Reliability', max: 10 },
{ name: 'Comfort', max: 10 },
{ name: 'Safety', max: 10 },
{ name: 'Cost', max: 10 },
];
const singleSeries = [
{ name: 'Rating', values: [8.5, 9.2, 7.0, 9.5, 6.0] },
];
return html`
<dees-demowrapper .runAfterRender=${async (elementArg: HTMLElement) => {
const compChart = elementArg.querySelector('#comparison-chart') as DeesChartRadar;
const singleChart = elementArg.querySelector('#single-chart') as DeesChartRadar;
const buttons = elementArg.querySelectorAll('dees-button');
buttons.forEach((button: any) => {
const text = button.text?.trim();
if (text === 'Randomize') {
button.addEventListener('click', () => {
compChart.series = series.map((s) => ({
...s,
values: s.values.map(() => Math.round(20 + Math.random() * 80)),
}));
singleChart.series = singleSeries.map((s) => ({
...s,
values: s.values.map(() => Math.round((2 + Math.random() * 8) * 10) / 10),
}));
});
}
});
}}>
<style>
${css`
.demoBox {
position: relative;
background: ${cssManager.bdTheme('hsl(0 0% 95%)', 'hsl(0 0% 9%)')};
height: 100%;
width: 100%;
padding: 40px;
box-sizing: border-box;
display: flex;
flex-direction: column;
gap: 24px;
}
.chartRow {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 24px;
}
.controls {
display: flex;
gap: 12px;
margin-bottom: 8px;
}
.info {
color: ${cssManager.bdTheme('hsl(215.4 16.3% 56.9%)', 'hsl(215 20.2% 55.1%)')};
font-size: 12px;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Geist Sans', sans-serif;
text-align: center;
margin-top: 8px;
}
`}
</style>
<div class="demoBox">
<div class="controls">
<dees-button-group label="Actions:">
<dees-button>Randomize</dees-button>
</dees-button-group>
</div>
<div class="chartRow">
<dees-chart-radar
id="comparison-chart"
.label=${'Service Health Comparison'}
.indicators=${indicators}
.series=${series}
></dees-chart-radar>
<dees-chart-radar
id="single-chart"
.label=${'Product Rating'}
.indicators=${singleIndicators}
.series=${singleSeries}
.fillArea=${true}
></dees-chart-radar>
</div>
<div class="info">
Radar chart for multi-dimensional comparison •
Supports multiple overlay series and configurable fill •
Click 'Randomize' to update data
</div>
</div>
</dees-demowrapper>
`;
};

View File

@@ -0,0 +1 @@
export * from './component.js';

View File

@@ -0,0 +1,7 @@
import { css } from '@design.estate/dees-element';
import { echartsBaseStyles } from '../dees-chart-echarts-styles.js';
export const radarStyles = [
...echartsBaseStyles,
css``,
];

View File

@@ -0,0 +1,13 @@
import { html, type TemplateResult } from '@design.estate/dees-element';
import type { DeesChartRadar } from './component.js';
export const renderChartRadar = (component: DeesChartRadar): TemplateResult => {
return html`
<dees-tile>
<div slot="header" class="chartHeader">
<span class="chartLabel">${component.label}</span>
</div>
<div class="chartContainer"></div>
</dees-tile>
`;
};