Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

graph performance #2336

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12,433 changes: 6,654 additions & 5,779 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"@mui/material": "5.14.5",
"@mui/styled-engine-sc": "5.12.0",
"@mui/styles": "5.14.5",
"@mui/x-charts": "7.3.2",
seeden marked this conversation as resolved.
Show resolved Hide resolved
"@rollup/plugin-alias": "5.0.0",
"@rollup/plugin-babel": "6.0.3",
"@rollup/plugin-commonjs": "25.0.4",
Expand Down Expand Up @@ -116,6 +117,7 @@
"@mui/material": "^5.14.5",
"@mui/styled-engine-sc": "^5.12.0",
"@mui/styles": "^5.14.5",
"@mui/x-charts": "^7.3.2",
"electron": "^30.0.9",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function FormatLargeNumber(props: FormatLargeNumberProps) {
const [locale] = useLocale();

const numberFormat = useMemo(() => new Intl.NumberFormat(locale), [locale]);
const formatedValue = useMemo(() => {
const formattedValue = useMemo(() => {
if (typeof value === 'undefined' || value === null) {
return value;
}
Expand All @@ -42,5 +42,5 @@ export default function FormatLargeNumber(props: FormatLargeNumberProps) {
return numberFormat.format(value);
}, [value, numberFormat, locale]);

return <span>{formatedValue}</span>;
return <span>{formattedValue}</span>;
}
104 changes: 104 additions & 0 deletions packages/core/src/components/LineChart/LineChart.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { alpha } from '@mui/material';
import { SparkLineChart, type SparkLineChartProps } from '@mui/x-charts';
import { areaElementClasses } from '@mui/x-charts/LineChart';
import BigNumber from 'bignumber.js';
import JSONbig from 'json-bigint';
import React, { useMemo, memo } from 'react';
import styled from 'styled-components';

import Color from '../../constants/Color';

const StyledGraphContainer = styled.div<{ height: number }>`
position: relative;
min-height: 80px;
height: ${({ height }) => `${height}px`};
`;

function LinearGradient() {
return (
<defs>
<linearGradient id="graph-gradient" x1="0%" y1="0%" x2="0%" y2="100%">
<stop offset="0%" stopColor={alpha(Color.Green[500], 0.4)} />
<stop offset="100%" stopColor={alpha(Color.Green[500], 0)} />
</linearGradient>
</defs>
);
}

const sx = {
[`& .${areaElementClasses.root}`]: {
fill: 'url(#graph-gradient)',
},
};

const chartColors = [Color.Green[500]];
const chartMargin = { top: 0, bottom: 0, left: 0, right: 0 };
const defaultXValueFormatter = (value: number) => value.toString();
const defaultYValueFormatter = (value: number | BigNumber | null) => (value !== null ? value.toString() : '');

type Point = {
x: number;
y: number | BigNumber;
};

const MemoLineChart = memo((props: SparkLineChartProps) => (
<SparkLineChart {...props}>
<LinearGradient />
<rect x={0} y={0} width={0} height="100%" fill="url(#graph-gradient)" />
</SparkLineChart>
));

export type LineChartProps = {
data: Point[];
// min?: number;
height?: number;
xValueFormatter?: (value: number) => string;
yValueFormatter?: (value: number | BigNumber | null) => string;
};

export default function LineChart(props: LineChartProps) {
const {
data,
// min: defaultMin = 0,
xValueFormatter = defaultXValueFormatter,
yValueFormatter = defaultYValueFormatter,
height = 150,
} = props;

const stringifiedData = useMemo(() => JSONbig.stringify(data), [data]);
const freezedData = useMemo<Point[]>(() => JSONbig.parse(stringifiedData), [stringifiedData]);
seeden marked this conversation as resolved.
Show resolved Hide resolved

const yData = useMemo(() => freezedData.map((item) => item.y), [freezedData]);
const xData = useMemo(() => freezedData.map((item) => item.x), [freezedData]);

const yDataNumber = useMemo(
() => yData.map((value) => (value instanceof BigNumber ? value.toNumber() : value)),
[yData],
);
seeden marked this conversation as resolved.
Show resolved Hide resolved

const xAxis = useMemo(
() => ({
data: xData,
valueFormatter: xValueFormatter,
}),
[xData, xValueFormatter],
);
seeden marked this conversation as resolved.
Show resolved Hide resolved

return (
<StyledGraphContainer height={height}>
<MemoLineChart
xAxis={xAxis}
data={yDataNumber}
height={height || 0}
valueFormatter={yValueFormatter}
curve="monotoneX"
margin={chartMargin}
colors={chartColors}
area
showHighlight
showTooltip
sx={sx}
/>
</StyledGraphContainer>
);
}
2 changes: 2 additions & 0 deletions packages/core/src/components/LineChart/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default } from './LineChart';
export * from './LineChart';
1 change: 1 addition & 0 deletions packages/core/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export { default as LayoutDashboard, LayoutDashboardSub } from './LayoutDashboar
export { default as LayoutHero } from './LayoutHero';
export { default as LayoutLoading } from './LayoutLoading';
export { default as LayoutMain } from './LayoutMain';
export { default as LineChart } from './LineChart';
export { default as Link } from './Link';
export { default as Loading } from './Loading';
export { default as LoadingOverlay } from './LoadingOverlay';
Expand Down
1 change: 1 addition & 0 deletions packages/gui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@mui/material": "5.14.5",
"@mui/styled-engine-sc": "5.12.0",
"@mui/styles": "5.14.5",
"@mui/x-charts": "7.3.2",
"@rehooks/local-storage": "2.4.4",
"@walletconnect/sign-client": "2.10.0",
"@walletconnect/utils": "2.10.0",
Expand Down
1 change: 0 additions & 1 deletion packages/gui/src/components/plotNFT/PlotNFTGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ export default function PlotNFTGraph(props: PlotNFTGraphProps) {
)}
<Box height={100} position="relative" ref={ref}>
<VictoryChart
animate={{ duration: 300, onLoad: { duration: 0 } }}
width={containerSize.width || 1}
height={containerSize.height || 1}
domain={{ x: [maxX, minX], y: [0, maxY] }}
Expand Down
3 changes: 1 addition & 2 deletions packages/wallets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
"react-use": "17.4.0",
"react-use-timeout": "1.0.0",
"use-dark-mode": "2.3.1",
"validator": "13.11.0",
"victory": "36.6.11"
"validator": "13.11.0"
},
"devDependencies": {
"@babel/core": "7.22.10",
Expand Down
Loading
Loading