Skip to content

Commit

Permalink
fix: separate input and processed data for points and links
Browse files Browse the repository at this point in the history
  • Loading branch information
Stukova committed Oct 4, 2024
1 parent 6501104 commit 1ac559a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ export class Graph {
* Example: `[1, 2, 3, 4, 5, 6]` sets the first point to (1, 2), the second point to (3, 4), and so on.
*/
public setPointPositions (pointPositions: number[]): void {
this.graph.pointPositions = pointPositions
this.graph.inputPointPositions = pointPositions
this._hasPointPositionsChanged = true
}

Expand Down Expand Up @@ -298,7 +298,7 @@ export class Graph {
* Example: `[0, 1, 1, 2]` creates a link from point 0 to point 1 and another link from point 1 to point 2.
*/
public setLinks (links: number[]): void {
this.graph.links = links
this.graph.inputLinks = links
this._hasLinksChanged = true
}

Expand Down
12 changes: 12 additions & 0 deletions src/modules/GraphData/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getRgbaColor, isNumber } from '@/graph/helper'
import { GraphConfig } from '@/graph/config'
export class GraphData {
public inputPointPositions: number[] | undefined
public inputPointColors: number[] | undefined
public inputPointSizes: number[] | undefined
public inputLinkColors: number[] | undefined
Expand All @@ -11,6 +12,7 @@ export class GraphData {
public pointColors: number[] | undefined
public pointSizes: number[] | undefined

public inputLinks: number[] | undefined
public links: number[] | undefined
public linkColors: number[] | undefined
public linkWidths: number[] | undefined
Expand Down Expand Up @@ -42,6 +44,10 @@ export class GraphData {
return this.links && this.links.length / 2
}

public updatePoints (): void {
this.pointPositions = this.inputPointPositions
}

/**
* Updates the point colors based on the input data or default config value.
*/
Expand Down Expand Up @@ -94,6 +100,10 @@ export class GraphData {
}
}

public updateLinks (): void {
this.links = this.inputLinks
}

/**
* Updates the link colors based on the input data or default config value.
*/
Expand Down Expand Up @@ -177,9 +187,11 @@ export class GraphData {
}

public update (): void {
this.updatePoints()
this.updatePointColor()
this.updatePointSize()

this.updateLinks()
this.updateLinkColor()
this.updateLinkWidth()
this.updateArrows()
Expand Down

0 comments on commit 1ac559a

Please sign in to comment.