From 54d1c6f57d0cad8408c81dd3f34b1753e7003f2d Mon Sep 17 00:00:00 2001 From: Akalanka Perera Date: Wed, 18 Dec 2024 19:39:41 +0530 Subject: [PATCH 1/2] Perf: reduced a few computations --- src/components/workspace/elements/seat.tsx | 28 ++++++++++++++-------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/components/workspace/elements/seat.tsx b/src/components/workspace/elements/seat.tsx index 7a3e8bc..0e1f92d 100644 --- a/src/components/workspace/elements/seat.tsx +++ b/src/components/workspace/elements/seat.tsx @@ -6,9 +6,17 @@ import { ISeat, ISeatCategory, ISection, SeatStatus } from "@/types/elements"; import { d3Extended } from "@/utils"; import { getDetailedSeat } from "./utils"; -export const seatSize = 28; +const seatSize = 28; -export const seatLabelFontSize = seatSize / 3; +const seatSizeHalf = seatSize / 2; + +const seatLabelFontSize = seatSize / 3; + +const seatIconXSubtract = seatSize / 2.73; + +const seatIconYSubtract = seatSize / 2.65; + +const seatIconSize = seatSize * 0.75; export interface ISeatProps extends ISeat { className?: string; @@ -134,8 +142,8 @@ const Seat: React.FC = forwardRef( <> {element.square ? ( = forwardRef( {...seatProps} /> ) : ( - + )} {SeatIcon && ( From cff896e67872914470003c139c87f8eeddcc0e23 Mon Sep 17 00:00:00 2001 From: Akalanka Perera Date: Wed, 18 Dec 2024 22:36:43 +0530 Subject: [PATCH 2/2] Patch: updated element visibility to improve performance --- CHANGELOG.md | 9 +++++ src/components/workspace/elements/seat.tsx | 6 ++-- src/components/workspace/elements/utils.ts | 41 ++++++++-------------- src/components/workspace/index.tsx | 6 +++- 4 files changed, 30 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 80d0d0c..57f8791 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ Changelog +# v3.2.1 [2024-12-18] + +## Patch Release + +### Fixes +- Updated performance when rendering large layouts + +--- + # v3.2.0 [2024-12-07] ## Minor Release diff --git a/src/components/workspace/elements/seat.tsx b/src/components/workspace/elements/seat.tsx index 0e1f92d..5920803 100644 --- a/src/components/workspace/elements/seat.tsx +++ b/src/components/workspace/elements/seat.tsx @@ -38,7 +38,7 @@ const Seat: React.FC = forwardRef( categories, category, sections, - status, + status = SeatStatus.Available, onClick, consumer, rotation, @@ -113,8 +113,6 @@ const Seat: React.FC = forwardRef( } }; - status ??= SeatStatus.Available; - const seatProps = { ref, id, @@ -177,7 +175,7 @@ const Seat: React.FC = forwardRef( {...{ [dataAttributes.elementType]: undefined }} className={twMerge(props.className, "unselectable !stroke-1")} > - {label ?? "A"} + {label} )} diff --git a/src/components/workspace/elements/utils.ts b/src/components/workspace/elements/utils.ts index fc8bbb3..db27a8e 100644 --- a/src/components/workspace/elements/utils.ts +++ b/src/components/workspace/elements/utils.ts @@ -48,8 +48,7 @@ const repositionShape = (shape, dx, dy) => { if (resizeCursors.includes(shape.style("cursor"))) return; const x = +shape.attr("x") + dx; const y = +shape.attr("y") + dy; - shape.attr("x", x); - shape.attr("y", y); + shape.attr("x", x).attr("y", y); }; const repositionPolyline = (polyline, dx, dy) => { @@ -101,43 +100,35 @@ export const handlePolylineDrag = drag().on("drag", function (event) { }); export const showSeat = (seat: d3.Selection) => { - seat.style("opacity", "1"); - seat.style("pointer-events", "all"); - const label = d3Extended.selectById(`${seat.attr("id")}-label`); - label?.style("opacity", "1"); - label?.style("pointer-events", "all"); + seat.style("display", "block"); + d3Extended.selectById(`${seat.attr("id")}-label`)?.style("display", "block"); }; export const hideSeat = (seat: d3.Selection) => { - seat.style("opacity", "0"); - seat.style("pointer-events", "none"); - const label = d3Extended.selectById(`${seat.attr("id")}-label`); - label?.style("opacity", "0"); - label?.style("pointer-events", "none"); + seat.style("display", "none"); + d3Extended.selectById(`${seat.attr("id")}-label`)?.style("display", "none"); }; export const showPreOffsetElements = () => { const seats = d3Extended.selectAll(`[${dataAttributes.elementType}="${ElementType.Seat}"]`); - if (seats.size() && +seats?.style("opacity") !== 0) { + if (seats.size() && seats?.style("display") !== "none") { const sections = d3Extended.selectAll( `[${dataAttributes.elementType}="${ElementType.Polyline}"][${dataAttributes.section}]` ); const elementsEmbracingOffset = d3Extended.selectAll(`[${dataAttributes.embraceOffset}="true"]`); - seats.forEach(hideSeat); + setTimeout(() => seats.forEach(hideSeat), 100); sections.forEach((section) => { - section.style("opacity", 1); - section.style("pointer-events", "all"); + section.style("opacity", 1).style("pointer-events", "all"); }); elementsEmbracingOffset.forEach((element) => { - element.style("opacity", 1); - element.style("pointer-events", "all"); + element.style("opacity", 1).style("pointer-events", "all"); }); } }; export const showPostOffsetElements = () => { const seats = d3Extended.selectAll(`[${dataAttributes.elementType}="${ElementType.Seat}"]`); - if (seats.size() && +seats.style("opacity") !== 1) { + if (seats.size() && seats.style("display") !== "block") { const sections = d3Extended.selectAll( `[${dataAttributes.elementType}="${ElementType.Polyline}"][${dataAttributes.section}]` ); @@ -145,13 +136,11 @@ export const showPostOffsetElements = () => { seats.forEach(showSeat); sections.forEach((section) => { if (section.attr(dataAttributes.sectionFreeSeating) !== "true") { - section.style("opacity", 0); - section.style("pointer-events", "none"); + section.style("opacity", 0).style("pointer-events", "none"); } }); elementsEmbracingOffset.forEach((element) => { - element.style("opacity", 0); - element.style("pointer-events", "none"); + element.style("opacity", 0).style("pointer-events", "none"); }); } }; @@ -162,12 +151,10 @@ export const showAllElements = () => { const elementsEmbracingOffset = d3Extended.selectAll(`[${dataAttributes.embraceOffset}="true"]`); seats.forEach(showSeat); sections.forEach((section) => { - section.style("opacity", 1); - section.style("pointer-events", "all"); + section.style("opacity", 1).style("pointer-events", "all"); }); elementsEmbracingOffset.forEach((element) => { - element.style("opacity", 1); - element.style("pointer-events", "all"); + element.style("opacity", 1).style("pointer-events", "all"); }); }; diff --git a/src/components/workspace/index.tsx b/src/components/workspace/index.tsx index 044dc15..59ac0b8 100644 --- a/src/components/workspace/index.tsx +++ b/src/components/workspace/index.tsx @@ -58,7 +58,11 @@ export const Workspace: React.FC = (props) => { style={props.styles?.workspace?.root?.properties} > - + {images.map((e) => (