Skip to content

Commit 1cae793

Browse files
[fix]知识图谱ISVJ-7577 review by qiwei
1 parent 81596e2 commit 1cae793

File tree

2 files changed

+85
-5
lines changed

2 files changed

+85
-5
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
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;
67

78
const rst = { nodes: [], edges: [] };
89
data.forEach((item) => {
@@ -51,7 +52,7 @@ export function nodeFromGraphMap(entity, style, captionField) {
5152
const fillColor = styleData.fillColor || '';
5253
const node = {
5354
id: id + '',
54-
label: label,
55+
label: label === undefined ? '' : label + '',
5556
properties,
5657
lables
5758
};
@@ -161,11 +162,11 @@ function getNodeLabel(entity, captionField) {
161162
const types = JSON.parse(entityTypes || '[]');
162163
const labelStr = labels && labels.join('&');
163164
if (ids.includes(id) || types.includes(labelStr)) {
164-
return properties[name] || '';
165+
return properties[name];
165166
}
166167
}
167168
}
168-
return properties[properties._labelfieldname] || '';
169+
return properties[properties._labelfieldname];
169170
}
170171

171172
function formatFontStyle(fontStyle) {

test/common/overlay/KnowledgeGraphSpec.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,84 @@ 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+
94172
it('dataFromGraphMap', (done) => {
95173
var graphData = [
96174
{
@@ -162,6 +240,7 @@ describe('KnowledgeGraph', () => {
162240
var data = KnowledgeGraph.dataFromGraphMap(graphData, { styles: { style } });
163241
expect(data.nodes).not.toBeNull();
164242
expect(data.edges).not.toBeNull();
243+
expect(data.edges[0].label).toBe('邻接');
165244
done();
166245
});
167246

0 commit comments

Comments
 (0)