Skip to content

Commit 73d8b37

Browse files
committed
refactor: replace globalCompositeOperation with zIndex-based rendering (#163)
1 parent c0a58d1 commit 73d8b37

File tree

4 files changed

+13
-47
lines changed

4 files changed

+13
-47
lines changed

src/components/canvas/connections/BatchPath2D/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export class BatchPath2DRenderer {
136136

137137
public orderedPaths = cache(() => {
138138
return Array.from(this.indexes.entries())
139-
.sort(([indexA], [indexB]) => indexB - indexA)
139+
.sort(([indexA], [indexB]) => indexA - indexB)
140140
.reduce((acc, [_, items]) => {
141141
acc.push(...Array.from(items.values()));
142142
return acc;

src/components/canvas/connections/BlockConnection.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export class BlockConnection<T extends TConnection>
8080
// Handle arrow visibility based on the provided props
8181
if (props.showConnectionArrows) {
8282
// Update will handle adding if not already in batch or updating if it is
83-
this.context.batch.update(this.arrowShape, { zIndex: zIndex, group: `arrow/${this.getClassName(state)}` });
83+
this.context.batch.update(this.arrowShape, { zIndex: zIndex - 1, group: `arrow/${this.getClassName(state)}` });
8484
} else {
8585
// Remove arrow from batch if showConnectionArrows is false
8686
this.context.batch.delete(this.arrowShape);
@@ -284,16 +284,6 @@ export class BlockConnection<T extends TConnection>
284284

285285
this.labelGeometry = { x, y, width, height };
286286

287-
ctx.fillStyle = this.context.colors.connectionLabel.text;
288-
289-
if (this.state.hovered) ctx.fillStyle = this.context.colors.connectionLabel.hoverText;
290-
if (this.state.selected) ctx.fillStyle = this.context.colors.connectionLabel.selectedText;
291-
292-
ctx.textBaseline = "top";
293-
ctx.textAlign = aligment;
294-
ctx.font = font;
295-
ctx.fillText(this.state.label, x + padding, y + padding);
296-
297287
ctx.fillStyle = this.context.colors.connectionLabel.background;
298288

299289
if (this.state.hovered) ctx.fillStyle = this.context.colors.connectionLabel.hoverBackground;
@@ -305,6 +295,16 @@ export class BlockConnection<T extends TConnection>
305295
measure.width + labelInnerLeftPadding + labelInnerRightPadding,
306296
measure.height + labelInnerTopPadding + labelInnerBottomPadding
307297
);
298+
299+
ctx.fillStyle = this.context.colors.connectionLabel.text;
300+
301+
if (this.state.hovered) ctx.fillStyle = this.context.colors.connectionLabel.hoverText;
302+
if (this.state.selected) ctx.fillStyle = this.context.colors.connectionLabel.selectedText;
303+
304+
ctx.textBaseline = "top";
305+
ctx.textAlign = aligment;
306+
ctx.font = font;
307+
ctx.fillText(this.state.label, x + padding, y + padding);
308308
}
309309

310310
public getStrokeColor(state: TConnection) {

src/components/canvas/layers/graphLayer/GraphLayer.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import { Blocks } from "../../blocks/Blocks";
1010
import { BlockConnection } from "../../connections/BlockConnection";
1111
import { BlockConnections } from "../../connections/BlockConnections";
1212

13-
import { DrawBelow, DrawOver } from "./helpers";
14-
1513
export type TGraphLayerProps = LayerProps & {
1614
camera: ICamera;
1715
root: HTMLDivElement;
@@ -329,8 +327,7 @@ export class GraphLayer extends Layer<TGraphLayerProps, TGraphLayerContext> {
329327

330328
public updateChildren() {
331329
const cameraProps: TCameraProps = {
332-
/* Blocks must be initialized before connections as connections need Block instances to access their geometry */
333-
children: [DrawOver.create(), Blocks.create(), DrawBelow.create(), BlockConnections.create()],
330+
children: [BlockConnections.create(), Blocks.create()],
334331
root: this.root,
335332
};
336333

src/components/canvas/layers/graphLayer/helpers.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)