Skip to content

Commit 10023e5

Browse files
committed
Use constant for edge external caption. Use let instead of var
1 parent 2e52a38 commit 10023e5

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export const ZOOM_PROPS = {
1515

1616
export const COMPACT_FLAG = '--compact'
1717

18+
export const EDGE_CAPTION_EXTERNAL = "external"
19+
1820
export const NODE_COLORS_DARK = [
1921
{ color: '#6A1DC3', borderColor: '#6A1DC3', textColor: '#FFFFFF' },
2022
{ color: '#364CFF', borderColor: '#364CFF', textColor: '#FFFFFF' },

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

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
NODE_STROKE_WIDTH,
66
NODE_RADIUS,
77
ZOOM_PROPS,
8+
EDGE_CAPTION_EXTERNAL,
89
} from './constants'
910

1011
const DEFAULT_OPTIONS = {
@@ -208,7 +209,7 @@ function StraightArrow(
208209

209210
// for shortCaptionLength we use textBoundingBox = text.node().getComputedTextLength(),
210211
this.outline = function (shortCaptionLength: number) {
211-
if (captionLayout === "external") {
212+
if (captionLayout === EDGE_CAPTION_EXTERNAL) {
212213
const startBreak = startArrow + (this.shaftLength - shortCaptionLength) / 2
213214
const endBreak = endShaft - (this.shaftLength - shortCaptionLength) / 2
214215

@@ -443,7 +444,7 @@ function ArcArrow(
443444
].join(" ")
444445
}
445446

446-
if (captionLayout === "external") {
447+
if (captionLayout === EDGE_CAPTION_EXTERNAL) {
447448
let captionSweep = shortCaptionLength / arcRadius
448449
if (this.deflection > 0) {
449450
captionSweep *= -1
@@ -1333,26 +1334,26 @@ function GraphD3(_selector: HTMLDivElement, _options: any): IGraphD3 {
13331334

13341335
return (() => {
13351336
const result = []
1336-
for (var nodePair of Array.from(nodePairs)) {
1337-
for (var relationship of Array.from(nodePair.relationships)) {
1337+
for (let nodePair of Array.from(nodePairs)) {
1338+
for (let relationship of Array.from(nodePair.relationships)) {
13381339
delete relationship.arrow
13391340
}
13401341

1341-
var middleRelationshipIndex = (nodePair.relationships.length - 1) / 2
1342-
var defaultDeflectionStep = 30
1342+
let middleRelationshipIndex = (nodePair.relationships.length - 1) / 2
1343+
let defaultDeflectionStep = 30
13431344
const maximumTotalDeflection = 150
13441345
const numberOfSteps = nodePair.relationships.length - 1
13451346
const totalDeflection = defaultDeflectionStep * numberOfSteps
13461347

1347-
var deflectionStep =
1348+
let deflectionStep =
13481349
totalDeflection > maximumTotalDeflection
13491350
? maximumTotalDeflection / numberOfSteps
13501351
: defaultDeflectionStep
13511352

13521353
result.push(
13531354
(() => {
13541355
for (let i = 0; i < nodePair.relationships.length; i++) {
1355-
var ref
1356+
let ref
13561357
relationship = nodePair.relationships[i]
13571358
const nodeRadius = options.nodeRadius
13581359
const shaftWidth = options.relationshipWidth
@@ -1378,7 +1379,7 @@ function GraphD3(_selector: HTMLDivElement, _options: any): IGraphD3 {
13781379
shaftWidth,
13791380
headWidth,
13801381
headHeight,
1381-
relationship.captionLayout || "external"
1382+
relationship.captionLayout || EDGE_CAPTION_EXTERNAL
13821383
)
13831384
} else {
13841385
let deflection =
@@ -1396,7 +1397,7 @@ function GraphD3(_selector: HTMLDivElement, _options: any): IGraphD3 {
13961397
shaftWidth,
13971398
headWidth,
13981399
headHeight,
1399-
relationship.captionLayout || "external"
1400+
relationship.captionLayout || EDGE_CAPTION_EXTERNAL
14001401
)
14011402
}
14021403
}
@@ -1462,8 +1463,8 @@ function GraphD3(_selector: HTMLDivElement, _options: any): IGraphD3 {
14621463
if (!nodePair.isLoop()) {
14631464
const dx = nodePair.nodeA.x - nodePair.nodeB.x
14641465
const dy = nodePair.nodeA.y - nodePair.nodeB.y
1465-
var angle = ((Math.atan2(dy, dx) / Math.PI) * 180 + 360) % 360
1466-
var centreDistance = Math.sqrt(square(dx) + square(dy))
1466+
let angle = ((Math.atan2(dy, dx) / Math.PI) * 180 + 360) % 360
1467+
let centreDistance = Math.sqrt(square(dx) + square(dy))
14671468
result.push(
14681469
(() => {
14691470
const result1: number[] = []
@@ -1488,12 +1489,12 @@ function GraphD3(_selector: HTMLDivElement, _options: any): IGraphD3 {
14881489
function distributeAnglesForLoopArrows(nodePairs: NodePair[], relationships: IRelationship[]) {
14891490
return (() => {
14901491
const result = []
1491-
for (var nodePair of Array.from(nodePairs)) {
1492+
for (let nodePair of Array.from(nodePairs)) {
14921493
if (nodePair.isLoop()) {
1493-
var i: number, separation: number
1494+
let i: number, separation: number
14941495
let angles = []
14951496
const node = nodePair.nodeA
1496-
for (var relationship of Array.from(relationships)) {
1497+
for (let relationship of Array.from(relationships)) {
14971498
if (!relationship.isLoop()) {
14981499
if (relationship.source === node) {
14991500
angles.push(relationship.naturalAngle)
@@ -1505,8 +1506,8 @@ function GraphD3(_selector: HTMLDivElement, _options: any): IGraphD3 {
15051506
}
15061507
angles = angles.map((a) => (a + 360) % 360).sort((a, b) => a - b)
15071508
if (angles.length > 0) {
1508-
var end: number, start: number
1509-
var biggestGap = {
1509+
let end: number, start: number
1510+
let biggestGap = {
15101511
start: 0,
15111512
end: 0,
15121513
}

0 commit comments

Comments
 (0)