MCPcopy
hub / github.com/opentrace/opentrace / addData

Method addData

ui/src/components/pixi/PixiRenderer.ts:701–799  ·  view source on GitHub ↗

* Incrementally add new nodes and edges without touching existing sprites.

(
    newNodes: GraphNode[],
    newLinks: GraphLink[],
    positions: Map<string, { x: number; y: number }>,
    nodeColors: Map<string, string>,
    nodeSizes: Map<string, number>,
    linkColors: Map<string, string>,
  )

Source from the content-addressed store, hash-verified

699 * Incrementally add new nodes and edges without touching existing sprites.
700 */
701 async addData(
702 newNodes: GraphNode[],
703 newLinks: GraphLink[],
704 positions: Map<string, { x: number; y: number }>,
705 nodeColors: Map<string, string>,
706 nodeSizes: Map<string, number>,
707 linkColors: Map<string, string>,
708 ): Promise<void> {
709 if (this.initPromise) await this.initPromise;
710 if (
711 this.destroyed ||
712 !this.app ||
713 !this.nodeContainer ||
714 !this.labelContainer
715 )
716 return;
717
718 // Add only nodes not already present
719 for (const gn of newNodes) {
720 if (this.nodes.has(gn.id)) continue;
721
722 const pos = positions.get(gn.id) ?? { x: 0, y: 0 };
723 const color = nodeColors.get(gn.id) ?? '#888888';
724 const size = nodeSizes.get(gn.id) ?? 4;
725 const tex = getCircleTexture(this.app, color, this.textureCache);
726
727 const sprite = new Sprite(tex);
728 sprite.anchor.set(0.5);
729 sprite.scale.set(size / CIRCLE_RADIUS);
730 sprite.alpha = 0.9;
731 sprite.position.set(pos.x, pos.y);
732 this.nodeContainer.addChild(sprite);
733
734 const node: PixiNode = {
735 id: gn.id,
736 graphNode: gn,
737 x: pos.x,
738 y: pos.y,
739 size,
740 color,
741 sprite,
742 visible: true,
743 };
744 this.nodeIdToIndex.set(gn.id, this.nodeArray.length);
745 this.nodeArray.push(node);
746 this.nodes.set(gn.id, node);
747 }
748
749 // Add only edges not already present
750 const existingEdgeKeys = new Set(
751 this.edges.map((e) => `${e.sourceId}-${e.label}-${e.targetId}`),
752 );
753 for (const gl of newLinks) {
754 const sourceId =
755 typeof gl.source === 'string' ? gl.source : (gl.source as GraphNode).id;
756 const targetId =
757 typeof gl.target === 'string' ? gl.target : (gl.target as GraphNode).id;
758 if (!this.nodes.has(sourceId) || !this.nodes.has(targetId)) continue;

Callers 1

Calls 8

redrawAllEdgesMethod · 0.95
rebuildQuadtreeMethod · 0.95
applyCounterScaleMethod · 0.95
getCircleTextureFunction · 0.90
selectBreakpointFunction · 0.90
pushMethod · 0.80
getMethod · 0.65
addMethod · 0.45

Tested by

no test coverage detected