Skip to content

Commit 3b6321e

Browse files
author
Erik van Velzen
committedMar 25, 2025·
Remove duplicate sankey import code
1 parent 6d1f1a9 commit 3b6321e

File tree

6 files changed

+17
-34
lines changed

6 files changed

+17
-34
lines changed
 

‎frontend/components/IJzerboeren/Sankey/IronPowderProcessSankey.tsx

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
import {SankeyLink} from "@/components/IJzerboeren/Sankey/link"
33
import {FunctionComponent} from "react"
4-
import dynamic from "next/dynamic"
4+
import {IronPowderSankey} from "@/components/IJzerboeren/Sankey/dynamic-import"
55

66
/**
77
Wind + zon 100%
@@ -80,14 +80,8 @@ function* linkGenerator(includeLoss: boolean): Generator<SankeyLink> {
8080

8181
const links = Array.from(linkGenerator(false))
8282

83-
// This prevents an issue with server-side rendering
84-
const IronPowderSankey = dynamic(
85-
() => import('../Sankey/Sankey').then(res => res.IronPowderSankey),
86-
{ ssr: false }
87-
)
88-
8983
export const IronPowderProcessSankey: FunctionComponent = () => (
90-
<IronPowderSankey links={links} maxWidth="" svgHeight={200} />
84+
<IronPowderSankey links={links} maxWidth="" />
9185
)
9286

9387
function ratio(input: number, ratio: number): [number, number] {

‎frontend/components/IJzerboeren/Sankey/Sankey.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use client"
22

33
import {FunctionComponent, useLayoutEffect, useMemo, useRef} from "react"
4-
import {uniq, uniqBy} from "lodash"
4+
import {uniq, uniqBy, merge} from "lodash"
55
import { useRandomInt } from "@/utils/useRandomInt"
66
import Plotly, {SankeyData} from "plotly.js-dist-min"
77
import chroma from "chroma-js";
@@ -137,23 +137,23 @@ function doTransition(divId: string, oldLinks: SankeyLink[], newLinks: SankeyLin
137137
export const IronPowderSankey: FunctionComponent<{
138138
links: SankeyLink[]
139139
maxWidth?: string,
140-
svgHeight?: number,
140+
plotlyLayout?: Partial<Plotly.Layout>,
141141
}> = ({
142142
links,
143143
maxWidth = "50rem",
144-
svgHeight = 600,
144+
plotlyLayout = {},
145145
}) => {
146146
const divId = "sankey" + useRandomInt()
147147
const divRef = useRef<HTMLDivElement | null>(null)
148148

149149
const previousLinks = useRef<SankeyLink[] | null>(null)
150150

151151
const width = divRef.current?.clientWidth;
152-
const layout = useMemo(() => ({
152+
const layout = useMemo(() => (merge({
153153
...plotlySankeyLayout,
154154
width,
155155
// height: svgHeight
156-
}), [width]);
156+
}, plotlyLayout)), [width]);
157157

158158
useLayoutEffect(() => {
159159
if (previousLinks.current === null) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import dynamic from "next/dynamic"
2+
3+
// Importing like this prevents an issue with server-side rendering
4+
export const IronPowderSankey = dynamic(
5+
() => import('../Sankey/Sankey').then(res => res.IronPowderSankey),
6+
{ ssr: false }
7+
)

‎frontend/components/IJzerboeren/Step1/Step1.tsx

+1-7
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,11 @@ import { KpiRow } from "@/components/IJzerboeren/KPIs/KpiRow"
22
import {heatPumpKpis, heatPumpSankeyLinks} from "@/components/IJzerboeren/Step1/step-1-data"
33
import {TwoColumnSimulationLayout} from "@/components/Blocks/SectionBlock/TwoColumn"
44
import {FunctionComponent} from "react"
5-
import dynamic from 'next/dynamic'
65
import {GelijktijdigheidKpi} from "@/components/IJzerboeren/KPIs/GelijktijdigheidKPI"
76
import {LCOEVerwarmen} from "@/components/IJzerboeren/KPIs/LCOEVerwarmen"
87
import {CO2EmissionKPI} from "@/components/IJzerboeren/KPIs/CO2EmissionKPI"
98
import rawHtml from "@/components/RawHtml/RawHtml.module.css"
10-
11-
// Importing like this prevents an issue with server-side rendering
12-
const IronPowderSankey = dynamic(
13-
() => import('../Sankey/Sankey').then(res => res.IronPowderSankey),
14-
{ ssr: false }
15-
)
9+
import {IronPowderSankey} from "@/components/IJzerboeren/Sankey/dynamic-import"
1610

1711
export const Step1: FunctionComponent = () => {
1812
return (

‎frontend/components/IJzerboeren/Step2/Step2.tsx

+1-7
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,12 @@ import {step2Data, Step2Outputs} from "@/components/IJzerboeren/Step2/step2-data
44
import {useStateWithHistory} from "@/components/IJzerboeren/useStateWithHistory"
55
import {TwoColumnSimulationLayout} from "@/components/Blocks/SectionBlock/TwoColumn"
66
import {FunctionComponent} from "react"
7-
import dynamic from "next/dynamic"
87
import {GelijktijdigheidKpi} from "@/components/IJzerboeren/KPIs/GelijktijdigheidKPI"
98
import {LCOEVerwarmen} from "@/components/IJzerboeren/KPIs/LCOEVerwarmen"
109
import {CO2EmissionKPI} from "@/components/IJzerboeren/KPIs/CO2EmissionKPI"
1110
import {HeatingType} from "@/components/IJzerboeren/HeatingType/heating-type"
1211
import rawHtml from "@/components/RawHtml/RawHtml.module.css"
13-
14-
// This prevents an issue with server-side rendering
15-
const IronPowderSankey = dynamic(
16-
() => import('../Sankey/Sankey').then(res => res.IronPowderSankey),
17-
{ ssr: false }
18-
)
12+
import {IronPowderSankey} from "@/components/IJzerboeren/Sankey/dynamic-import"
1913

2014
export const Step2: FunctionComponent = () => {
2115
const [heatingType, previousHeatingType, setHeatingType] =

‎frontend/components/IJzerboeren/Step3/Step3.tsx

+1-7
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,13 @@ import {Step2Outputs} from "@/components/IJzerboeren/Step2/step2-data"
44
import {useStateWithHistory} from "@/components/IJzerboeren/useStateWithHistory"
55
import {TwoColumnSimulationLayout} from "@/components/Blocks/SectionBlock/TwoColumn"
66
import {FunctionComponent} from "react"
7-
import dynamic from "next/dynamic"
87
import {GelijktijdigheidKpi} from "@/components/IJzerboeren/KPIs/GelijktijdigheidKPI"
98
import {LCOEVerwarmen} from "@/components/IJzerboeren/KPIs/LCOEVerwarmen"
109
import {CO2EmissionKPI} from "@/components/IJzerboeren/KPIs/CO2EmissionKPI"
1110
import {step3Data} from "@/components/IJzerboeren/Step3/step3-data"
1211
import {HeatingType} from "@/components/IJzerboeren/HeatingType/heating-type"
1312
import rawHtml from "@/components/RawHtml/RawHtml.module.css"
14-
15-
// This prevents an issue with server-side rendering
16-
const IronPowderSankey = dynamic(
17-
() => import('../Sankey/Sankey').then(res => res.IronPowderSankey),
18-
{ ssr: false }
19-
)
13+
import {IronPowderSankey} from "@/components/IJzerboeren/Sankey/dynamic-import"
2014

2115
export const Step3: FunctionComponent = () => {
2216
const [heatingType, previousHeatingType, setHeatingType] =

0 commit comments

Comments
 (0)
Please sign in to comment.