Skip to content

Commit 7fa0013

Browse files
committed
Use same node/edge colors on hover. Fix graph on empty node labels
1 parent 500f312 commit 7fa0013

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

redisinsight/ui/src/packages/redisgraph/src/graphd3.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ function GraphD3(_selector: HTMLDivElement, _options: any) {
124124
if (typeof options.onLabelNode === 'function') {
125125
label = options.onLabelNode(d);
126126
} else {
127-
label = d.properties?.name || (d.labels ? d.labels[0] : '');
127+
label = d.properties?.name || (d.labels?.length ? d.labels[0] : '');
128128
}
129129
let maxLength = (maxTextSize - textSize) + 3;
130130
return label.length > maxLength ? Utils.truncateText(label, maxLength) : label;
@@ -241,7 +241,7 @@ function GraphD3(_selector: HTMLDivElement, _options: any) {
241241
return node.enter()
242242
.append('g')
243243
.attr('class', (d) => {
244-
const label = d.labels[0];
244+
const label = d.labels?.length ? d.labels[0] : '';
245245
let classes = 'node';
246246
let highlight;
247247

@@ -303,16 +303,17 @@ function GraphD3(_selector: HTMLDivElement, _options: any) {
303303

304304
function appendRingToNode(svgNode) {
305305
return svgNode.append('circle')
306-
.attr('class', 'ring')
307-
.attr('r', options.nodeRadius * 1.16);
306+
.attr('class', 'ring')
307+
.style('stroke', (d) => labelColors(d.labels?.length ? d.labels[0] : '').borderColor)
308+
.attr('r', options.nodeRadius * 1.16);
308309
}
309310

310311
function appendOutlineToNode(svgNode) {
311312
return svgNode.append('circle')
312313
.attr('class', 'outline')
313314
.attr('r', options.nodeRadius)
314-
.style('fill', (d) => labelColors(d.labels[0]).color)
315-
.style('stroke', (d) => labelColors(d.labels[0]).borderColor);
315+
.style('fill', (d) => labelColors(d.labels?.length ? d.labels[0] : '').color)
316+
.style('stroke', (d) => labelColors(d.labels?.length ? d.labels[0] : '').borderColor);
316317
}
317318

318319
function appendNodeInfo(svgNode) {
@@ -353,15 +354,15 @@ function GraphD3(_selector: HTMLDivElement, _options: any) {
353354
if (typeof options.onLabelNode === 'function') {
354355
label = options.onLabelNode(d);
355356
} else {
356-
label = d.properties?.name || (d.labels ? d.labels[0] : '');
357+
label = d.properties?.name || (d.labels?.length ? d.labels[0] : '');
357358
}
358359

359360
let maxLength = maxTextSize - nominalTextSize - 5;
360361
return label.length > maxLength ? Utils.truncateText(label, maxLength) : label;
361362
})
362363
.attr('class', 'text')
363364
.attr('font-size', (d) => nominalTextSize + "px")
364-
.attr('fill', (d) => labelColors(d.labels[0]).textColor)
365+
.attr('fill', (d) => labelColors(d.labels?.length ? d.labels[0] : '').textColor)
365366
.attr('pointer-events', 'none')
366367
.attr('text-anchor', 'middle')
367368
.attr('dy', () => options.nodeRadius / ((options.nodeRadius * 25) / 100));
@@ -408,7 +409,8 @@ function GraphD3(_selector: HTMLDivElement, _options: any) {
408409

409410
function appendOverlayToRelationship(r) {
410411
return r.append('path')
411-
.attr('class', 'overlay');
412+
.attr('class', 'overlay')
413+
.style('fill', (d) => edgeColors(d.type).color)
412414
}
413415

414416
function appendTextToRelationship(r) {

redisinsight/ui/src/packages/redisgraph/src/styles/styles.less

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@
170170
.node.selected .ring,
171171
.node:hover .ring {
172172
-ms-filter: 'progid:DXImageTransform.Microsoft.Alpha(Opacity=30)';
173-
filter: alpha(opacity=30);
174-
opacity: .3;
173+
filter: alpha(opacity=50);
174+
opacity: .5;
175175
}
176176

177177
.relationship {
@@ -202,8 +202,8 @@
202202
.relationship.selected .overlay,
203203
.relationship:hover .overlay {
204204
-ms-filter: 'progid:DXImageTransform.Microsoft.Alpha(Opacity=30)';
205-
filter: alpha(opacity=30);
206-
opacity: .3;
205+
filter: alpha(opacity=50);
206+
opacity: .5;
207207
}
208208

209209
#graphd3 {

redisinsight/ui/src/packages/redisgraph/src/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ export const unitaryVector = (source, target, newLength) => {
7878
export const darkenColor = (color) => d3.rgb(color).darker(1);
7979

8080

81-
function charCodeSum(str: string) {
81+
function charCodeSum(str: string | undefined) {
82+
if (str === undefined) return 0
8283
let sum = 0
8384
for (let i = 0; i < str.length; i++) {
8485
sum += str.charCodeAt(i)

0 commit comments

Comments
 (0)