Skip to content

Commit c504538

Browse files
committed
we do a little optimization
1 parent aed3ccb commit c504538

File tree

8 files changed

+1280
-24
lines changed

8 files changed

+1280
-24
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ dist-ssr
2525

2626
# sensitive files
2727
.env
28+
29+
# Million Lint
30+
.million

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"preview": "vite preview"
1212
},
1313
"dependencies": {
14+
"@million/lint": "^1.0.14",
1415
"@react-sigma/core": "^4.0.3",
1516
"@react-sigma/layout-circular": "^4.0.3",
1617
"@react-sigma/layout-core": "^4.0.3",

src/App.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ export const LoadGraph = () => {
102102
});
103103

104104
// map weight to size of edges
105-
const minEdgeMult = 0.1; // minimum multiplier from weight to size
106-
const maxEdgeMult = 10; // maximum multiplier from weight to size
105+
const minEdgeMult = 0.05; // minimum multiplier from weight to size
106+
const maxEdgeMult = 5; // maximum multiplier from weight to size
107107
graph.forEachEdge((edge) => {
108108
const weight = graph.getEdgeAttribute(edge, "weight");
109109
const size =
@@ -150,7 +150,7 @@ export const LoadGraph = () => {
150150
const sensibleSettings = forceAtlas2.inferSettings(graph);
151151
forceAtlas2.assign(graph, {
152152
// assign the forceAtlas2 layout
153-
iterations: 50,
153+
iterations: 15,
154154
settings: {
155155
scalingRatio: 500,
156156
...sensibleSettings,

src/Utils.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function getMinMaxWeightedDegrees(graph: Graph) {
7070
function getNodeSize(graph: Graph, node: string) {
7171
const degree = weightedDegree(graph, node);
7272
const { minDegree, maxDegree } = getMinMaxWeightedDegrees(graph);
73-
return scale(degree, minDegree, maxDegree, 1.5, 10);
73+
return scale(degree, minDegree, maxDegree, 1.5, 5);
7474
}
7575

7676
// Get color of a target node

src/components/Controls.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FC } from "react";
1+
import { FC, memo } from "react";
22

33
import {
44
ControlsContainer,
@@ -13,7 +13,7 @@ import "../index.css";
1313

1414
// import { LayoutsControl } from "../../common/LayoutsControl";
1515

16-
export const Complete: FC = () => {
16+
export const Complete: FC = memo(() => {
1717
return (
1818
// this crap <>
1919
// you have to wrap it in an empty element????
@@ -31,4 +31,4 @@ export const Complete: FC = () => {
3131
</ControlsContainer>
3232
</>
3333
);
34-
};
34+
});

src/components/DescriptionPanel.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FC, PropsWithChildren, ReactNode, useEffect, useRef, useState } from "react";
1+
import { FC, PropsWithChildren, ReactNode, useEffect, useRef, useState, useMemo } from "react";
22
import { BsInfoCircle } from "react-icons/bs";
33
import { MdExpandLess, MdExpandMore } from "react-icons/md";
44
import AnimateHeight from "react-animate-height";
@@ -20,6 +20,16 @@ const Panel: FC<PropsWithChildren<{ title: ReactNode | string; initiallyDeployed
2020
}, DURATION);
2121
}, [isDeployed]);
2222

23+
const memoizedAnimateHeight = useMemo(() => (
24+
<AnimateHeight duration={DURATION} height={isDeployed ? "auto" : 0}>
25+
{children}
26+
</AnimateHeight>
27+
), [isDeployed, children]);
28+
29+
const memoizedMdExpandLess = useMemo(() => (
30+
<MdExpandLess style={{ fontSize: "1.5rem" }} />
31+
), []);
32+
2333
return (
2434
<div className="panel dark:bg-black dark:text-white" ref={dom}>
2535
<h2 className="flex items-center justify-between">
@@ -30,15 +40,13 @@ const Panel: FC<PropsWithChildren<{ title: ReactNode | string; initiallyDeployed
3040
className="p-2"
3141
>
3242
{isDeployed ? (
33-
<MdExpandLess style={{ fontSize: "1.5rem" }} />
43+
memoizedMdExpandLess
3444
) : (
3545
<MdExpandMore style={{ fontSize: "1.5rem" }} />
3646
)}
3747
</button>
3848
</h2>
39-
<AnimateHeight duration={DURATION} height={isDeployed ? "auto" : 0}>
40-
{children}
41-
</AnimateHeight>
49+
{memoizedAnimateHeight}
4250
</div>
4351
);
4452
};

vite.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { defineConfig } from 'vite'
22
import react from '@vitejs/plugin-react'
33
import tailwindcss from 'tailwindcss'
4+
import MillionLint from '@million/lint';
45

56
export default defineConfig({
6-
plugins: [react()],
7+
plugins: [MillionLint.vite(), react()],
78
css: {
89
postcss: {
910
plugins: [tailwindcss()],

0 commit comments

Comments
 (0)