Skip to content

Commit cff896e

Browse files
committed
Patch: updated element visibility to improve performance
1 parent 54d1c6f commit cff896e

File tree

4 files changed

+30
-32
lines changed

4 files changed

+30
-32
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: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const Seat: React.FC<ISeatProps> = forwardRef(
3838
categories,
3939
category,
4040
sections,
41-
status,
41+
status = SeatStatus.Available,
4242
onClick,
4343
consumer,
4444
rotation,
@@ -113,8 +113,6 @@ const Seat: React.FC<ISeatProps> = forwardRef(
113113
}
114114
};
115115

116-
status ??= SeatStatus.Available;
117-
118116
const seatProps = {
119117
ref,
120118
id,
@@ -177,7 +175,7 @@ const Seat: React.FC<ISeatProps> = forwardRef(
177175
{...{ [dataAttributes.elementType]: undefined }}
178176
className={twMerge(props.className, "unselectable !stroke-1")}
179177
>
180-
{label ?? "A"}
178+
{label}
181179
</text>
182180
)}
183181
</>

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)