Skip to content

Commit 83b15b5

Browse files
Merge pull request #13 from mezh-hq/perf/large-layouts
Perf/large layouts
2 parents f30031d + cff896e commit 83b15b5

File tree

4 files changed

+48
-42
lines changed

4 files changed

+48
-42
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
Changelog
22

3+
# v3.2.1 [2024-12-18]
4+
5+
## Patch Release
6+
7+
### Fixes
8+
- Updated performance when rendering large layouts
9+
10+
---
11+
312
# v3.2.0 [2024-12-07]
413

514
## Minor Release

src/components/workspace/elements/seat.tsx

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,17 @@ import { ISeat, ISeatCategory, ISection, SeatStatus } from "@/types/elements";
66
import { d3Extended } from "@/utils";
77
import { getDetailedSeat } from "./utils";
88

9-
export const seatSize = 28;
9+
const seatSize = 28;
1010

11-
export const seatLabelFontSize = seatSize / 3;
11+
const seatSizeHalf = seatSize / 2;
12+
13+
const seatLabelFontSize = seatSize / 3;
14+
15+
const seatIconXSubtract = seatSize / 2.73;
16+
17+
const seatIconYSubtract = seatSize / 2.65;
18+
19+
const seatIconSize = seatSize * 0.75;
1220

1321
export interface ISeatProps extends ISeat {
1422
className?: string;
@@ -30,7 +38,7 @@ const Seat: React.FC<ISeatProps> = forwardRef(
3038
categories,
3139
category,
3240
sections,
33-
status,
41+
status = SeatStatus.Available,
3442
onClick,
3543
consumer,
3644
rotation,
@@ -105,8 +113,6 @@ const Seat: React.FC<ISeatProps> = forwardRef(
105113
}
106114
};
107115

108-
status ??= SeatStatus.Available;
109-
110116
const seatProps = {
111117
ref,
112118
id,
@@ -134,24 +140,24 @@ const Seat: React.FC<ISeatProps> = forwardRef(
134140
<>
135141
{element.square ? (
136142
<rect
137-
x={x - seatSize / 2}
138-
y={y - seatSize / 2}
143+
x={x - seatSizeHalf}
144+
y={y - seatSizeHalf}
139145
height={seatSize}
140146
width={seatSize}
141147
rx={3}
142148
ry={3}
143149
{...seatProps}
144150
/>
145151
) : (
146-
<circle cx={x} cy={y} r={seatSize / 2} {...seatProps} />
152+
<circle cx={x} cy={y} r={seatSizeHalf} {...seatProps} />
147153
)}
148154
{SeatIcon && (
149155
<SeatIcon
150-
x={x - seatSize / 2.73}
151-
y={y - seatSize / 2.65}
152-
width={seatSize * 0.75}
153-
height={seatSize * 0.75}
154-
size={seatSize * 0.75}
156+
x={x - seatIconXSubtract}
157+
y={y - seatIconYSubtract}
158+
width={seatIconSize}
159+
height={seatIconSize}
160+
size={seatIconSize}
155161
className={twMerge(consumer.styles?.elements?.seat?.icon?.className, "stk-seat-icon")}
156162
style={consumer.styles?.elements?.seat?.icon?.properties}
157163
/>
@@ -169,7 +175,7 @@ const Seat: React.FC<ISeatProps> = forwardRef(
169175
{...{ [dataAttributes.elementType]: undefined }}
170176
className={twMerge(props.className, "unselectable !stroke-1")}
171177
>
172-
{label ?? "A"}
178+
{label}
173179
</text>
174180
)}
175181
</>

src/components/workspace/elements/utils.ts

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ const repositionShape = (shape, dx, dy) => {
4848
if (resizeCursors.includes(shape.style("cursor"))) return;
4949
const x = +shape.attr("x") + dx;
5050
const y = +shape.attr("y") + dy;
51-
shape.attr("x", x);
52-
shape.attr("y", y);
51+
shape.attr("x", x).attr("y", y);
5352
};
5453

5554
const repositionPolyline = (polyline, dx, dy) => {
@@ -101,57 +100,47 @@ export const handlePolylineDrag = drag().on("drag", function (event) {
101100
});
102101

103102
export const showSeat = (seat: d3.Selection<Element, {}, HTMLElement, any>) => {
104-
seat.style("opacity", "1");
105-
seat.style("pointer-events", "all");
106-
const label = d3Extended.selectById(`${seat.attr("id")}-label`);
107-
label?.style("opacity", "1");
108-
label?.style("pointer-events", "all");
103+
seat.style("display", "block");
104+
d3Extended.selectById(`${seat.attr("id")}-label`)?.style("display", "block");
109105
};
110106

111107
export const hideSeat = (seat: d3.Selection<Element, {}, HTMLElement, any>) => {
112-
seat.style("opacity", "0");
113-
seat.style("pointer-events", "none");
114-
const label = d3Extended.selectById(`${seat.attr("id")}-label`);
115-
label?.style("opacity", "0");
116-
label?.style("pointer-events", "none");
108+
seat.style("display", "none");
109+
d3Extended.selectById(`${seat.attr("id")}-label`)?.style("display", "none");
117110
};
118111

119112
export const showPreOffsetElements = () => {
120113
const seats = d3Extended.selectAll(`[${dataAttributes.elementType}="${ElementType.Seat}"]`);
121-
if (seats.size() && +seats?.style("opacity") !== 0) {
114+
if (seats.size() && seats?.style("display") !== "none") {
122115
const sections = d3Extended.selectAll(
123116
`[${dataAttributes.elementType}="${ElementType.Polyline}"][${dataAttributes.section}]`
124117
);
125118
const elementsEmbracingOffset = d3Extended.selectAll(`[${dataAttributes.embraceOffset}="true"]`);
126-
seats.forEach(hideSeat);
119+
setTimeout(() => seats.forEach(hideSeat), 100);
127120
sections.forEach((section) => {
128-
section.style("opacity", 1);
129-
section.style("pointer-events", "all");
121+
section.style("opacity", 1).style("pointer-events", "all");
130122
});
131123
elementsEmbracingOffset.forEach((element) => {
132-
element.style("opacity", 1);
133-
element.style("pointer-events", "all");
124+
element.style("opacity", 1).style("pointer-events", "all");
134125
});
135126
}
136127
};
137128

138129
export const showPostOffsetElements = () => {
139130
const seats = d3Extended.selectAll(`[${dataAttributes.elementType}="${ElementType.Seat}"]`);
140-
if (seats.size() && +seats.style("opacity") !== 1) {
131+
if (seats.size() && seats.style("display") !== "block") {
141132
const sections = d3Extended.selectAll(
142133
`[${dataAttributes.elementType}="${ElementType.Polyline}"][${dataAttributes.section}]`
143134
);
144135
const elementsEmbracingOffset = d3Extended.selectAll(`[${dataAttributes.embraceOffset}="true"]`);
145136
seats.forEach(showSeat);
146137
sections.forEach((section) => {
147138
if (section.attr(dataAttributes.sectionFreeSeating) !== "true") {
148-
section.style("opacity", 0);
149-
section.style("pointer-events", "none");
139+
section.style("opacity", 0).style("pointer-events", "none");
150140
}
151141
});
152142
elementsEmbracingOffset.forEach((element) => {
153-
element.style("opacity", 0);
154-
element.style("pointer-events", "none");
143+
element.style("opacity", 0).style("pointer-events", "none");
155144
});
156145
}
157146
};
@@ -162,12 +151,10 @@ export const showAllElements = () => {
162151
const elementsEmbracingOffset = d3Extended.selectAll(`[${dataAttributes.embraceOffset}="true"]`);
163152
seats.forEach(showSeat);
164153
sections.forEach((section) => {
165-
section.style("opacity", 1);
166-
section.style("pointer-events", "all");
154+
section.style("opacity", 1).style("pointer-events", "all");
167155
});
168156
elementsEmbracingOffset.forEach((element) => {
169-
element.style("opacity", 1);
170-
element.style("pointer-events", "all");
157+
element.style("opacity", 1).style("pointer-events", "all");
171158
});
172159
};
173160

src/components/workspace/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ export const Workspace: React.FC<ISTKProps> = (props) => {
5858
style={props.styles?.workspace?.root?.properties}
5959
>
6060
<svg id={ids.workspace} className="w-full h-full flex-1" onMouseOver={onWorkspaceHover}>
61-
<g {...{ [dataAttributes.visibilityOffset]: "0" }} style={{ transformBox: "unset" }}>
61+
<g
62+
{...{ [dataAttributes.visibilityOffset]: "0" }}
63+
className="will-change-transform"
64+
style={{ transformBox: "unset" }}
65+
>
6266
{images.map((e) => (
6367
<Element
6468
key={e.id}

0 commit comments

Comments
 (0)