@matdata/yasgui-graph-plugin 1.0.8 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -6
- package/dist/yasgui-graph-plugin.cjs.js +147 -42
- package/dist/yasgui-graph-plugin.cjs.js.map +3 -3
- package/dist/yasgui-graph-plugin.esm.js +147 -42
- package/dist/yasgui-graph-plugin.esm.js.map +3 -3
- package/dist/yasgui-graph-plugin.min.js +32 -25
- package/dist/yasgui-graph-plugin.min.js.map +4 -4
- package/package.json +2 -2
|
@@ -44,7 +44,7 @@ function truncateLabel(text, maxLength = 50) {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
// src/networkConfig.js
|
|
47
|
-
function getDefaultNetworkOptions() {
|
|
47
|
+
function getDefaultNetworkOptions(themeColors) {
|
|
48
48
|
return {
|
|
49
49
|
autoResize: true,
|
|
50
50
|
width: "100%",
|
|
@@ -75,27 +75,20 @@ function getDefaultNetworkOptions() {
|
|
|
75
75
|
},
|
|
76
76
|
nodes: {
|
|
77
77
|
shape: "dot",
|
|
78
|
-
size:
|
|
78
|
+
size: 10,
|
|
79
79
|
font: {
|
|
80
|
-
size:
|
|
81
|
-
color:
|
|
82
|
-
align: "center",
|
|
83
|
-
vadjust: 0,
|
|
84
|
-
multi: false
|
|
80
|
+
size: 12,
|
|
81
|
+
color: themeColors.text
|
|
85
82
|
},
|
|
86
|
-
borderWidth:
|
|
87
|
-
borderWidthSelected:
|
|
88
|
-
labelHighlightBold: true
|
|
89
|
-
fixed: {
|
|
90
|
-
x: false,
|
|
91
|
-
y: false
|
|
92
|
-
}
|
|
83
|
+
borderWidth: 1,
|
|
84
|
+
borderWidthSelected: 2,
|
|
85
|
+
labelHighlightBold: true
|
|
93
86
|
},
|
|
94
87
|
edges: {
|
|
95
88
|
arrows: {
|
|
96
89
|
to: {
|
|
97
90
|
enabled: true,
|
|
98
|
-
scaleFactor: 0.
|
|
91
|
+
scaleFactor: 0.6
|
|
99
92
|
}
|
|
100
93
|
},
|
|
101
94
|
smooth: {
|
|
@@ -104,7 +97,14 @@ function getDefaultNetworkOptions() {
|
|
|
104
97
|
},
|
|
105
98
|
font: {
|
|
106
99
|
size: 12,
|
|
107
|
-
align: "middle"
|
|
100
|
+
align: "middle",
|
|
101
|
+
color: themeColors.edgeLabel,
|
|
102
|
+
background: themeColors.edgeLabelBackground,
|
|
103
|
+
strokeWidth: 0
|
|
104
|
+
// Remove white outline/halo
|
|
105
|
+
},
|
|
106
|
+
color: {
|
|
107
|
+
color: themeColors.edge
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
};
|
|
@@ -137,24 +137,24 @@ function parseConstructResults(yasrResults) {
|
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
// src/colorUtils.js
|
|
140
|
-
function getNodeColor(node, triples) {
|
|
140
|
+
function getNodeColor(node, triples, themeColors) {
|
|
141
141
|
if (node.uri && node.uri.startsWith("_:")) {
|
|
142
|
-
return
|
|
142
|
+
return themeColors.blankNode;
|
|
143
143
|
}
|
|
144
144
|
if (node.type === "literal") {
|
|
145
|
-
return
|
|
145
|
+
return themeColors.literal;
|
|
146
146
|
}
|
|
147
147
|
const isTypeObject = triples.some(
|
|
148
148
|
(triple) => triple.predicate === "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" && triple.object.value === node.uri
|
|
149
149
|
);
|
|
150
150
|
if (isTypeObject) {
|
|
151
|
-
return
|
|
151
|
+
return themeColors.typeObject;
|
|
152
152
|
}
|
|
153
|
-
return
|
|
153
|
+
return themeColors.uri;
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
// src/transformers.js
|
|
157
|
-
function createNodeMap(triples, prefixMap) {
|
|
157
|
+
function createNodeMap(triples, prefixMap, themeColors) {
|
|
158
158
|
const nodeMap = /* @__PURE__ */ new Map();
|
|
159
159
|
let nodeId = 1;
|
|
160
160
|
triples.forEach((triple) => {
|
|
@@ -165,15 +165,10 @@ function createNodeMap(triples, prefixMap) {
|
|
|
165
165
|
id: nodeId++,
|
|
166
166
|
uri: triple.subject,
|
|
167
167
|
label,
|
|
168
|
-
color: getNodeColor({ uri: triple.subject, type: "uri" }, triples),
|
|
168
|
+
color: getNodeColor({ uri: triple.subject, type: "uri" }, triples, themeColors),
|
|
169
169
|
type: "uri",
|
|
170
170
|
fullValue: triple.subject,
|
|
171
|
-
title: isBlankNode ? triple.subject : applyPrefix(triple.subject, prefixMap)
|
|
172
|
-
font: {
|
|
173
|
-
vadjust: -30,
|
|
174
|
-
// Position label above the node
|
|
175
|
-
align: "center"
|
|
176
|
-
}
|
|
171
|
+
title: isBlankNode ? triple.subject : applyPrefix(triple.subject, prefixMap)
|
|
177
172
|
});
|
|
178
173
|
}
|
|
179
174
|
const objValue = triple.object.value;
|
|
@@ -200,16 +195,12 @@ function createNodeMap(triples, prefixMap) {
|
|
|
200
195
|
label,
|
|
201
196
|
color: getNodeColor(
|
|
202
197
|
{ uri: objValue, type: isLiteral ? "literal" : "uri" },
|
|
203
|
-
triples
|
|
198
|
+
triples,
|
|
199
|
+
themeColors
|
|
204
200
|
),
|
|
205
201
|
type: isLiteral ? "literal" : "uri",
|
|
206
202
|
fullValue,
|
|
207
|
-
title
|
|
208
|
-
font: {
|
|
209
|
-
vadjust: -30,
|
|
210
|
-
// Position label above the node
|
|
211
|
-
align: "center"
|
|
212
|
-
}
|
|
203
|
+
title
|
|
213
204
|
});
|
|
214
205
|
}
|
|
215
206
|
});
|
|
@@ -239,8 +230,8 @@ function createEdgesArray(triples, nodeMap, prefixMap) {
|
|
|
239
230
|
});
|
|
240
231
|
return edges;
|
|
241
232
|
}
|
|
242
|
-
function triplesToGraph(triples, prefixMap) {
|
|
243
|
-
const nodeMap = createNodeMap(triples, prefixMap);
|
|
233
|
+
function triplesToGraph(triples, prefixMap, themeColors) {
|
|
234
|
+
const nodeMap = createNodeMap(triples, prefixMap, themeColors);
|
|
244
235
|
const edges = createEdgesArray(triples, nodeMap, prefixMap);
|
|
245
236
|
const nodes = Array.from(nodeMap.values());
|
|
246
237
|
return { nodes, edges };
|
|
@@ -29947,6 +29938,66 @@ Network.prototype.getOptionsFromConfigurator = function() {
|
|
|
29947
29938
|
return options;
|
|
29948
29939
|
};
|
|
29949
29940
|
|
|
29941
|
+
// src/themeUtils.js
|
|
29942
|
+
function getCurrentTheme() {
|
|
29943
|
+
return document.documentElement.getAttribute("data-theme") || "light";
|
|
29944
|
+
}
|
|
29945
|
+
function getThemeNodeColors(theme) {
|
|
29946
|
+
if (theme === "dark") {
|
|
29947
|
+
return {
|
|
29948
|
+
uri: "#97C2FC",
|
|
29949
|
+
// Light blue for URIs
|
|
29950
|
+
literal: "#a6c8a6ff",
|
|
29951
|
+
// Light green for literals
|
|
29952
|
+
blankNode: "#888888",
|
|
29953
|
+
// Medium grey for blank nodes (darker than light mode)
|
|
29954
|
+
typeObject: "#e15b13ff",
|
|
29955
|
+
// Orange for rdf:type objects
|
|
29956
|
+
text: "#e0e0e0",
|
|
29957
|
+
// Light text for dark backgrounds
|
|
29958
|
+
edge: "#666666",
|
|
29959
|
+
// Darker edges
|
|
29960
|
+
edgeLabel: "#cccccc",
|
|
29961
|
+
// Lighter edge labels
|
|
29962
|
+
edgeLabelBackground: "rgba(30, 30, 30, 0.8)"
|
|
29963
|
+
// Dark semi-transparent background
|
|
29964
|
+
};
|
|
29965
|
+
}
|
|
29966
|
+
return {
|
|
29967
|
+
uri: "#97C2FC",
|
|
29968
|
+
// Light blue for URIs
|
|
29969
|
+
literal: "#a6c8a6ff",
|
|
29970
|
+
// Light green for literals
|
|
29971
|
+
blankNode: "#c5c5c5ff",
|
|
29972
|
+
// Light grey for blank nodes
|
|
29973
|
+
typeObject: "#e15b13ff",
|
|
29974
|
+
// Orange for rdf:type objects
|
|
29975
|
+
text: "#000000",
|
|
29976
|
+
// Black text
|
|
29977
|
+
edge: "#cccccc",
|
|
29978
|
+
// Light grey edges
|
|
29979
|
+
edgeLabel: "#666666",
|
|
29980
|
+
// Dark grey edge labels
|
|
29981
|
+
edgeLabelBackground: "rgba(255, 255, 255, 0.8)"
|
|
29982
|
+
// Light semi-transparent background
|
|
29983
|
+
};
|
|
29984
|
+
}
|
|
29985
|
+
function watchThemeChanges(callback) {
|
|
29986
|
+
const observer = new MutationObserver((mutations) => {
|
|
29987
|
+
mutations.forEach((mutation) => {
|
|
29988
|
+
if (mutation.attributeName === "data-theme") {
|
|
29989
|
+
const theme = getCurrentTheme();
|
|
29990
|
+
callback(theme);
|
|
29991
|
+
}
|
|
29992
|
+
});
|
|
29993
|
+
});
|
|
29994
|
+
observer.observe(document.documentElement, {
|
|
29995
|
+
attributes: true,
|
|
29996
|
+
attributeFilter: ["data-theme"]
|
|
29997
|
+
});
|
|
29998
|
+
return observer;
|
|
29999
|
+
}
|
|
30000
|
+
|
|
29950
30001
|
// src/GraphPlugin.js
|
|
29951
30002
|
function getVisNetwork() {
|
|
29952
30003
|
return { Network, DataSet };
|
|
@@ -29955,6 +30006,8 @@ var GraphPlugin = class {
|
|
|
29955
30006
|
constructor(yasr) {
|
|
29956
30007
|
this.yasr = yasr;
|
|
29957
30008
|
this.network = null;
|
|
30009
|
+
this.currentTheme = getCurrentTheme();
|
|
30010
|
+
this.themeObserver = null;
|
|
29958
30011
|
}
|
|
29959
30012
|
/**
|
|
29960
30013
|
* Plugin priority (higher = shown first in tabs)
|
|
@@ -29997,7 +30050,9 @@ var GraphPlugin = class {
|
|
|
29997
30050
|
return;
|
|
29998
30051
|
}
|
|
29999
30052
|
const prefixMap = extractPrefixes(this.yasr);
|
|
30000
|
-
|
|
30053
|
+
this.currentTheme = getCurrentTheme();
|
|
30054
|
+
const themeColors = getThemeNodeColors(this.currentTheme);
|
|
30055
|
+
const { nodes, edges } = triplesToGraph(triples, prefixMap, themeColors);
|
|
30001
30056
|
const container = document.createElement("div");
|
|
30002
30057
|
container.style.width = "100%";
|
|
30003
30058
|
container.style.height = "600px";
|
|
@@ -30007,7 +30062,11 @@ var GraphPlugin = class {
|
|
|
30007
30062
|
const { Network: Network2, DataSet: DataSet2 } = getVisNetwork();
|
|
30008
30063
|
const nodesDataSet = new DataSet2(nodes);
|
|
30009
30064
|
const edgesDataSet = new DataSet2(edges);
|
|
30010
|
-
const options = getDefaultNetworkOptions();
|
|
30065
|
+
const options = getDefaultNetworkOptions(themeColors);
|
|
30066
|
+
this.nodesDataSet = nodesDataSet;
|
|
30067
|
+
this.edgesDataSet = edgesDataSet;
|
|
30068
|
+
this.triples = triples;
|
|
30069
|
+
this.prefixMap = prefixMap;
|
|
30011
30070
|
this.network = new Network2(
|
|
30012
30071
|
container,
|
|
30013
30072
|
{ nodes: nodesDataSet, edges: edgesDataSet },
|
|
@@ -30018,6 +30077,11 @@ var GraphPlugin = class {
|
|
|
30018
30077
|
this.network.setOptions({ physics: { enabled: true } });
|
|
30019
30078
|
this.networkReady = true;
|
|
30020
30079
|
});
|
|
30080
|
+
if (!this.themeObserver) {
|
|
30081
|
+
this.themeObserver = watchThemeChanges((newTheme) => {
|
|
30082
|
+
this.applyTheme(newTheme);
|
|
30083
|
+
});
|
|
30084
|
+
}
|
|
30021
30085
|
const controls = document.createElement("div");
|
|
30022
30086
|
controls.style.position = "absolute";
|
|
30023
30087
|
controls.style.top = "10px";
|
|
@@ -30053,16 +30117,57 @@ var GraphPlugin = class {
|
|
|
30053
30117
|
this.yasr.resultsEl.innerHTML = '<div style="padding: 20px; color: red;">Error rendering graph. See console for details.</div>';
|
|
30054
30118
|
}
|
|
30055
30119
|
}
|
|
30120
|
+
/**
|
|
30121
|
+
* Apply theme to existing network
|
|
30122
|
+
* @param {string} newTheme - 'light' or 'dark'
|
|
30123
|
+
*/
|
|
30124
|
+
applyTheme(newTheme) {
|
|
30125
|
+
if (!this.network || !this.nodesDataSet || !this.triples || !this.prefixMap) {
|
|
30126
|
+
return;
|
|
30127
|
+
}
|
|
30128
|
+
this.currentTheme = newTheme;
|
|
30129
|
+
const themeColors = getThemeNodeColors(newTheme);
|
|
30130
|
+
const { nodes, edges } = triplesToGraph(this.triples, this.prefixMap, themeColors);
|
|
30131
|
+
this.nodesDataSet.clear();
|
|
30132
|
+
this.nodesDataSet.add(nodes);
|
|
30133
|
+
this.edgesDataSet.clear();
|
|
30134
|
+
this.edgesDataSet.add(edges);
|
|
30135
|
+
const options = getDefaultNetworkOptions(themeColors);
|
|
30136
|
+
this.network.setOptions(options);
|
|
30137
|
+
}
|
|
30056
30138
|
/**
|
|
30057
30139
|
* Get icon for plugin tab
|
|
30058
30140
|
* @returns {Element} Icon element
|
|
30059
30141
|
*/
|
|
30060
30142
|
getIcon() {
|
|
30061
|
-
const icon = document.createElement("
|
|
30062
|
-
icon.className = "fas fa-project-diagram";
|
|
30143
|
+
const icon = document.createElement("div");
|
|
30063
30144
|
icon.setAttribute("aria-label", "Graph visualization");
|
|
30145
|
+
icon.style.display = "inline-flex";
|
|
30146
|
+
icon.style.alignItems = "center";
|
|
30147
|
+
icon.style.justifyContent = "center";
|
|
30148
|
+
icon.innerHTML = `<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
|
|
30149
|
+
<circle cx="3" cy="3" r="2" />
|
|
30150
|
+
<circle cx="13" cy="3" r="2" />
|
|
30151
|
+
<circle cx="8" cy="13" r="2" />
|
|
30152
|
+
<line x1="4.5" y1="4" x2="7" y2="11.5" stroke="currentColor" stroke-width="1.5" />
|
|
30153
|
+
<line x1="11.5" y1="4" x2="9" y2="11.5" stroke="currentColor" stroke-width="1.5" />
|
|
30154
|
+
<line x1="5" y1="3" x2="11" y2="3" stroke="currentColor" stroke-width="1.5" />
|
|
30155
|
+
</svg>`;
|
|
30064
30156
|
return icon;
|
|
30065
30157
|
}
|
|
30158
|
+
/**
|
|
30159
|
+
* Cleanup when plugin is destroyed
|
|
30160
|
+
*/
|
|
30161
|
+
destroy() {
|
|
30162
|
+
if (this.themeObserver) {
|
|
30163
|
+
this.themeObserver.disconnect();
|
|
30164
|
+
this.themeObserver = null;
|
|
30165
|
+
}
|
|
30166
|
+
if (this.network) {
|
|
30167
|
+
this.network.destroy();
|
|
30168
|
+
this.network = null;
|
|
30169
|
+
}
|
|
30170
|
+
}
|
|
30066
30171
|
};
|
|
30067
30172
|
var GraphPlugin_default = GraphPlugin;
|
|
30068
30173
|
|