Skip to content

Commit 0eb119f

Browse files
committed
chore: replaced reactjs-based pie charts by plotly
1 parent 7603b0f commit 0eb119f

File tree

5 files changed

+27
-79
lines changed

5 files changed

+27
-79
lines changed

web-frontend/package-lock.json

Lines changed: 2 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web-frontend/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,12 @@
2020
"dependencies": {
2121
"antd": "5.24.2",
2222
"axios": "1.7.9",
23-
"chart.js": "4.4.8",
2423
"compression": "1.8.0",
2524
"d3": "7.9.0",
2625
"express": "5.0.1",
2726
"file-saver": "2.0.5",
2827
"openchemlib": "8.18.1",
2928
"react": "18.3.1",
30-
"react-chartjs-2": "5.3.0",
3129
"react-dom": "18.3.1",
3230
"react-markdown": "10.0.0",
3331
"react-mf": "3.0.0",

web-frontend/src/elements/routes/pages/content/ContentChart.tsx

Lines changed: 23 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,21 @@
11
import './ContentChart.scss';
22

3-
import { CSSProperties, useMemo } from 'react';
3+
import { useMemo } from 'react';
44
import {
55
splitStringAndCapitaliseFirstLetter,
66
splitStringAndJoin,
77
} from '../../../../utils/stringUtils';
88
import ValueCount from '../../../../types/ValueCount';
99
import ContentFilterOptions from '../../../../types/filterOptions/ContentFilterOtions';
1010
import { Content } from 'antd/es/layout/layout';
11-
import {
12-
Chart as ChartJS,
13-
ArcElement,
14-
Colors,
15-
Legend,
16-
Title,
17-
Tooltip,
18-
} from 'chart.js';
19-
import { Doughnut } from 'react-chartjs-2';
2011

21-
ChartJS.register(ArcElement, Colors, Legend, Title, Tooltip);
12+
import Plot, { PlotParams } from 'react-plotly.js';
2213

2314
type InputProps = {
2415
content: ContentFilterOptions;
2516
identifier: string;
26-
width: CSSProperties['width'];
27-
height: CSSProperties['height'];
17+
width: number;
18+
height: number;
2819
};
2920

3021
function ContentChart({ content, identifier, width, height }: InputProps) {
@@ -63,14 +54,16 @@ function ContentChart({ content, identifier, width, height }: InputProps) {
6354
);
6455
const counts = contentValueCounts.map((vc) => vc.count);
6556

66-
const data = {
67-
labels,
68-
datasets: [
69-
{
70-
data: labels.map((_, i) => counts[i]),
71-
},
72-
],
73-
};
57+
const data: PlotParams['data'] = [
58+
{
59+
type: 'pie',
60+
hole: 0.5,
61+
labels,
62+
values: labels.map((_, i) => counts[i]),
63+
textinfo: 'label',
64+
insidetextorientation: 'radial',
65+
},
66+
];
7467

7568
return (
7669
<Content
@@ -84,30 +77,17 @@ function ContentChart({ content, identifier, width, height }: InputProps) {
8477
margin: 0,
8578
}}
8679
>
87-
<Doughnut
80+
<Plot
8881
data={data}
89-
width={width}
90-
height={height}
91-
options={{
92-
maintainAspectRatio: false,
93-
aspectRatio: 1,
94-
plugins: {
95-
title: {
96-
display: true,
97-
text:
98-
(itemCount > topN ? 'Top ' + topN + ' of ' : '') +
99-
splitStringAndCapitaliseFirstLetter(identifier, '_', ' '),
100-
fullSize: true,
101-
font: {
102-
size: 18,
103-
weight: 'bold',
104-
},
105-
},
106-
legend: {
107-
display: true,
108-
position: 'right',
109-
},
82+
layout={{
83+
title: {
84+
text:
85+
(itemCount > topN ? 'Top ' + topN + ' of ' : '') +
86+
splitStringAndCapitaliseFirstLetter(identifier, '_', ' '),
11087
},
88+
width,
89+
height,
90+
showlegend: false,
11191
}}
11292
/>
11393
</Content>

web-frontend/src/elements/routes/pages/content/ContentView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
22
import useContainerDimensions from '../../../../utils/useContainerDimensions';
3-
import ContentChart from './ContentChart';
43
import fetchData from '../../../../utils/request/fetchData';
54
import buildSearchParams from '../../../../utils/request/buildSearchParams';
65
import initFlags from '../../../../utils/initFlags';
@@ -27,6 +26,7 @@ import Segmented from '../../../basic/Segmented';
2726
import segmentedWidth from '../../../../constants/segmentedWidth';
2827
import { Suspense, lazy } from 'react';
2928

29+
const ContentChart = lazy(() => import('./ContentChart'));
3030
const SunburstPlot = lazy(() => import('./SunburstPlot'));
3131

3232
const defaultSearchPanelWidth = 450;

web-frontend/src/elements/routes/pages/search/searchPanel/msSpecFilter/PropertyFilterOptionsMenuItems.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ function PropertyFilterOptionsMenuItems({
9393
filterOptions={propertyFilterOptions?.ms_type ?? []}
9494
filterName="propertyFilterOptions"
9595
label="ms_type"
96-
height={50}
96+
height={80}
9797
showCounts={showCounts}
9898
/>
9999
</Form.Item>

0 commit comments

Comments
 (0)