Spaces:
Running
Running
Commit
·
5fc2d28
1
Parent(s):
513a8f8
ui finished v1
Browse files- config.json +9 -9
- css/style.css +6 -0
- daily-paper-atlas/js/main.js +88 -1
- graph.json +0 -0
- json_converter.js +116 -0
- sigma_graph.json +0 -0
config.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
{
|
2 |
"type": "network",
|
3 |
"version": "1.0",
|
4 |
-
"data": "
|
5 |
"logo": {
|
6 |
"file": "",
|
7 |
"link": "",
|
@@ -54,10 +54,10 @@
|
|
54 |
"defaultLabelSize": 14
|
55 |
},
|
56 |
"graphProperties": {
|
57 |
-
"maxEdgeSize":
|
58 |
-
"minEdgeSize": 0.
|
59 |
-
"minNodeSize":
|
60 |
-
"maxNodeSize":
|
61 |
},
|
62 |
"mouseProperties": {
|
63 |
"maxRatio": 20,
|
@@ -65,13 +65,13 @@
|
|
65 |
}
|
66 |
},
|
67 |
"nodeTypes": {
|
68 |
-
"paper": { "color": "#
|
69 |
-
"author": { "color": "#
|
70 |
-
"organization": { "color": "#
|
71 |
"unknown": { "color": "#ff7f0e", "size": 3 }
|
72 |
},
|
73 |
"colorPalette": [
|
74 |
-
"#
|
75 |
"#ff7f0e", "#d62728", "#8c564b", "#e377c2",
|
76 |
"#bcbd22", "#7f7f7f"
|
77 |
]
|
|
|
1 |
{
|
2 |
"type": "network",
|
3 |
"version": "1.0",
|
4 |
+
"data": "sigma_graph.json",
|
5 |
"logo": {
|
6 |
"file": "",
|
7 |
"link": "",
|
|
|
54 |
"defaultLabelSize": 14
|
55 |
},
|
56 |
"graphProperties": {
|
57 |
+
"maxEdgeSize": 1.5,
|
58 |
+
"minEdgeSize": 0.2,
|
59 |
+
"minNodeSize": 1,
|
60 |
+
"maxNodeSize": 8
|
61 |
},
|
62 |
"mouseProperties": {
|
63 |
"maxRatio": 20,
|
|
|
65 |
}
|
66 |
},
|
67 |
"nodeTypes": {
|
68 |
+
"paper": { "color": "#FF009A", "size": 1 },
|
69 |
+
"author": { "color": "#62D600", "size": 1 },
|
70 |
+
"organization": { "color": "#020AA7", "size": 1 },
|
71 |
"unknown": { "color": "#ff7f0e", "size": 3 }
|
72 |
},
|
73 |
"colorPalette": [
|
74 |
+
"#FF9A00", "#62D600", "#020AA7", "#17becf",
|
75 |
"#ff7f0e", "#d62728", "#8c564b", "#e377c2",
|
76 |
"#bcbd22", "#7f7f7f"
|
77 |
]
|
css/style.css
CHANGED
@@ -556,4 +556,10 @@ canvas#sigma_bg_1 {
|
|
556 |
margin-bottom: 12px;
|
557 |
font-size: 13px;
|
558 |
display: block;
|
|
|
|
|
|
|
|
|
|
|
|
|
559 |
}
|
|
|
556 |
margin-bottom: 12px;
|
557 |
font-size: 13px;
|
558 |
display: block;
|
559 |
+
}
|
560 |
+
|
561 |
+
/* Hide debug controls */
|
562 |
+
#debug-controls,
|
563 |
+
#config-debug {
|
564 |
+
display: none !important;
|
565 |
}
|
daily-paper-atlas/js/main.js
CHANGED
@@ -23,6 +23,87 @@ function forceEdgeColors() {
|
|
23 |
console.log("Edge colors have been forcibly updated");
|
24 |
}
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
// Initialize the graph with the loaded data
|
27 |
function initializeGraph(data) {
|
28 |
graph = data;
|
@@ -103,7 +184,10 @@ function initializeGraph(data) {
|
|
103 |
// Force redraw and refresh
|
104 |
sigmaInstance.draw(2, 2, 2, 2);
|
105 |
|
106 |
-
// Force
|
|
|
|
|
|
|
107 |
forceEdgeColors();
|
108 |
|
109 |
console.log("Sigma instance created and configured:", sigmaInstance);
|
@@ -130,10 +214,13 @@ function applyNodeStyles() {
|
|
130 |
try {
|
131 |
// First update node colors
|
132 |
sigmaInstance.iterNodes(function(node) {
|
|
|
133 |
if (node.type && config.nodeTypes && config.nodeTypes[node.type]) {
|
|
|
134 |
node.color = config.nodeTypes[node.type].color;
|
135 |
node.size = config.nodeTypes[node.type].size;
|
136 |
} else if (node.type && nodeTypes[node.type]) {
|
|
|
137 |
node.color = nodeTypes[node.type].color;
|
138 |
node.size = nodeTypes[node.type].size;
|
139 |
}
|
|
|
23 |
console.log("Edge colors have been forcibly updated");
|
24 |
}
|
25 |
|
26 |
+
// Log node colors for debugging
|
27 |
+
function logNodeColors() {
|
28 |
+
if (!sigmaInstance) return;
|
29 |
+
|
30 |
+
console.log("Current node colors by type:");
|
31 |
+
let typeColors = {};
|
32 |
+
|
33 |
+
// Collect colors for each node type
|
34 |
+
sigmaInstance.iterNodes(function(node) {
|
35 |
+
if (node.type) {
|
36 |
+
if (!typeColors[node.type]) {
|
37 |
+
typeColors[node.type] = {
|
38 |
+
configColor: (config.nodeTypes && config.nodeTypes[node.type])
|
39 |
+
? config.nodeTypes[node.type].color
|
40 |
+
: (nodeTypes[node.type] ? nodeTypes[node.type].color : 'none'),
|
41 |
+
nodeCount: 0,
|
42 |
+
colorCounts: {}
|
43 |
+
};
|
44 |
+
}
|
45 |
+
|
46 |
+
typeColors[node.type].nodeCount++;
|
47 |
+
|
48 |
+
if (!typeColors[node.type].colorCounts[node.color]) {
|
49 |
+
typeColors[node.type].colorCounts[node.color] = 0;
|
50 |
+
}
|
51 |
+
typeColors[node.type].colorCounts[node.color]++;
|
52 |
+
}
|
53 |
+
});
|
54 |
+
|
55 |
+
// Log the results
|
56 |
+
for (const type in typeColors) {
|
57 |
+
console.log(`Node type: ${type}`);
|
58 |
+
console.log(` Config color: ${typeColors[type].configColor}`);
|
59 |
+
console.log(` Node count: ${typeColors[type].nodeCount}`);
|
60 |
+
console.log(' Actual colors used:');
|
61 |
+
for (const color in typeColors[type].colorCounts) {
|
62 |
+
console.log(` ${color}: ${typeColors[type].colorCounts[color]} nodes`);
|
63 |
+
}
|
64 |
+
}
|
65 |
+
}
|
66 |
+
|
67 |
+
// Force apply node colors from config, overriding any colors in the data
|
68 |
+
function forceNodeColorsFromConfig() {
|
69 |
+
console.log("Forcibly applying node colors from config settings");
|
70 |
+
|
71 |
+
if (!sigmaInstance) {
|
72 |
+
console.error("Cannot apply node colors, sigma instance not initialized");
|
73 |
+
return;
|
74 |
+
}
|
75 |
+
|
76 |
+
// Use configured node types with fallback to default types
|
77 |
+
let configNodeTypes = config.nodeTypes || nodeTypes;
|
78 |
+
|
79 |
+
// Apply colors to all nodes based on their type
|
80 |
+
sigmaInstance.iterNodes(function(node) {
|
81 |
+
if (node.type && configNodeTypes[node.type]) {
|
82 |
+
// Override the node color with the one from config
|
83 |
+
const configColor = configNodeTypes[node.type].color;
|
84 |
+
console.log(`Setting node ${node.id} color to ${configColor} based on type ${node.type}`);
|
85 |
+
node.color = configColor;
|
86 |
+
|
87 |
+
// Also set size if configured
|
88 |
+
if (configNodeTypes[node.type].size) {
|
89 |
+
node.size = configNodeTypes[node.type].size;
|
90 |
+
}
|
91 |
+
}
|
92 |
+
});
|
93 |
+
|
94 |
+
// Refresh the display
|
95 |
+
sigmaInstance.refresh();
|
96 |
+
|
97 |
+
// Also update edge colors to match their target nodes
|
98 |
+
setTimeout(function() {
|
99 |
+
forceEdgeColors();
|
100 |
+
// Log node colors after setting them for verification
|
101 |
+
logNodeColors();
|
102 |
+
}, 100);
|
103 |
+
|
104 |
+
console.log("Node colors have been forcibly applied from config");
|
105 |
+
}
|
106 |
+
|
107 |
// Initialize the graph with the loaded data
|
108 |
function initializeGraph(data) {
|
109 |
graph = data;
|
|
|
184 |
// Force redraw and refresh
|
185 |
sigmaInstance.draw(2, 2, 2, 2);
|
186 |
|
187 |
+
// Force apply node colors from config to override any hardcoded colors in the data
|
188 |
+
forceNodeColorsFromConfig();
|
189 |
+
|
190 |
+
// Force edge colors again after applying node colors
|
191 |
forceEdgeColors();
|
192 |
|
193 |
console.log("Sigma instance created and configured:", sigmaInstance);
|
|
|
214 |
try {
|
215 |
// First update node colors
|
216 |
sigmaInstance.iterNodes(function(node) {
|
217 |
+
// Always use config colors for node types, ignoring any existing colors
|
218 |
if (node.type && config.nodeTypes && config.nodeTypes[node.type]) {
|
219 |
+
// Override with config color (even if node already has a color)
|
220 |
node.color = config.nodeTypes[node.type].color;
|
221 |
node.size = config.nodeTypes[node.type].size;
|
222 |
} else if (node.type && nodeTypes[node.type]) {
|
223 |
+
// Fallback to default colors
|
224 |
node.color = nodeTypes[node.type].color;
|
225 |
node.size = nodeTypes[node.type].size;
|
226 |
}
|
graph.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
json_converter.js
ADDED
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* JSON Format Converter
|
3 |
+
*
|
4 |
+
* This script converts the graph.json file from its source format to the format
|
5 |
+
* expected by the SigmaJS visualization library.
|
6 |
+
*/
|
7 |
+
|
8 |
+
// Load required modules
|
9 |
+
const fs = require('fs');
|
10 |
+
const path = require('path');
|
11 |
+
|
12 |
+
// File paths
|
13 |
+
const sourcePath = 'graph.json';
|
14 |
+
const outputPath = 'sigma_graph.json';
|
15 |
+
|
16 |
+
// Load config to access node type colors
|
17 |
+
let config;
|
18 |
+
try {
|
19 |
+
config = JSON.parse(fs.readFileSync('config.json', 'utf8'));
|
20 |
+
} catch (error) {
|
21 |
+
console.error('Error loading config.json:', error);
|
22 |
+
config = {
|
23 |
+
nodeTypes: {
|
24 |
+
paper: { color: '#FF9A00', size: 3 },
|
25 |
+
author: { color: '#62D600', size: 5 },
|
26 |
+
organization: { color: '#020AA7', size: 4 },
|
27 |
+
unknown: { color: '#ff7f0e', size: 3 }
|
28 |
+
}
|
29 |
+
};
|
30 |
+
}
|
31 |
+
|
32 |
+
// Convert the graph JSON
|
33 |
+
function convertGraph() {
|
34 |
+
try {
|
35 |
+
// Read the source file
|
36 |
+
const graphData = JSON.parse(fs.readFileSync(sourcePath, 'utf8'));
|
37 |
+
|
38 |
+
// Prepare the SigmaJS JSON structure
|
39 |
+
const sigmaData = {
|
40 |
+
nodes: [],
|
41 |
+
edges: []
|
42 |
+
};
|
43 |
+
|
44 |
+
// Process nodes
|
45 |
+
graphData.nodes.forEach(node => {
|
46 |
+
// Extract node data
|
47 |
+
const nodeType = node.attributes.type || 'unknown';
|
48 |
+
const nodeColor = (nodeType && config.nodeTypes && config.nodeTypes[nodeType])
|
49 |
+
? config.nodeTypes[nodeType].color
|
50 |
+
: node.attributes.color || '#666';
|
51 |
+
|
52 |
+
// Create node in SigmaJS format
|
53 |
+
const sigmaNode = {
|
54 |
+
id: node.key,
|
55 |
+
label: node.attributes.label || node.key,
|
56 |
+
x: node.attributes.x || 0,
|
57 |
+
y: node.attributes.y || 0,
|
58 |
+
size: node.attributes.size || 1,
|
59 |
+
color: nodeColor,
|
60 |
+
type: nodeType,
|
61 |
+
attr: { colors: {} }
|
62 |
+
};
|
63 |
+
|
64 |
+
// Add type to colors attribute for filtering
|
65 |
+
if (nodeType) {
|
66 |
+
sigmaNode.attr.colors.type = nodeType;
|
67 |
+
}
|
68 |
+
|
69 |
+
// Add any additional attributes
|
70 |
+
for (const [key, value] of Object.entries(node.attributes)) {
|
71 |
+
if (!['label', 'x', 'y', 'size', 'color', 'type'].includes(key)) {
|
72 |
+
sigmaNode[key] = value;
|
73 |
+
}
|
74 |
+
}
|
75 |
+
|
76 |
+
sigmaData.nodes.push(sigmaNode);
|
77 |
+
});
|
78 |
+
|
79 |
+
// Process edges
|
80 |
+
let edgeCount = 0;
|
81 |
+
graphData.edges.forEach(edge => {
|
82 |
+
// Create edge in SigmaJS format
|
83 |
+
const sigmaEdge = {
|
84 |
+
id: edge.key || `e${edgeCount++}`,
|
85 |
+
source: edge.source,
|
86 |
+
target: edge.target
|
87 |
+
};
|
88 |
+
|
89 |
+
// Add weight if available
|
90 |
+
if (edge.attributes && edge.attributes.weight) {
|
91 |
+
sigmaEdge.weight = edge.attributes.weight;
|
92 |
+
}
|
93 |
+
|
94 |
+
// Add label if available
|
95 |
+
if (edge.attributes && edge.attributes.label) {
|
96 |
+
sigmaEdge.label = edge.attributes.label;
|
97 |
+
}
|
98 |
+
|
99 |
+
sigmaData.edges.push(sigmaEdge);
|
100 |
+
});
|
101 |
+
|
102 |
+
// Write the converted data
|
103 |
+
fs.writeFileSync(outputPath, JSON.stringify(sigmaData, null, 2));
|
104 |
+
|
105 |
+
return true;
|
106 |
+
} catch (error) {
|
107 |
+
console.error('Error during conversion:', error);
|
108 |
+
return false;
|
109 |
+
}
|
110 |
+
}
|
111 |
+
|
112 |
+
// Execute the conversion
|
113 |
+
convertGraph();
|
114 |
+
|
115 |
+
// Export function for potential reuse
|
116 |
+
module.exports = { convertGraph };
|
sigma_graph.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|