Skip to content

Commit 7966c9e

Browse files
terapyonterapyon
authored andcommitted
updata graph.ts for settings
1 parent 971349f commit 7966c9e

File tree

2 files changed

+20
-25
lines changed

2 files changed

+20
-25
lines changed

src/graph.ts

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,8 @@
11
import * as d3 from 'd3';
22
import { SimulationNodeDatum, SimulationLinkDatum } from 'd3';
3+
import { Collors, Settings } from './settings';
34
import { convertToCategoryKey } from './utils/string';
45

5-
/**
6-
* Settings for the graph (inlined from deleted settings.ts)
7-
*/
8-
const Settings = {
9-
DEFAULT_NODE_SIZE: 5,
10-
DEFAULT_COLOR: 'TYPE_A',
11-
};
12-
13-
const Collors = {
14-
TYPE_A: 'red',
15-
TYPE_B: 'blue',
16-
TYPE_C: 'green',
17-
TYPE_D: 'yellow',
18-
TYPE_E: 'purple',
19-
TYPE_F: 'orange',
20-
TYPE_G: 'black',
21-
TYPE_H: 'white',
22-
};
23-
246
export interface Node extends SimulationNodeDatum {
257
id: string;
268
[key: string]: any; // Additional properties can be added
@@ -245,22 +227,18 @@ function Graph(svg: any, { nodes, links }: { nodes: Node[]; links: Link[] }) {
245227
export function renderGraph(container: HTMLElement, data: GraphData): void {
246228
// Validate data before rendering
247229
console.log('[NetVis] renderGraph called with data:', data);
248-
249230
if (!data) {
250231
console.error('[NetVis] Error: data is null or undefined');
251232
throw new Error('GraphData is required');
252233
}
253-
254234
if (!data.nodes) {
255235
console.error('[NetVis] Error: data.nodes is missing', data);
256236
throw new Error('GraphData must have nodes array');
257237
}
258-
259238
if (!data.links) {
260239
console.error('[NetVis] Error: data.links is missing', data);
261240
throw new Error('GraphData must have links array');
262241
}
263-
264242
console.log(
265243
`[NetVis] Rendering ${data.nodes.length} nodes and ${data.links.length} links`,
266244
);
@@ -273,7 +251,6 @@ export function renderGraph(container: HTMLElement, data: GraphData): void {
273251
}
274252
return false;
275253
});
276-
277254
if (missingIds.length > 0) {
278255
throw new Error(`${missingIds.length} nodes are missing 'id' field`);
279256
}
@@ -289,4 +266,4 @@ export function renderGraph(container: HTMLElement, data: GraphData): void {
289266
Graph(svg, data);
290267
}
291268

292-
export default Graph;
269+
// export default Graph;

src/settings.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Settings for the graph
3+
*/
4+
export const Settings = {
5+
DEFAULT_NODE_SIZE: 5,
6+
DEFAULT_COLOR: 'TYPE_A',
7+
};
8+
9+
export const Collors = {
10+
TYPE_A: 'red',
11+
TYPE_B: 'blue',
12+
TYPE_C: 'green',
13+
TYPE_D: 'yellow',
14+
TYPE_E: 'purple',
15+
TYPE_F: 'orange',
16+
TYPE_G: 'black',
17+
TYPE_H: 'white',
18+
};

0 commit comments

Comments
 (0)