style(usage): tune shared bar/pie charts for the usage views
- bar-chart: barMinWidth so hour-granularity bars stay visible with gaps. - pie-chart: single legend-beside-pie layout, value (percent%) tooltip, 2-decimal rounding for the Summary donut.
This commit is contained in:
@@ -100,7 +100,11 @@ const BarChart: React.FC<BarChartProps> = (props) => {
|
|||||||
data: processedData,
|
data: processedData,
|
||||||
type: 'bar',
|
type: 'bar',
|
||||||
barMaxWidth: 20,
|
barMaxWidth: 20,
|
||||||
barMinWidth: 8,
|
// Keep a small floor only — a large barMinWidth would force wide bars
|
||||||
|
// when there are many categories (e.g. hourly buckets), squeezing out
|
||||||
|
// the category gap so bars look fused. A low floor lets barCategoryGap
|
||||||
|
// win, so even dense hourly views keep visible gaps.
|
||||||
|
barMinWidth: 2,
|
||||||
barGap: '30%',
|
barGap: '30%',
|
||||||
barCategoryGap: '50%',
|
barCategoryGap: '50%',
|
||||||
...(stack === false || stack === undefined ? {} : { stack }),
|
...(stack === false || stack === undefined ? {} : { stack }),
|
||||||
|
|||||||
@@ -19,6 +19,11 @@ interface PieChartProps {
|
|||||||
totalLabel?: string;
|
totalLabel?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Donut sits on the left; a vertical legend hugs it just to the right and
|
||||||
|
// scrolls when there are many entries.
|
||||||
|
const CENTER_X = '32%';
|
||||||
|
const round2 = (n: number) => Math.round((Number(n) || 0) * 100) / 100;
|
||||||
|
|
||||||
const PieChart: React.FC<PieChartProps> = ({
|
const PieChart: React.FC<PieChartProps> = ({
|
||||||
data,
|
data,
|
||||||
height = 300,
|
height = 300,
|
||||||
@@ -51,7 +56,7 @@ const PieChart: React.FC<PieChartProps> = ({
|
|||||||
<span class="tooltip-item-dot" style="border-radius:50%;background-color:${params.color};"></span>
|
<span class="tooltip-item-dot" style="border-radius:50%;background-color:${params.color};"></span>
|
||||||
<span class="tooltip-item-title">${params.name}</span>:
|
<span class="tooltip-item-title">${params.name}</span>:
|
||||||
</span>
|
</span>
|
||||||
<span class="tooltip-value">${formatLargeNumber(params.value)}</span>
|
<span class="tooltip-value">${formatLargeNumber(round2(params.value))} (${params.percent}%)</span>
|
||||||
</span>
|
</span>
|
||||||
</div>`;
|
</div>`;
|
||||||
}
|
}
|
||||||
@@ -59,18 +64,18 @@ const PieChart: React.FC<PieChartProps> = ({
|
|||||||
legend: {
|
legend: {
|
||||||
type: 'scroll',
|
type: 'scroll',
|
||||||
orient: 'vertical',
|
orient: 'vertical',
|
||||||
right: 0,
|
left: '56%',
|
||||||
top: 18,
|
top: 'middle',
|
||||||
bottom: 18,
|
|
||||||
itemWidth: 8,
|
itemWidth: 8,
|
||||||
itemHeight: 8,
|
itemHeight: 8,
|
||||||
itemGap: 12,
|
itemGap: 10,
|
||||||
textStyle: {
|
textStyle: {
|
||||||
color: token.colorTextTertiary,
|
color: token.colorTextTertiary,
|
||||||
overflow: 'truncate',
|
overflow: 'truncate',
|
||||||
width: 180
|
width: 120
|
||||||
},
|
},
|
||||||
pageTextStyle: { color: token.colorTextTertiary },
|
pageTextStyle: { color: token.colorTextTertiary },
|
||||||
|
pageIconSize: 10,
|
||||||
pageIconColor: token.colorTextTertiary,
|
pageIconColor: token.colorTextTertiary,
|
||||||
pageIconInactiveColor: token.colorTextDisabled,
|
pageIconInactiveColor: token.colorTextDisabled,
|
||||||
data: data.map((item) => item.name),
|
data: data.map((item) => item.name),
|
||||||
@@ -79,24 +84,14 @@ const PieChart: React.FC<PieChartProps> = ({
|
|||||||
series: [
|
series: [
|
||||||
{
|
{
|
||||||
type: 'pie',
|
type: 'pie',
|
||||||
radius: ['52%', '72%'],
|
radius: ['54%', '78%'],
|
||||||
center: ['34%', '50%'],
|
center: [CENTER_X, '50%'],
|
||||||
avoidLabelOverlap: true,
|
avoidLabelOverlap: true,
|
||||||
label: {
|
// No on-arc label — the percentage lives in the tooltip instead, so
|
||||||
show: false
|
// hovering shows value + percent in one place.
|
||||||
},
|
label: { show: false },
|
||||||
emphasis: {
|
emphasis: { label: { show: false }, scale: false },
|
||||||
label: {
|
labelLine: { show: false },
|
||||||
show: true,
|
|
||||||
formatter: (params: any) => `${params.percent}%`,
|
|
||||||
fontSize: 16,
|
|
||||||
fontWeight: 600,
|
|
||||||
color: token.colorText
|
|
||||||
}
|
|
||||||
},
|
|
||||||
labelLine: {
|
|
||||||
show: false
|
|
||||||
},
|
|
||||||
data
|
data
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -137,7 +132,7 @@ const PieChart: React.FC<PieChartProps> = ({
|
|||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
left: '34%',
|
left: CENTER_X,
|
||||||
top: '50%',
|
top: '50%',
|
||||||
transform: 'translate(-50%, -50%)',
|
transform: 'translate(-50%, -50%)',
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
|
|||||||
Reference in New Issue
Block a user