mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-09 17:57:26 +03:00
Improved memoization of grouped visits for line chart
This commit is contained in:
parent
daf9e7cf64
commit
b6ab9a1bdd
1 changed files with 5 additions and 6 deletions
|
@ -72,16 +72,14 @@ const generateLabels = (step, visits) => {
|
|||
];
|
||||
};
|
||||
|
||||
const generateLabelsAndGroupedVisits = (visits, step, skipNoElements) => {
|
||||
const groupedVisits = groupVisitsByStep(step, reverse(visits));
|
||||
|
||||
const generateLabelsAndGroupedVisits = (visits, groupedVisitsWithGaps, step, skipNoElements) => {
|
||||
if (skipNoElements) {
|
||||
return [ Object.keys(groupedVisits), groupedVisits ];
|
||||
return [ Object.keys(groupedVisitsWithGaps), groupedVisitsWithGaps ];
|
||||
}
|
||||
|
||||
const labels = generateLabels(step, visits);
|
||||
|
||||
return [ labels, fillTheGaps(groupedVisits, labels) ];
|
||||
return [ labels, fillTheGaps(groupedVisitsWithGaps, labels) ];
|
||||
};
|
||||
|
||||
const generateDataset = (stats, label, color) => ({
|
||||
|
@ -97,8 +95,9 @@ const LineChartCard = ({ title, visits, highlightedVisits }) => {
|
|||
const [ step, setStep ] = useState('monthly');
|
||||
const [ skipNoVisits, toggleSkipNoVisits ] = useToggle(true);
|
||||
|
||||
const groupedVisitsWithGaps = useMemo(() => groupVisitsByStep(step, reverse(visits)), [ step, visits ]);
|
||||
const [ labels, groupedVisits ] = useMemo(
|
||||
() => generateLabelsAndGroupedVisits(visits, step, skipNoVisits),
|
||||
() => generateLabelsAndGroupedVisits(visits, groupedVisitsWithGaps, step, skipNoVisits),
|
||||
[ visits, step, skipNoVisits ]
|
||||
);
|
||||
const groupedHighlighted = useMemo(
|
||||
|
|
Loading…
Reference in a new issue