@neo4j-ndl/react-graph 1.2.44 → 1.3.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/lib/cjs/graph-visualization-buttons.js +1 -3
- package/lib/cjs/graph-visualization-buttons.js.map +1 -1
- package/lib/cjs/graph-visualization-context.js.map +1 -1
- package/lib/cjs/graph-visualization.js +7 -5
- package/lib/cjs/graph-visualization.js.map +1 -1
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/sidepanel-components/details-panel.js +5 -11
- package/lib/cjs/sidepanel-components/details-panel.js.map +1 -1
- package/lib/cjs/sidepanel-components/graph-label-wrapper.js +40 -0
- package/lib/cjs/sidepanel-components/graph-label-wrapper.js.map +1 -0
- package/lib/cjs/sidepanel-components/overview-panel.js +3 -12
- package/lib/cjs/sidepanel-components/overview-panel.js.map +1 -1
- package/lib/cjs/stories/graph-visualization-rule-based-styling-advanced.story.js +247 -0
- package/lib/cjs/stories/graph-visualization-rule-based-styling-advanced.story.js.map +1 -0
- package/lib/cjs/stories/graph-visualization-rule-based-styling.story.js +79 -0
- package/lib/cjs/stories/graph-visualization-rule-based-styling.story.js.map +1 -0
- package/lib/cjs/stories/graph-visualization-simple-styling.story.js +57 -0
- package/lib/cjs/stories/graph-visualization-simple-styling.story.js.map +1 -0
- package/lib/cjs/stories/index.js +23 -10
- package/lib/cjs/stories/index.js.map +1 -1
- package/lib/cjs/stories/story-data.js +906 -3
- package/lib/cjs/stories/story-data.js.map +1 -1
- package/lib/cjs/styling/compile-graph-styles.js +22 -21
- package/lib/cjs/styling/compile-graph-styles.js.map +1 -1
- package/lib/cjs/styling/create-vis-data-structures.js +126 -0
- package/lib/cjs/styling/create-vis-data-structures.js.map +1 -0
- package/lib/cjs/styling/use-graph-data.js +35 -0
- package/lib/cjs/styling/use-graph-data.js.map +1 -0
- package/lib/cjs/utils.js +23 -9
- package/lib/cjs/utils.js.map +1 -1
- package/lib/esm/graph-visualization-buttons.js +1 -3
- package/lib/esm/graph-visualization-buttons.js.map +1 -1
- package/lib/esm/graph-visualization-context.js.map +1 -1
- package/lib/esm/graph-visualization.js +7 -5
- package/lib/esm/graph-visualization.js.map +1 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/sidepanel-components/details-panel.js +6 -12
- package/lib/esm/sidepanel-components/details-panel.js.map +1 -1
- package/lib/esm/sidepanel-components/graph-label-wrapper.js +33 -0
- package/lib/esm/sidepanel-components/graph-label-wrapper.js.map +1 -0
- package/lib/esm/sidepanel-components/overview-panel.js +4 -13
- package/lib/esm/sidepanel-components/overview-panel.js.map +1 -1
- package/lib/esm/stories/graph-visualization-rule-based-styling-advanced.story.js +244 -0
- package/lib/esm/stories/graph-visualization-rule-based-styling-advanced.story.js.map +1 -0
- package/lib/esm/stories/graph-visualization-rule-based-styling.story.js +76 -0
- package/lib/esm/stories/graph-visualization-rule-based-styling.story.js.map +1 -0
- package/lib/esm/stories/graph-visualization-simple-styling.story.js +54 -0
- package/lib/esm/stories/graph-visualization-simple-styling.story.js.map +1 -0
- package/lib/esm/stories/index.js +18 -8
- package/lib/esm/stories/index.js.map +1 -1
- package/lib/esm/stories/story-data.js +905 -2
- package/lib/esm/stories/story-data.js.map +1 -1
- package/lib/esm/styling/compile-graph-styles.js +22 -21
- package/lib/esm/styling/compile-graph-styles.js.map +1 -1
- package/lib/esm/styling/create-vis-data-structures.js +122 -0
- package/lib/esm/styling/create-vis-data-structures.js.map +1 -0
- package/lib/esm/styling/use-graph-data.js +32 -0
- package/lib/esm/styling/use-graph-data.js.map +1 -0
- package/lib/esm/utils.js +20 -8
- package/lib/esm/utils.js.map +1 -1
- package/lib/types/graph-visualization-buttons.d.ts.map +1 -1
- package/lib/types/graph-visualization-context.d.ts +15 -9
- package/lib/types/graph-visualization-context.d.ts.map +1 -1
- package/lib/types/graph-visualization.d.ts +8 -1
- package/lib/types/graph-visualization.d.ts.map +1 -1
- package/lib/types/index.d.ts +2 -1
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/sidepanel-components/details-panel.d.ts.map +1 -1
- package/lib/types/{map-to-nvl-graph.d.ts → sidepanel-components/graph-label-wrapper.d.ts} +10 -17
- package/lib/types/sidepanel-components/graph-label-wrapper.d.ts.map +1 -0
- package/lib/types/sidepanel-components/overview-panel.d.ts.map +1 -1
- package/lib/types/stories/graph-visualization-rule-based-styling-advanced.story.d.ts +33 -0
- package/lib/types/stories/graph-visualization-rule-based-styling-advanced.story.d.ts.map +1 -0
- package/lib/types/stories/graph-visualization-rule-based-styling.story.d.ts +25 -0
- package/lib/types/stories/graph-visualization-rule-based-styling.story.d.ts.map +1 -0
- package/lib/types/stories/graph-visualization-simple-styling.story.d.ts +25 -0
- package/lib/types/stories/graph-visualization-simple-styling.story.d.ts.map +1 -0
- package/lib/types/stories/index.d.ts +7 -1
- package/lib/types/stories/index.d.ts.map +1 -1
- package/lib/types/stories/story-data.d.ts +4 -0
- package/lib/types/stories/story-data.d.ts.map +1 -1
- package/lib/types/styling/compile-graph-styles.d.ts +2 -5
- package/lib/types/styling/compile-graph-styles.d.ts.map +1 -1
- package/lib/types/styling/create-vis-data-structures.d.ts +28 -0
- package/lib/types/styling/create-vis-data-structures.d.ts.map +1 -0
- package/lib/types/styling/style-types.d.ts +2 -2
- package/lib/types/styling/use-graph-data.d.ts +28 -0
- package/lib/types/styling/use-graph-data.d.ts.map +1 -0
- package/lib/types/utils.d.ts +5 -3
- package/lib/types/utils.d.ts.map +1 -1
- package/package.json +1 -1
- package/lib/cjs/map-to-nvl-graph.js +0 -167
- package/lib/cjs/map-to-nvl-graph.js.map +0 -1
- package/lib/esm/map-to-nvl-graph.js +0 -162
- package/lib/esm/map-to-nvl-graph.js.map +0 -1
- package/lib/types/map-to-nvl-graph.d.ts.map +0 -1
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) "Neo4j"
|
|
5
|
-
* Neo4j Sweden AB [http://neo4j.com]
|
|
6
|
-
*
|
|
7
|
-
* This file is part of Neo4j.
|
|
8
|
-
*
|
|
9
|
-
* Neo4j is free software: you can redistribute it and/or modify
|
|
10
|
-
* it under the terms of the GNU General Public License as published by
|
|
11
|
-
* the Free Software Foundation, either version 3 of the License, or
|
|
12
|
-
* (at your option) any later version.
|
|
13
|
-
*
|
|
14
|
-
* This program is distributed in the hope that it will be useful,
|
|
15
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17
|
-
* GNU General Public License for more details.
|
|
18
|
-
*
|
|
19
|
-
* You should have received a copy of the GNU General Public License
|
|
20
|
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
21
|
-
*/
|
|
22
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.captionPriorityOrder = exports.NO_LABEL_FALLBACK_COLOR = exports.DEFAULT_REL_COLOR = void 0;
|
|
24
|
-
exports.getDefaultCaptionKey = getDefaultCaptionKey;
|
|
25
|
-
exports.mapToNvlGraph = mapToNvlGraph;
|
|
26
|
-
const word_color_1 = require("@neo4j-devtools/word-color");
|
|
27
|
-
const base_1 = require("@neo4j-ndl/base");
|
|
28
|
-
exports.DEFAULT_REL_COLOR = base_1.tokens.palette.neutral['40'];
|
|
29
|
-
exports.NO_LABEL_FALLBACK_COLOR = base_1.tokens.palette.neutral['40'];
|
|
30
|
-
const sortAlphabetically = (a = '', b = '') => a.toLowerCase().localeCompare(b.toLowerCase());
|
|
31
|
-
function getMostCommonColor(colors) {
|
|
32
|
-
var _a;
|
|
33
|
-
const [firstColor] = colors;
|
|
34
|
-
if (firstColor === undefined) {
|
|
35
|
-
return exports.NO_LABEL_FALLBACK_COLOR;
|
|
36
|
-
}
|
|
37
|
-
const colorCounts = {};
|
|
38
|
-
for (const color of colors) {
|
|
39
|
-
colorCounts[color] = ((_a = colorCounts[color]) !== null && _a !== void 0 ? _a : 0) + 1;
|
|
40
|
-
}
|
|
41
|
-
let maxCount = 0;
|
|
42
|
-
let mostCommonColor = firstColor;
|
|
43
|
-
for (const [color, colorCount] of Object.entries(colorCounts)) {
|
|
44
|
-
if (colorCount > maxCount) {
|
|
45
|
-
maxCount = colorCount;
|
|
46
|
-
mostCommonColor = color;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return mostCommonColor;
|
|
50
|
-
}
|
|
51
|
-
function transformToItemMetada(arg) {
|
|
52
|
-
return Object.entries(arg).reduce((acc, [label, colors]) => {
|
|
53
|
-
acc[label] = {
|
|
54
|
-
mostCommonColor: getMostCommonColor(colors),
|
|
55
|
-
totalCount: colors.length,
|
|
56
|
-
};
|
|
57
|
-
return acc;
|
|
58
|
-
}, {});
|
|
59
|
-
}
|
|
60
|
-
exports.captionPriorityOrder = [
|
|
61
|
-
/^name$/i,
|
|
62
|
-
/^title$/i,
|
|
63
|
-
/^label$/i,
|
|
64
|
-
/name$/i,
|
|
65
|
-
/description$/i,
|
|
66
|
-
/^.+/,
|
|
67
|
-
];
|
|
68
|
-
function getDefaultCaptionKey(options) {
|
|
69
|
-
const captionKeys = options
|
|
70
|
-
.filter((option) => option.type === 'property')
|
|
71
|
-
.map((option) => option.captionKey);
|
|
72
|
-
for (const regex of exports.captionPriorityOrder) {
|
|
73
|
-
const matchingKey = captionKeys.find((key) => regex.test(key));
|
|
74
|
-
if (matchingKey !== undefined) {
|
|
75
|
-
return {
|
|
76
|
-
captionKey: matchingKey,
|
|
77
|
-
type: 'property',
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
const typeOption = options.find((option) => option.type === 'type');
|
|
82
|
-
if (typeOption) {
|
|
83
|
-
return typeOption;
|
|
84
|
-
}
|
|
85
|
-
return options.find((option) => option.type === 'id');
|
|
86
|
-
}
|
|
87
|
-
const getDefaultNodeCaption = (item) => {
|
|
88
|
-
const options = Object.keys(item.properties).map((property) => ({
|
|
89
|
-
captionKey: property,
|
|
90
|
-
type: 'property',
|
|
91
|
-
}));
|
|
92
|
-
options.push({ type: 'id' }, { type: 'type' });
|
|
93
|
-
const defaultCaptionKey = getDefaultCaptionKey(options);
|
|
94
|
-
if ((defaultCaptionKey === null || defaultCaptionKey === void 0 ? void 0 : defaultCaptionKey.type) === 'property') {
|
|
95
|
-
const caption = item.properties[defaultCaptionKey.captionKey];
|
|
96
|
-
if (caption !== undefined) {
|
|
97
|
-
// remove quotes from string
|
|
98
|
-
if (caption.type === 'string') {
|
|
99
|
-
return [{ value: caption.stringified.slice(1, -1) }];
|
|
100
|
-
}
|
|
101
|
-
return [{ value: caption.stringified }];
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
const [firstLabel] = item.labels;
|
|
105
|
-
if ((defaultCaptionKey === null || defaultCaptionKey === void 0 ? void 0 : defaultCaptionKey.type) === 'type' && firstLabel !== undefined) {
|
|
106
|
-
return [{ value: firstLabel }];
|
|
107
|
-
}
|
|
108
|
-
return [{ value: item.id }];
|
|
109
|
-
};
|
|
110
|
-
// Properties can be huge, so we split them out into a separate lookup table
|
|
111
|
-
// to prevent them from making the physics slow
|
|
112
|
-
// here we also apply default colors & captions to nodes and relationships
|
|
113
|
-
// and sample colors for the sidepanel
|
|
114
|
-
// in the future we'll apply styling here as well
|
|
115
|
-
function mapToNvlGraph(rawNodes, rawRels) {
|
|
116
|
-
const labelColorPairs = {};
|
|
117
|
-
const typeColorPairs = {};
|
|
118
|
-
const nodeData = {};
|
|
119
|
-
const relData = {};
|
|
120
|
-
const nodes = rawNodes.map((node) => {
|
|
121
|
-
var _a;
|
|
122
|
-
const [firstLabel] = node.labels;
|
|
123
|
-
const newNode = Object.assign(Object.assign({ captions: getDefaultNodeCaption(node), color: (_a = node.color) !== null && _a !== void 0 ? _a : (firstLabel === undefined
|
|
124
|
-
? exports.NO_LABEL_FALLBACK_COLOR
|
|
125
|
-
: (0, word_color_1.calculateDefaultNodeColors)(firstLabel).backgroundColor) }, node), { labels: undefined, properties: undefined });
|
|
126
|
-
nodeData[node.id] = {
|
|
127
|
-
color: newNode.color,
|
|
128
|
-
id: node.id,
|
|
129
|
-
labelsSorted: [...node.labels].sort(sortAlphabetically),
|
|
130
|
-
properties: node.properties,
|
|
131
|
-
};
|
|
132
|
-
node.labels.forEach((label) => {
|
|
133
|
-
var _a;
|
|
134
|
-
labelColorPairs[label] = [
|
|
135
|
-
...((_a = labelColorPairs[label]) !== null && _a !== void 0 ? _a : []),
|
|
136
|
-
newNode.color,
|
|
137
|
-
];
|
|
138
|
-
});
|
|
139
|
-
return newNode;
|
|
140
|
-
});
|
|
141
|
-
const rels = rawRels.map((rel) => {
|
|
142
|
-
var _a, _b, _c;
|
|
143
|
-
relData[rel.id] = {
|
|
144
|
-
color: (_a = rel.color) !== null && _a !== void 0 ? _a : exports.DEFAULT_REL_COLOR,
|
|
145
|
-
id: rel.id,
|
|
146
|
-
properties: rel.properties,
|
|
147
|
-
type: rel.type,
|
|
148
|
-
};
|
|
149
|
-
typeColorPairs[rel.type] = [
|
|
150
|
-
...((_b = typeColorPairs[rel.type]) !== null && _b !== void 0 ? _b : []),
|
|
151
|
-
(_c = rel.color) !== null && _c !== void 0 ? _c : exports.DEFAULT_REL_COLOR,
|
|
152
|
-
];
|
|
153
|
-
return Object.assign(Object.assign({ captions: [{ value: rel.type }], color: exports.DEFAULT_REL_COLOR }, rel), { properties: undefined, type: undefined });
|
|
154
|
-
});
|
|
155
|
-
const labelMetaData = transformToItemMetada(labelColorPairs);
|
|
156
|
-
const typeMetaData = transformToItemMetada(typeColorPairs);
|
|
157
|
-
const dataLookupTable = {
|
|
158
|
-
labelMetaData,
|
|
159
|
-
labels: Object.keys(labelMetaData).sort((a, b) => sortAlphabetically(a, b)),
|
|
160
|
-
nodes: nodeData,
|
|
161
|
-
relationships: relData,
|
|
162
|
-
typeMetaData,
|
|
163
|
-
types: Object.keys(typeMetaData).sort((a, b) => sortAlphabetically(a, b)),
|
|
164
|
-
};
|
|
165
|
-
return { dataLookupTable, nodes, rels };
|
|
166
|
-
}
|
|
167
|
-
//# sourceMappingURL=map-to-nvl-graph.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"map-to-nvl-graph.js","sourceRoot":"","sources":["../../src/map-to-nvl-graph.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;;;AA8EH,oDAuBC;AAuCD,sCA2EC;AArND,2DAAwE;AACxE,0CAAyC;AAsB5B,QAAA,iBAAiB,GAAG,aAAM,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AACjD,QAAA,uBAAuB,GAAG,aAAM,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAEpE,MAAM,kBAAkB,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,EAAE,EAAE,EAAE,CAC5C,CAAC,CAAC,WAAW,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;AAEjD,SAAS,kBAAkB,CAAC,MAAgB;;IAC1C,MAAM,CAAC,UAAU,CAAC,GAAG,MAAM,CAAC;IAE5B,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;QAC7B,OAAO,+BAAuB,CAAC;IACjC,CAAC;IAED,MAAM,WAAW,GAA2B,EAAE,CAAC;IAC/C,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,MAAA,WAAW,CAAC,KAAK,CAAC,mCAAI,CAAC,CAAC,GAAG,CAAC,CAAC;IACrD,CAAC;IAED,IAAI,QAAQ,GAAG,CAAC,CAAC;IACjB,IAAI,eAAe,GAAG,UAAU,CAAC;IAEjC,KAAK,MAAM,CAAC,KAAK,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;QAC9D,IAAI,UAAU,GAAG,QAAQ,EAAE,CAAC;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CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAC3E,KAAK,EAAE,QAAQ;QACf,aAAa,EAAE,OAAO;QACtB,YAAY;QACZ,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;KAC1E,CAAC;IAEF,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC1C,CAAC","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nimport { calculateDefaultNodeColors } from '@neo4j-devtools/word-color';\nimport { tokens } from '@neo4j-ndl/base';\nimport { type StyledCaption } from '@neo4j-nvl/base';\n\nimport {\n type DataLookupTable,\n type GraphItemMetaData,\n type NeoNode,\n type NeoRel,\n type NodeData,\n type NvlGraph,\n type RelData,\n} from './graph-visualization-context';\n\nexport type CaptionOption =\n | { type: 'id'; captionSize?: number }\n | { type: 'type'; captionSize?: number }\n | {\n type: 'property';\n captionKey: string;\n captionSize?: number;\n };\n\nexport const DEFAULT_REL_COLOR = tokens.palette.neutral['40'];\nexport const NO_LABEL_FALLBACK_COLOR = tokens.palette.neutral['40'];\n\nconst sortAlphabetically = (a = '', b = '') =>\n a.toLowerCase().localeCompare(b.toLowerCase());\n\nfunction getMostCommonColor(colors: string[]): string {\n const [firstColor] = colors;\n\n if (firstColor === undefined) {\n return NO_LABEL_FALLBACK_COLOR;\n }\n\n const colorCounts: Record<string, number> = {};\n for (const color of colors) {\n colorCounts[color] = (colorCounts[color] ?? 0) + 1;\n }\n\n let maxCount = 0;\n let mostCommonColor = firstColor;\n\n for (const [color, colorCount] of Object.entries(colorCounts)) {\n if (colorCount > maxCount) {\n maxCount = colorCount;\n mostCommonColor = color;\n }\n }\n\n return mostCommonColor;\n}\n\nfunction transformToItemMetada(arg: Record<string, string[]>) {\n return Object.entries(arg).reduce<Record<string, GraphItemMetaData>>(\n (acc, [label, colors]) => {\n acc[label] = {\n mostCommonColor: getMostCommonColor(colors),\n totalCount: colors.length,\n };\n return acc;\n },\n {},\n );\n}\n\nexport const captionPriorityOrder = [\n /^name$/i,\n /^title$/i,\n /^label$/i,\n /name$/i,\n /description$/i,\n /^.+/,\n];\n\nexport function getDefaultCaptionKey(\n options: CaptionOption[],\n): CaptionOption | undefined {\n const captionKeys = options\n .filter((option) => option.type === 'property')\n .map((option) => option.captionKey);\n\n for (const regex of captionPriorityOrder) {\n const matchingKey = captionKeys.find((key) => regex.test(key));\n if (matchingKey !== undefined) {\n return {\n captionKey: matchingKey,\n type: 'property',\n };\n }\n }\n\n const typeOption = options.find((option) => option.type === 'type');\n if (typeOption) {\n return typeOption;\n }\n\n return options.find((option) => option.type === 'id');\n}\n\nconst getDefaultNodeCaption = (item: NeoNode): StyledCaption[] => {\n const options: CaptionOption[] = Object.keys(item.properties).map(\n (property) => ({\n captionKey: property,\n type: 'property',\n }),\n );\n\n options.push({ type: 'id' as const }, { type: 'type' as const });\n\n const defaultCaptionKey = getDefaultCaptionKey(options);\n\n if (defaultCaptionKey?.type === 'property') {\n const caption = item.properties[defaultCaptionKey.captionKey];\n\n if (caption !== undefined) {\n // remove quotes from string\n if (caption.type === 'string') {\n return [{ value: caption.stringified.slice(1, -1) }];\n }\n return [{ value: caption.stringified }];\n }\n }\n\n const [firstLabel] = item.labels;\n if (defaultCaptionKey?.type === 'type' && firstLabel !== undefined) {\n return [{ value: firstLabel }];\n }\n\n return [{ value: item.id }];\n};\n\n// Properties can be huge, so we split them out into a separate lookup table\n// to prevent them from making the physics slow\n// here we also apply default colors & captions to nodes and relationships\n// and sample colors for the sidepanel\n// in the future we'll apply styling here as well\nexport function mapToNvlGraph(\n rawNodes: NeoNode[],\n rawRels: NeoRel[],\n): NvlGraph {\n const labelColorPairs: Record<string, string[]> = {};\n const typeColorPairs: Record<string, string[]> = {};\n const nodeData: Record<string, NodeData> = {};\n const relData: Record<string, RelData> = {};\n\n const nodes = rawNodes.map((node) => {\n const [firstLabel] = node.labels;\n const newNode = {\n captions: getDefaultNodeCaption(node),\n color:\n node.color ??\n (firstLabel === undefined\n ? NO_LABEL_FALLBACK_COLOR\n : calculateDefaultNodeColors(firstLabel).backgroundColor),\n ...node,\n labels: undefined,\n properties: undefined,\n };\n\n nodeData[node.id] = {\n color: newNode.color,\n id: node.id,\n labelsSorted: [...node.labels].sort(sortAlphabetically),\n properties: node.properties,\n };\n\n node.labels.forEach((label) => {\n labelColorPairs[label] = [\n ...(labelColorPairs[label] ?? []),\n newNode.color,\n ];\n });\n\n return newNode;\n });\n\n const rels = rawRels.map((rel) => {\n relData[rel.id] = {\n color: rel.color ?? DEFAULT_REL_COLOR,\n id: rel.id,\n properties: rel.properties,\n type: rel.type,\n };\n\n typeColorPairs[rel.type] = [\n ...(typeColorPairs[rel.type] ?? []),\n rel.color ?? DEFAULT_REL_COLOR,\n ];\n\n return {\n captions: [{ value: rel.type }],\n color: DEFAULT_REL_COLOR,\n ...rel,\n properties: undefined,\n type: undefined,\n };\n });\n\n const labelMetaData = transformToItemMetada(labelColorPairs);\n const typeMetaData = transformToItemMetada(typeColorPairs);\n\n const dataLookupTable: DataLookupTable = {\n labelMetaData,\n labels: Object.keys(labelMetaData).sort((a, b) => sortAlphabetically(a, b)),\n nodes: nodeData,\n relationships: relData,\n typeMetaData,\n types: Object.keys(typeMetaData).sort((a, b) => sortAlphabetically(a, b)),\n };\n\n return { dataLookupTable, nodes, rels };\n}\n"]}
|
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* Copyright (c) "Neo4j"
|
|
4
|
-
* Neo4j Sweden AB [http://neo4j.com]
|
|
5
|
-
*
|
|
6
|
-
* This file is part of Neo4j.
|
|
7
|
-
*
|
|
8
|
-
* Neo4j is free software: you can redistribute it and/or modify
|
|
9
|
-
* it under the terms of the GNU General Public License as published by
|
|
10
|
-
* the Free Software Foundation, either version 3 of the License, or
|
|
11
|
-
* (at your option) any later version.
|
|
12
|
-
*
|
|
13
|
-
* This program is distributed in the hope that it will be useful,
|
|
14
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
-
* GNU General Public License for more details.
|
|
17
|
-
*
|
|
18
|
-
* You should have received a copy of the GNU General Public License
|
|
19
|
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
20
|
-
*/
|
|
21
|
-
import { calculateDefaultNodeColors } from '@neo4j-devtools/word-color';
|
|
22
|
-
import { tokens } from '@neo4j-ndl/base';
|
|
23
|
-
export const DEFAULT_REL_COLOR = tokens.palette.neutral['40'];
|
|
24
|
-
export const NO_LABEL_FALLBACK_COLOR = tokens.palette.neutral['40'];
|
|
25
|
-
const sortAlphabetically = (a = '', b = '') => a.toLowerCase().localeCompare(b.toLowerCase());
|
|
26
|
-
function getMostCommonColor(colors) {
|
|
27
|
-
var _a;
|
|
28
|
-
const [firstColor] = colors;
|
|
29
|
-
if (firstColor === undefined) {
|
|
30
|
-
return NO_LABEL_FALLBACK_COLOR;
|
|
31
|
-
}
|
|
32
|
-
const colorCounts = {};
|
|
33
|
-
for (const color of colors) {
|
|
34
|
-
colorCounts[color] = ((_a = colorCounts[color]) !== null && _a !== void 0 ? _a : 0) + 1;
|
|
35
|
-
}
|
|
36
|
-
let maxCount = 0;
|
|
37
|
-
let mostCommonColor = firstColor;
|
|
38
|
-
for (const [color, colorCount] of Object.entries(colorCounts)) {
|
|
39
|
-
if (colorCount > maxCount) {
|
|
40
|
-
maxCount = colorCount;
|
|
41
|
-
mostCommonColor = color;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return mostCommonColor;
|
|
45
|
-
}
|
|
46
|
-
function transformToItemMetada(arg) {
|
|
47
|
-
return Object.entries(arg).reduce((acc, [label, colors]) => {
|
|
48
|
-
acc[label] = {
|
|
49
|
-
mostCommonColor: getMostCommonColor(colors),
|
|
50
|
-
totalCount: colors.length,
|
|
51
|
-
};
|
|
52
|
-
return acc;
|
|
53
|
-
}, {});
|
|
54
|
-
}
|
|
55
|
-
export const captionPriorityOrder = [
|
|
56
|
-
/^name$/i,
|
|
57
|
-
/^title$/i,
|
|
58
|
-
/^label$/i,
|
|
59
|
-
/name$/i,
|
|
60
|
-
/description$/i,
|
|
61
|
-
/^.+/,
|
|
62
|
-
];
|
|
63
|
-
export function getDefaultCaptionKey(options) {
|
|
64
|
-
const captionKeys = options
|
|
65
|
-
.filter((option) => option.type === 'property')
|
|
66
|
-
.map((option) => option.captionKey);
|
|
67
|
-
for (const regex of captionPriorityOrder) {
|
|
68
|
-
const matchingKey = captionKeys.find((key) => regex.test(key));
|
|
69
|
-
if (matchingKey !== undefined) {
|
|
70
|
-
return {
|
|
71
|
-
captionKey: matchingKey,
|
|
72
|
-
type: 'property',
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
const typeOption = options.find((option) => option.type === 'type');
|
|
77
|
-
if (typeOption) {
|
|
78
|
-
return typeOption;
|
|
79
|
-
}
|
|
80
|
-
return options.find((option) => option.type === 'id');
|
|
81
|
-
}
|
|
82
|
-
const getDefaultNodeCaption = (item) => {
|
|
83
|
-
const options = Object.keys(item.properties).map((property) => ({
|
|
84
|
-
captionKey: property,
|
|
85
|
-
type: 'property',
|
|
86
|
-
}));
|
|
87
|
-
options.push({ type: 'id' }, { type: 'type' });
|
|
88
|
-
const defaultCaptionKey = getDefaultCaptionKey(options);
|
|
89
|
-
if ((defaultCaptionKey === null || defaultCaptionKey === void 0 ? void 0 : defaultCaptionKey.type) === 'property') {
|
|
90
|
-
const caption = item.properties[defaultCaptionKey.captionKey];
|
|
91
|
-
if (caption !== undefined) {
|
|
92
|
-
// remove quotes from string
|
|
93
|
-
if (caption.type === 'string') {
|
|
94
|
-
return [{ value: caption.stringified.slice(1, -1) }];
|
|
95
|
-
}
|
|
96
|
-
return [{ value: caption.stringified }];
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
const [firstLabel] = item.labels;
|
|
100
|
-
if ((defaultCaptionKey === null || defaultCaptionKey === void 0 ? void 0 : defaultCaptionKey.type) === 'type' && firstLabel !== undefined) {
|
|
101
|
-
return [{ value: firstLabel }];
|
|
102
|
-
}
|
|
103
|
-
return [{ value: item.id }];
|
|
104
|
-
};
|
|
105
|
-
// Properties can be huge, so we split them out into a separate lookup table
|
|
106
|
-
// to prevent them from making the physics slow
|
|
107
|
-
// here we also apply default colors & captions to nodes and relationships
|
|
108
|
-
// and sample colors for the sidepanel
|
|
109
|
-
// in the future we'll apply styling here as well
|
|
110
|
-
export function mapToNvlGraph(rawNodes, rawRels) {
|
|
111
|
-
const labelColorPairs = {};
|
|
112
|
-
const typeColorPairs = {};
|
|
113
|
-
const nodeData = {};
|
|
114
|
-
const relData = {};
|
|
115
|
-
const nodes = rawNodes.map((node) => {
|
|
116
|
-
var _a;
|
|
117
|
-
const [firstLabel] = node.labels;
|
|
118
|
-
const newNode = Object.assign(Object.assign({ captions: getDefaultNodeCaption(node), color: (_a = node.color) !== null && _a !== void 0 ? _a : (firstLabel === undefined
|
|
119
|
-
? NO_LABEL_FALLBACK_COLOR
|
|
120
|
-
: calculateDefaultNodeColors(firstLabel).backgroundColor) }, node), { labels: undefined, properties: undefined });
|
|
121
|
-
nodeData[node.id] = {
|
|
122
|
-
color: newNode.color,
|
|
123
|
-
id: node.id,
|
|
124
|
-
labelsSorted: [...node.labels].sort(sortAlphabetically),
|
|
125
|
-
properties: node.properties,
|
|
126
|
-
};
|
|
127
|
-
node.labels.forEach((label) => {
|
|
128
|
-
var _a;
|
|
129
|
-
labelColorPairs[label] = [
|
|
130
|
-
...((_a = labelColorPairs[label]) !== null && _a !== void 0 ? _a : []),
|
|
131
|
-
newNode.color,
|
|
132
|
-
];
|
|
133
|
-
});
|
|
134
|
-
return newNode;
|
|
135
|
-
});
|
|
136
|
-
const rels = rawRels.map((rel) => {
|
|
137
|
-
var _a, _b, _c;
|
|
138
|
-
relData[rel.id] = {
|
|
139
|
-
color: (_a = rel.color) !== null && _a !== void 0 ? _a : DEFAULT_REL_COLOR,
|
|
140
|
-
id: rel.id,
|
|
141
|
-
properties: rel.properties,
|
|
142
|
-
type: rel.type,
|
|
143
|
-
};
|
|
144
|
-
typeColorPairs[rel.type] = [
|
|
145
|
-
...((_b = typeColorPairs[rel.type]) !== null && _b !== void 0 ? _b : []),
|
|
146
|
-
(_c = rel.color) !== null && _c !== void 0 ? _c : DEFAULT_REL_COLOR,
|
|
147
|
-
];
|
|
148
|
-
return Object.assign(Object.assign({ captions: [{ value: rel.type }], color: DEFAULT_REL_COLOR }, rel), { properties: undefined, type: undefined });
|
|
149
|
-
});
|
|
150
|
-
const labelMetaData = transformToItemMetada(labelColorPairs);
|
|
151
|
-
const typeMetaData = transformToItemMetada(typeColorPairs);
|
|
152
|
-
const dataLookupTable = {
|
|
153
|
-
labelMetaData,
|
|
154
|
-
labels: Object.keys(labelMetaData).sort((a, b) => sortAlphabetically(a, b)),
|
|
155
|
-
nodes: nodeData,
|
|
156
|
-
relationships: relData,
|
|
157
|
-
typeMetaData,
|
|
158
|
-
types: Object.keys(typeMetaData).sort((a, b) => sortAlphabetically(a, b)),
|
|
159
|
-
};
|
|
160
|
-
return { dataLookupTable, nodes, rels };
|
|
161
|
-
}
|
|
162
|
-
//# sourceMappingURL=map-to-nvl-graph.js.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AC,CAAC,EAAE,CAAC,CAAC,CAAC;QAC3E,KAAK,EAAE,QAAQ;QACf,aAAa,EAAE,OAAO;QACtB,YAAY;QACZ,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;KAC1E,CAAC;IAEF,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC1C,CAAC","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nimport { calculateDefaultNodeColors } from '@neo4j-devtools/word-color';\nimport { tokens } from '@neo4j-ndl/base';\nimport { type StyledCaption } from '@neo4j-nvl/base';\n\nimport {\n type DataLookupTable,\n type GraphItemMetaData,\n type NeoNode,\n type NeoRel,\n type NodeData,\n type NvlGraph,\n type RelData,\n} from './graph-visualization-context';\n\nexport type CaptionOption =\n | { type: 'id'; captionSize?: number }\n | { type: 'type'; captionSize?: number }\n | {\n type: 'property';\n captionKey: string;\n captionSize?: number;\n };\n\nexport const DEFAULT_REL_COLOR = tokens.palette.neutral['40'];\nexport const NO_LABEL_FALLBACK_COLOR = tokens.palette.neutral['40'];\n\nconst sortAlphabetically = (a = '', b = '') =>\n a.toLowerCase().localeCompare(b.toLowerCase());\n\nfunction getMostCommonColor(colors: string[]): string {\n const [firstColor] = colors;\n\n if (firstColor === undefined) {\n return NO_LABEL_FALLBACK_COLOR;\n }\n\n const colorCounts: Record<string, number> = {};\n for (const color of colors) {\n colorCounts[color] = (colorCounts[color] ?? 0) + 1;\n }\n\n let maxCount = 0;\n let mostCommonColor = firstColor;\n\n for (const [color, colorCount] of Object.entries(colorCounts)) {\n if (colorCount > maxCount) {\n maxCount = colorCount;\n mostCommonColor = color;\n }\n }\n\n return mostCommonColor;\n}\n\nfunction transformToItemMetada(arg: Record<string, string[]>) {\n return Object.entries(arg).reduce<Record<string, GraphItemMetaData>>(\n (acc, [label, colors]) => {\n acc[label] = {\n mostCommonColor: getMostCommonColor(colors),\n totalCount: colors.length,\n };\n return acc;\n },\n {},\n );\n}\n\nexport const captionPriorityOrder = [\n /^name$/i,\n /^title$/i,\n /^label$/i,\n /name$/i,\n /description$/i,\n /^.+/,\n];\n\nexport function getDefaultCaptionKey(\n options: CaptionOption[],\n): CaptionOption | undefined {\n const captionKeys = options\n .filter((option) => option.type === 'property')\n .map((option) => option.captionKey);\n\n for (const regex of captionPriorityOrder) {\n const matchingKey = captionKeys.find((key) => regex.test(key));\n if (matchingKey !== undefined) {\n return {\n captionKey: matchingKey,\n type: 'property',\n };\n }\n }\n\n const typeOption = options.find((option) => option.type === 'type');\n if (typeOption) {\n return typeOption;\n }\n\n return options.find((option) => option.type === 'id');\n}\n\nconst getDefaultNodeCaption = (item: NeoNode): StyledCaption[] => {\n const options: CaptionOption[] = Object.keys(item.properties).map(\n (property) => ({\n captionKey: property,\n type: 'property',\n }),\n );\n\n options.push({ type: 'id' as const }, { type: 'type' as const });\n\n const defaultCaptionKey = getDefaultCaptionKey(options);\n\n if (defaultCaptionKey?.type === 'property') {\n const caption = item.properties[defaultCaptionKey.captionKey];\n\n if (caption !== undefined) {\n // remove quotes from string\n if (caption.type === 'string') {\n return [{ value: caption.stringified.slice(1, -1) }];\n }\n return [{ value: caption.stringified }];\n }\n }\n\n const [firstLabel] = item.labels;\n if (defaultCaptionKey?.type === 'type' && firstLabel !== undefined) {\n return [{ value: firstLabel }];\n }\n\n return [{ value: item.id }];\n};\n\n// Properties can be huge, so we split them out into a separate lookup table\n// to prevent them from making the physics slow\n// here we also apply default colors & captions to nodes and relationships\n// and sample colors for the sidepanel\n// in the future we'll apply styling here as well\nexport function mapToNvlGraph(\n rawNodes: NeoNode[],\n rawRels: NeoRel[],\n): NvlGraph {\n const labelColorPairs: Record<string, string[]> = {};\n const typeColorPairs: Record<string, string[]> = {};\n const nodeData: Record<string, NodeData> = {};\n const relData: Record<string, RelData> = {};\n\n const nodes = rawNodes.map((node) => {\n const [firstLabel] = node.labels;\n const newNode = {\n captions: getDefaultNodeCaption(node),\n color:\n node.color ??\n (firstLabel === undefined\n ? NO_LABEL_FALLBACK_COLOR\n : calculateDefaultNodeColors(firstLabel).backgroundColor),\n ...node,\n labels: undefined,\n properties: undefined,\n };\n\n nodeData[node.id] = {\n color: newNode.color,\n id: node.id,\n labelsSorted: [...node.labels].sort(sortAlphabetically),\n properties: node.properties,\n };\n\n node.labels.forEach((label) => {\n labelColorPairs[label] = [\n ...(labelColorPairs[label] ?? []),\n newNode.color,\n ];\n });\n\n return newNode;\n });\n\n const rels = rawRels.map((rel) => {\n relData[rel.id] = {\n color: rel.color ?? DEFAULT_REL_COLOR,\n id: rel.id,\n properties: rel.properties,\n type: rel.type,\n };\n\n typeColorPairs[rel.type] = [\n ...(typeColorPairs[rel.type] ?? []),\n rel.color ?? DEFAULT_REL_COLOR,\n ];\n\n return {\n captions: [{ value: rel.type }],\n color: DEFAULT_REL_COLOR,\n ...rel,\n properties: undefined,\n type: undefined,\n };\n });\n\n const labelMetaData = transformToItemMetada(labelColorPairs);\n const typeMetaData = transformToItemMetada(typeColorPairs);\n\n const dataLookupTable: DataLookupTable = {\n labelMetaData,\n labels: Object.keys(labelMetaData).sort((a, b) => sortAlphabetically(a, b)),\n nodes: nodeData,\n relationships: relData,\n typeMetaData,\n types: Object.keys(typeMetaData).sort((a, b) => sortAlphabetically(a, b)),\n };\n\n return { dataLookupTable, nodes, rels };\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"map-to-nvl-graph.d.ts","sourceRoot":"","sources":["../../src/map-to-nvl-graph.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAMH,OAAO,EAGL,KAAK,OAAO,EACZ,KAAK,MAAM,EAEX,KAAK,QAAQ,EAEd,MAAM,+BAA+B,CAAC;AAEvC,MAAM,MAAM,aAAa,GACrB;IAAE,IAAI,EAAE,IAAI,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,GACpC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,GACtC;IACE,IAAI,EAAE,UAAU,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEN,eAAO,MAAM,iBAAiB,QAA+B,CAAC;AAC9D,eAAO,MAAM,uBAAuB,QAA+B,CAAC;AA2CpE,eAAO,MAAM,oBAAoB,UAOhC,CAAC;AAEF,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,aAAa,EAAE,GACvB,aAAa,GAAG,SAAS,CAqB3B;AAuCD,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,OAAO,EAAE,EACnB,OAAO,EAAE,MAAM,EAAE,GAChB,QAAQ,CAwEV"}
|