Skip to content

Commit d1ff654

Browse files
committed
- Don't scale font size on zoom
- Also fix querying keys that contain quotes.
1 parent be19e50 commit d1ff654

File tree

2 files changed

+35
-23
lines changed

2 files changed

+35
-23
lines changed

redisinsight/ui/src/packages/redisgraph/src/Graph.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export default function Graph(props: { graphKey: string, data: any[] }) {
7070
if (parsedResponse.nodeIds.length > 0) {
7171
try {
7272
/* Fetch named path nodes */
73-
const resp = await executeRedisCommand(`graph.ro_query "${props.graphKey}" "MATCH (n) WHERE id(n) IN [${[...parsedResponse.nodeIds]}] RETURN n"`);
73+
const resp = await executeRedisCommand(`graph.ro_query ${props.graphKey} "MATCH (n) WHERE id(n) IN [${[...parsedResponse.nodeIds]}] RETURN n"`);
7474

7575
if (Array.isArray(resp) && (resp.length >= 1 || resp[0].status === 'success')) {
7676
const parsedData = responseParser(resp[0].response)
@@ -101,7 +101,7 @@ export default function Graph(props: { graphKey: string, data: any[] }) {
101101

102102
try {
103103
/* Fetch neighbours automatically */
104-
const resp = await executeRedisCommand(`graph.ro_query "${props.graphKey}" "MATCH (n)-[t]->(m) WHERE ID(n) IN [${[...nodeIds]}] OR ID(m) IN [${[...nodeIds]}] RETURN DISTINCT t"`);
104+
const resp = await executeRedisCommand(`graph.ro_query ${props.graphKey} "MATCH (n)-[t]->(m) WHERE ID(n) IN [${[...nodeIds]}] OR ID(m) IN [${[...nodeIds]}] RETURN DISTINCT t"`);
105105

106106
if (Array.isArray(resp) && (resp.length >= 1 || resp[0].status === 'success')) {
107107
const parsedData = responseParser(resp[0].response)

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

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ function GraphD3(_selector: HTMLDivElement, _options: any) {
7878
let svgTranslate: number[];
7979
let node: any;
8080
let justLoaded = false;
81+
var nominalTextSize = 10;
82+
var maxTextSize = 24;
8183
const VERSION = '2.0.0';
8284

8385
let zoomFuncs = {}
@@ -98,27 +100,36 @@ function GraphD3(_selector: HTMLDivElement, _options: any) {
98100

99101
function appendGraph(container: d3.Selection<any, unknown, null, undefined>) {
100102
var mainSvg = container.append('svg')
101-
.attr('width', '100%')
102-
.attr('height', '100%')
103-
.attr('class', 'graphd3-graph')
104-
.call(options.graphZoom.on('zoom', (event) => {
105-
let scale = event.transform.k;
106-
const translate = [event.transform.x, event.transform.y];
107-
108-
if (svgTranslate) {
109-
translate[0] += svgTranslate[0];
110-
translate[1] += svgTranslate[1];
111-
}
112-
113-
if (svgScale) {
114-
scale *= svgScale;
103+
.attr('width', '100%')
104+
.attr('height', '100%')
105+
.attr('class', 'graphd3-graph')
106+
.call(options.graphZoom.on('zoom', (event) => {
107+
let scale = event.transform.k;
108+
const translate = [event.transform.x, event.transform.y];
109+
if (svgTranslate) {
110+
translate[0] += svgTranslate[0];
111+
translate[1] += svgTranslate[1];
112+
}
113+
if (svgScale) {
114+
scale *= svgScale;
115+
}
116+
var text = svg.selectAll('.node .text');
117+
var textSize = nominalTextSize;
118+
if (nominalTextSize * scale > maxTextSize) textSize = maxTextSize / scale;
119+
text.attr("font-size", (textSize - 3) + "px");
120+
text.text((d) => {
121+
let label: string;
122+
if (typeof options.onLabelNode === 'function') {
123+
label = options.onLabelNode(d);
124+
} else {
125+
label = d.properties?.name || (d.labels ? d.labels[0] : '');
115126
}
116-
117-
svg.attr('transform', `translate(${translate[0]}, ${translate[1]}) scale(${scale})`);
118-
}))
127+
let maxLength = (maxTextSize - textSize) + 3;
128+
return label.length > maxLength ? Utils.truncateText(label, maxLength) : label;
129+
})
130+
svg.attr('transform', `translate(${translate[0]}, ${translate[1]}) scale(${scale})`);
131+
}))
119132
.on('dblclick.zoom', null)
120-
121-
122133
svg = mainSvg.append('g')
123134
.attr('width', '100%')
124135
.attr('height', '100%');
@@ -341,10 +352,11 @@ function GraphD3(_selector: HTMLDivElement, _options: any) {
341352
label = d.properties?.name || (d.labels ? d.labels[0] : '');
342353
}
343354

344-
return label.length > 10 ? Utils.truncateText(label, 10) : label;
355+
let maxLength = maxTextSize - nominalTextSize - 5;
356+
return label.length > maxLength ? Utils.truncateText(label, maxLength) : label;
345357
})
346358
.attr('class', 'text')
347-
.attr('font-size', '10px')
359+
.attr('font-size', (d) => nominalTextSize + "px")
348360
.attr('fill', (d) => labelColors(d.labels[0]).textColor)
349361
.attr('pointer-events', 'none')
350362
.attr('text-anchor', 'middle')

0 commit comments

Comments
 (0)