Skip to content

Commit 500f312

Browse files
committed
Fix graph height
1 parent d1ff654 commit 500f312

File tree

5 files changed

+40
-11
lines changed

5 files changed

+40
-11
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ function HandleError(props: { command?: string, data: any }): JSX.Element {
9090
const command = props.command.split(' ')
9191

9292
if (command[command.length - 1] === '--compact') {
93-
return <div className="responseFail">Queries with '--compact' flag is currently not supported.</div>
93+
return <div className="responseFail">'--compact' flag is currently not supported.</div>
9494
}
9595

9696
return null

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ export default function Graph(props: { graphKey: string, data: any[] }) {
4343
const parsedResponse = responseParser(props.data)
4444
let nodeIds = new Set(parsedResponse.nodes.map(n => n.id))
4545
let edgeIds = new Set(parsedResponse.edges.map(e => e.id))
46+
47+
if (nodeIds.size === 0 && parsedResponse.nodeIds.length === 0) {
48+
return <div className="responseFail">No vizualization data.</div>
49+
}
50+
4651
let data = {
4752
results: [{
4853
columns: parsedResponse.headers,
@@ -288,7 +293,7 @@ export default function Graph(props: { graphKey: string, data: any[] }) {
288293
</div>
289294
}
290295
</div>
291-
<div ref={d3Container} id="graphd3" style={{ height: "800px" }}></div>
296+
<div ref={d3Container} id="graphd3"></div>
292297
<div
293298
style={{
294299
position: 'absolute',

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

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,11 @@ 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;
81+
let nominalTextSize = 10;
82+
let maxTextSize = 24;
8383
const VERSION = '2.0.0';
84+
let coreSvg = null;
85+
let height = 585;
8486

8587
let zoomFuncs = {}
8688

@@ -99,9 +101,9 @@ function GraphD3(_selector: HTMLDivElement, _options: any) {
99101
}
100102

101103
function appendGraph(container: d3.Selection<any, unknown, null, undefined>) {
102-
var mainSvg = container.append('svg')
104+
let mainSvg = container.append('svg')
103105
.attr('width', '100%')
104-
.attr('height', '100%')
106+
.attr('height', height)
105107
.attr('class', 'graphd3-graph')
106108
.call(options.graphZoom.on('zoom', (event) => {
107109
let scale = event.transform.k;
@@ -113,8 +115,8 @@ function GraphD3(_selector: HTMLDivElement, _options: any) {
113115
if (svgScale) {
114116
scale *= svgScale;
115117
}
116-
var text = svg.selectAll('.node .text');
117-
var textSize = nominalTextSize;
118+
let text = svg.selectAll('.node .text');
119+
let textSize = nominalTextSize;
118120
if (nominalTextSize * scale > maxTextSize) textSize = maxTextSize / scale;
119121
text.attr("font-size", (textSize - 3) + "px");
120122
text.text((d) => {
@@ -146,6 +148,8 @@ function GraphD3(_selector: HTMLDivElement, _options: any) {
146148

147149
svgNodes = svg.append('g')
148150
.attr('class', 'nodes');
151+
152+
coreSvg = mainSvg
149153
}
150154

151155
function appendInfoPanel(container) {
@@ -465,10 +469,10 @@ function GraphD3(_selector: HTMLDivElement, _options: any) {
465469

466470
function updateNodesAndRelationships(n, r) {
467471

468-
var nodeIds = nodes.map(n => n.id)
472+
let nodeIds = nodes.map(n => n.id)
469473
n = n.filter(k => !nodeIds.includes(k.id))
470474

471-
var edgeIds = relationships.map(e => e.id)
475+
let edgeIds = relationships.map(e => e.id)
472476
r = r.filter(k => !edgeIds.includes(k.id))
473477

474478
updateRelationships(r);
@@ -789,6 +793,22 @@ function GraphD3(_selector: HTMLDivElement, _options: any) {
789793

790794
init();
791795

796+
function resize() {
797+
const isFullScreen = parent.document.body.getElementsByClassName('fullscreen').length > 0
798+
if (isFullScreen) {
799+
coreSvg.attr("height", parent.document.body.offsetHeight - 50)
800+
coreSvg.transition().call(zoom.translateTo, ...ZOOM_PROPS.CAMERA_CENTER(coreSvg.node().getBoundingClientRect().width, coreSvg.node().getBoundingClientRect().height - 300))
801+
} else {
802+
coreSvg.attr("height", height)
803+
coreSvg.transition().call(zoom.translateTo, ...ZOOM_PROPS.CAMERA_CENTER(coreSvg.node().getBoundingClientRect().width, coreSvg.node().getBoundingClientRect().height))
804+
}
805+
simulation.restart()
806+
}
807+
808+
d3.select(window).on("resize", resize)
809+
810+
resize()
811+
792812
return {
793813
graphDataToD3Data,
794814
size,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function responseParser(data: any) {
4343
let types: {[key: string]: number} = {}
4444
let labels: {[key: string]: number} = {}
4545
if (data.length === 0) return {
46-
nodes, edges, types, labels
46+
nodes, edges, types, labels, headers, nodeIds, edgeIds,
4747
}
4848

4949
const entries = data[1].map((entry: any) => {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@
206206
opacity: .3;
207207
}
208208

209+
#graphd3 {
210+
height: 100%;
211+
}
212+
209213
.graphd3-graph {
210214
cursor: move;
211215
background-color: var(--svg-background);

0 commit comments

Comments
 (0)