Skip to content

Commit 076e439

Browse files
committed
Added value with percentage in tooltip (Fixes #581)
Signed-off-by: Omkar Phansopkar <[email protected]>
1 parent cec79dc commit 076e439

File tree

3 files changed

+29
-26
lines changed

3 files changed

+29
-26
lines changed

src/components/FileTree/FileTree.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import React, { useEffect, useState } from "react";
44

55
import EllipticLoader from "../EllipticLoader";
66
import { PathType, useWorkbenchDB } from "../../contexts/workbenchContext";
7-
87
import SwitcherIcon from "./SwitcherIcon";
98

109
import "./FileTree.css";
Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import c3, { ChartAPI } from 'c3';
2-
import React, { useEffect, useRef, useState } from 'react';
1+
import c3, { ChartAPI } from "c3";
2+
import React, { useEffect, useRef, useState } from "react";
33

4-
import { PieChartFallback, PieChartFallbackProps } from './PieChartFallback';
4+
import { PieChartFallback, PieChartFallbackProps } from "./PieChartFallback";
55

6-
import { FormattedEntry } from '../../utils/pie';
7-
import { LEGEND_COLORS } from '../../constants/colors';
6+
import { FormattedEntry } from "../../utils/pie";
7+
import { LEGEND_COLORS } from "../../constants/colors";
88

9-
import './piechart.css';
9+
import "./piechart.css";
1010

1111
interface PieChartProps extends PieChartFallbackProps {
12-
chartData: FormattedEntry[] | null,
12+
chartData: FormattedEntry[] | null;
1313
}
1414

1515
const PieChart = (props: PieChartProps) => {
@@ -20,26 +20,30 @@ const PieChart = (props: PieChartProps) => {
2020

2121
// Redraw chart on data change
2222
useEffect(() => {
23-
if(!chartData || !chartRef.current)
24-
return;
25-
23+
if (!chartData || !chartRef.current) return;
24+
2625
const newChart = c3.generate({
2726
bindto: chartRef.current,
2827
data: {
2928
columns: chartData,
30-
type : 'pie',
29+
type: "pie",
3130
},
3231
color: {
3332
pattern: LEGEND_COLORS,
34-
}
33+
},
34+
tooltip: {
35+
format: {
36+
value: (value, ratio) =>
37+
`${String(value)} \n${(ratio * 100).toFixed(1)}%`,
38+
},
39+
},
3540
});
3641
setC3Chart(newChart);
3742
}, [chartData]);
3843

3944
// Suppress continuous resize calls that may cause stutter and bad UX
4045
useEffect(() => {
41-
if(!chartContainerRef.current || !c3Chart)
42-
return;
46+
if (!chartContainerRef.current || !c3Chart) return;
4347

4448
const resizeChart = () => c3Chart.resize();
4549

@@ -52,23 +56,22 @@ const PieChart = (props: PieChartProps) => {
5256

5357
const chartContainerObserver = new ResizeObserver(resizeActionHandler);
5458
chartContainerObserver.observe(chartContainerRef.current);
55-
59+
5660
return () => {
5761
clearTimeout(resizeTimeout);
5862
chartContainerObserver.disconnect();
59-
}
63+
};
6064
}, [c3Chart]);
6165

62-
63-
if(!chartData || !chartData.length){
64-
return <PieChartFallback {...props} loading={!chartData} />
66+
if (!chartData || !chartData.length) {
67+
return <PieChartFallback {...props} loading={!chartData} />;
6568
}
6669

6770
return (
68-
<div className='pie-chart-container' ref={chartContainerRef}>
69-
<div ref={chartRef} className='pie-chart' />
71+
<div className="pie-chart-container" ref={chartContainerRef}>
72+
<div ref={chartRef} className="pie-chart" />
7073
</div>
71-
)
72-
}
74+
);
75+
};
7376

74-
export default PieChart
77+
export default PieChart;

src/components/PieChart/piechart.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,6 @@
5252
}
5353

5454
.c3-tooltip td.value {
55-
text-align: right
55+
text-align: right;
56+
white-space: pre-wrap;
5657
}

0 commit comments

Comments
 (0)