Skip to content

Commit 0a0f110

Browse files
[fix]知识图谱ISVJ-7577和showRelationType review by qiwei
1 parent 2f4674a commit 0a0f110

File tree

2 files changed

+250
-10
lines changed

2 files changed

+250
-10
lines changed

src/common/overlay/knowledge-graph/format.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import uniqBy from 'lodash.uniqby';
22

33
export function transformGraphMap(data, graphMap) {
4-
const style = graphMap && graphMap.styles && graphMap.styles.style;
5-
const captionField = graphMap && graphMap.captionFields && graphMap.captionFields.captionField;
4+
graphMap = graphMap || {};
5+
const style = graphMap.styles && graphMap.styles.style;
6+
const captionField = graphMap.captionFields && graphMap.captionFields.captionField;
7+
const showRelationTypes = graphMap.showRelationTypes;
68

79
const rst = { nodes: [], edges: [] };
810
data.forEach((item) => {
911
const pathData = item.path;
1012
if (pathData) {
11-
const { nodes, edges } = transformPath(pathData, style, captionField);
13+
const { nodes, edges } = transformPath(pathData, style, captionField, showRelationTypes);
1214
rst.nodes.push(...nodes);
1315
rst.edges.push(...edges);
1416
} else if (isEdge(item)) {
15-
const edge = edgeFromGraphMap(item, style);
17+
const edge = edgeFromGraphMap(item, style, showRelationTypes);
1618
rst.edges.push(edge);
1719
} else {
1820
const node = nodeFromGraphMap(item, style, captionField);
@@ -30,11 +32,11 @@ function isEdge(entity) {
3032
return entity.hasOwnProperty('start') && entity.hasOwnProperty('end');
3133
}
3234

33-
function transformPath(pathData, style, captionField) {
35+
function transformPath(pathData, style, captionField, showRelationTypes) {
3436
const rst = { nodes: [], edges: [] };
3537
pathData.forEach((item) => {
3638
if (isEdge(item)) {
37-
const edge = edgeFromGraphMap(item, style);
39+
const edge = edgeFromGraphMap(item, style, showRelationTypes);
3840
rst.edges.push(edge);
3941
} else {
4042
const node = nodeFromGraphMap(item, style, captionField);
@@ -51,7 +53,7 @@ export function nodeFromGraphMap(entity, style, captionField) {
5153
const fillColor = styleData.fillColor || '';
5254
const node = {
5355
id: id + '',
54-
label: label,
56+
label: label === undefined ? '' : label + '',
5557
properties,
5658
lables
5759
};
@@ -73,7 +75,7 @@ export function nodeFromGraphMap(entity, style, captionField) {
7375
}
7476
return node;
7577
}
76-
export function edgeFromGraphMap(entity, style) {
78+
export function edgeFromGraphMap(entity, style, showRelationTypes) {
7779
const { start, end, id, type, properties } = entity;
7880
const styleData = style ? getEdgeStyle(entity, style) : {};
7981
const edge = {
@@ -85,6 +87,9 @@ export function edgeFromGraphMap(entity, style) {
8587
labelCfg: {},
8688
properties
8789
};
90+
if (showRelationTypes === false) {
91+
delete edge.label;
92+
}
8893
if (styleData.stroke) {
8994
edge.style.stroke = styleData.stroke;
9095
edge.style.endArrow = {
@@ -161,11 +166,11 @@ function getNodeLabel(entity, captionField) {
161166
const types = JSON.parse(entityTypes || '[]');
162167
const labelStr = labels && labels.join('&');
163168
if (ids.includes(id) || types.includes(labelStr)) {
164-
return properties[name] || '';
169+
return properties[name];
165170
}
166171
}
167172
}
168-
return properties[properties._labelfieldname] || '';
173+
return properties[properties._labelfieldname];
169174
}
170175

171176
function formatFontStyle(fontStyle) {

test/common/overlay/KnowledgeGraphSpec.js

Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,240 @@ describe('KnowledgeGraph', () => {
9191
done();
9292
});
9393

94+
it('node label 0', (done) => {
95+
var graphData = [
96+
{
97+
path: [
98+
{
99+
id: 17732923532771331,
100+
properties: {
101+
server: 0
102+
},
103+
labels: ['面1']
104+
},
105+
{
106+
start: 17732923532771331,
107+
end: 18014398509481990,
108+
id: 20547673299877890,
109+
type: '邻接',
110+
properties: {}
111+
},
112+
{
113+
id: 18014398509481990,
114+
properties: {
115+
server: '0'
116+
},
117+
labels: ['面2']
118+
}
119+
]
120+
},
121+
{
122+
id: 177329231,
123+
properties: {
124+
server: 0
125+
},
126+
labels: ['面1']
127+
},
128+
{
129+
start: 177329231,
130+
end: 17732923,
131+
id: 20547673890,
132+
type: '邻接1',
133+
properties: {}
134+
}
135+
];
136+
var style = [
137+
{
138+
type: 'entity',
139+
color: '#ffc454',
140+
textColor: '#ffffff',
141+
font: {
142+
fontName: 'Microsoft Yahei UI',
143+
fontSize: 13,
144+
fontStyle: 0
145+
},
146+
size: 20,
147+
entityIds: '[12,16,18,21,23,25,28,29]'
148+
},
149+
{
150+
type: 'entity',
151+
color: '#c990c0',
152+
textColor: '#595959',
153+
font: {
154+
fontName: 'Microsoft Yahei UI',
155+
fontSize: 6,
156+
fontStyle: 0
157+
},
158+
size: 20,
159+
entityTypes: '["地籍子区"]'
160+
}
161+
];
162+
var captionField = { entityTypes: '["面1"]', name: 'server' };
163+
var data = KnowledgeGraph.dataFromGraphMap(graphData, {
164+
styles: { style },
165+
captionFields: { captionField: [captionField] }
166+
});
167+
expect(data.nodes[0].label).toBe('0');
168+
expect(data.edges).not.toBeNull();
169+
done();
170+
});
171+
172+
it('showRelationTypes false', (done) => {
173+
var graphData = [
174+
{
175+
path: [
176+
{
177+
id: 17732923532771331,
178+
properties: {
179+
server: undefined
180+
},
181+
labels: ['面1']
182+
},
183+
{
184+
start: 17732923532771331,
185+
end: 18014398509481990,
186+
id: 20547673299877890,
187+
type: '邻接',
188+
properties: {}
189+
},
190+
{
191+
id: 18014398509481990,
192+
properties: {
193+
server: undefined
194+
},
195+
labels: ['面2']
196+
}
197+
]
198+
},
199+
{
200+
id: 177329231,
201+
properties: {
202+
server: 0
203+
},
204+
labels: ['面1']
205+
},
206+
{
207+
start: 177329231,
208+
end: 17732923,
209+
id: 20547673890,
210+
type: '邻接1',
211+
properties: {}
212+
}
213+
];
214+
var style = [
215+
{
216+
type: 'entity',
217+
color: '#ffc454',
218+
textColor: '#ffffff',
219+
font: {
220+
fontName: 'Microsoft Yahei UI',
221+
fontSize: 13,
222+
fontStyle: 0
223+
},
224+
size: 20,
225+
entityIds: '[12,16,18,21,23,25,28,29]'
226+
},
227+
{
228+
type: 'entity',
229+
color: '#c990c0',
230+
textColor: '#595959',
231+
font: {
232+
fontName: 'Microsoft Yahei UI',
233+
fontSize: 6,
234+
fontStyle: 0
235+
},
236+
size: 20,
237+
entityTypes: '["地籍子区"]'
238+
}
239+
];
240+
var captionField = { entityTypes: '["面1"]', name: 'server' };
241+
var data = KnowledgeGraph.dataFromGraphMap(graphData, {
242+
styles: { style },
243+
captionFields: { captionField: [captionField] },
244+
showRelationTypes: false
245+
});
246+
expect(data.nodes[0].label).toBe('');
247+
expect(data.edges[0].label).toBeUndefined();
248+
done();
249+
});
250+
it('showRelationTypes true', (done) => {
251+
var graphData = [
252+
{
253+
path: [
254+
{
255+
id: 17732923532771331,
256+
properties: {
257+
server: 0
258+
},
259+
labels: ['面1']
260+
},
261+
{
262+
start: 17732923532771331,
263+
end: 18014398509481990,
264+
id: 20547673299877890,
265+
type: '邻接',
266+
properties: {}
267+
},
268+
{
269+
id: 18014398509481990,
270+
properties: {
271+
server: '0'
272+
},
273+
labels: ['面2']
274+
}
275+
]
276+
},
277+
{
278+
id: 177329231,
279+
properties: {
280+
server: 0
281+
},
282+
labels: ['面1']
283+
},
284+
{
285+
start: 177329231,
286+
end: 17732923,
287+
id: 20547673890,
288+
type: '邻接1',
289+
properties: {}
290+
}
291+
];
292+
var style = [
293+
{
294+
type: 'entity',
295+
color: '#ffc454',
296+
textColor: '#ffffff',
297+
font: {
298+
fontName: 'Microsoft Yahei UI',
299+
fontSize: 13,
300+
fontStyle: 0
301+
},
302+
size: 20,
303+
entityIds: '[12,16,18,21,23,25,28,29]'
304+
},
305+
{
306+
type: 'entity',
307+
color: '#c990c0',
308+
textColor: '#595959',
309+
font: {
310+
fontName: 'Microsoft Yahei UI',
311+
fontSize: 6,
312+
fontStyle: 0
313+
},
314+
size: 20,
315+
entityTypes: '["地籍子区"]'
316+
}
317+
];
318+
var captionField = { entityTypes: '["面1"]', name: 'server' };
319+
var data = KnowledgeGraph.dataFromGraphMap(graphData, {
320+
styles: { style },
321+
captionFields: { captionField: [captionField] },
322+
showRelationTypes: false
323+
});
324+
expect(data.edges[0].label).toBe('邻接');
325+
done();
326+
});
327+
94328
it('dataFromGraphMap', (done) => {
95329
var graphData = [
96330
{
@@ -162,6 +396,7 @@ describe('KnowledgeGraph', () => {
162396
var data = KnowledgeGraph.dataFromGraphMap(graphData, { styles: { style } });
163397
expect(data.nodes).not.toBeNull();
164398
expect(data.edges).not.toBeNull();
399+
expect(data.edges[0].label).toBe('邻接');
165400
done();
166401
});
167402

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy