-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: store whiteboard paths as point array
- Loading branch information
Showing
5 changed files
with
53 additions
and
9 deletions.
There are no files selected for viewing
3 changes: 1 addition & 2 deletions
3
...ices/ConferenceManagement/Strive.Core/Services/WhiteboardService/CanvasData/CanvasPath.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
#pragma warning disable 8618 | ||
|
||
using System.Collections.Generic; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace Strive.Core.Services.WhiteboardService.CanvasData | ||
{ | ||
public record CanvasPath : CanvasObject | ||
{ | ||
public IReadOnlyList<JValue[]> Path { get; set; } | ||
public IReadOnlyList<CanvasPoint> Path { get; set; } | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/Web/WebSPA/Client/src/features/whiteboard/path-cache.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { uncompressPathData } from './path-compression'; | ||
import { CanvasObject, VersionedCanvasObject, WhiteboardCanvas } from './types'; | ||
|
||
export default class PathCache { | ||
private uncompressedPaths = new Map<string, CanvasObject>(); | ||
|
||
public preprocess(canvas: WhiteboardCanvas): WhiteboardCanvas { | ||
const requiredPathIds = Object.fromEntries(Array.from(this.uncompressedPaths.keys()).map((x) => [x, false])); | ||
|
||
const uncompressPath = (obj: VersionedCanvasObject) => { | ||
requiredPathIds[obj.id] = true; | ||
|
||
let cached: any = this.uncompressedPaths.get(obj.id); | ||
if (!cached) { | ||
cached = uncompressPathData(obj.data); | ||
this.uncompressedPaths.set(obj.id, cached); | ||
} | ||
|
||
return { ...obj, data: { ...obj.data, path: cached } }; | ||
}; | ||
|
||
const result = { | ||
...canvas, | ||
objects: canvas.objects.map((x) => (x.data.type === 'path' ? uncompressPath(x) : x)), | ||
}; | ||
|
||
for (const [id, used] of Object.entries(requiredPathIds)) { | ||
if (!used) { | ||
this.uncompressedPaths.delete(id); | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
} |
18 changes: 12 additions & 6 deletions
18
src/Web/WebSPA/Client/src/features/whiteboard/path-compression.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters