From 6f6d465e8374bdc8acea784f91c75e439907681d Mon Sep 17 00:00:00 2001
From: braks <78412429+bcakmakoglu@users.noreply.github.com>
Date: Fri, 14 Oct 2022 02:25:10 +0200
Subject: [PATCH] feat(nc-gui): add color to edges
---
.../nc-gui/components/erd/RelationEdge.vue | 22 +------------------
packages/nc-gui/components/erd/utils.ts | 15 ++++++++++---
2 files changed, 13 insertions(+), 24 deletions(-)
diff --git a/packages/nc-gui/components/erd/RelationEdge.vue b/packages/nc-gui/components/erd/RelationEdge.vue
index 073d9ae64c..4cc019632c 100644
--- a/packages/nc-gui/components/erd/RelationEdge.vue
+++ b/packages/nc-gui/components/erd/RelationEdge.vue
@@ -55,23 +55,13 @@ export default {
-
-
-
-
diff --git a/packages/nc-gui/components/erd/utils.ts b/packages/nc-gui/components/erd/utils.ts
index 5b88eaed09..a6f47fa98a 100644
--- a/packages/nc-gui/components/erd/utils.ts
+++ b/packages/nc-gui/components/erd/utils.ts
@@ -5,7 +5,7 @@ import type { Edge, Elements } from '@vue-flow/core'
import type { MaybeRef } from '@vueuse/core'
import { Position, isEdge, isNode } from '@vue-flow/core'
import { scaleLinear as d3ScaleLinear } from 'd3-scale'
-import { computed, ref, unref, useMetas } from '#imports'
+import { computed, ref, unref, useMetas, useTheme } from '#imports'
export interface ErdFlowConfig {
showPkAndFk: boolean
@@ -27,7 +27,9 @@ interface Relation {
export function useErdElements(tables: MaybeRef, props: MaybeRef) {
const elements = ref([])
- const colorScale = d3ScaleLinear().domain([0, 4]).range(['#ff0072', '#0041d0'])
+ const { theme } = useTheme()
+
+ const colorScale = d3ScaleLinear().domain([0, 3]).range([theme.value.primaryColor, theme.value.accentColor])
const dagreGraph = new dagre.graphlib.Graph()
dagreGraph.setDefaultEdgeLabel(() => ({}))
@@ -212,12 +214,19 @@ export function useErdElements(tables: MaybeRef, props: MaybeRef {
if (isNode(el)) {
+ const color = colorScale(dagreGraph.predecessors(el.id)!.length)
const nodeWithPosition = dagreGraph.node(el.id)
el.targetPosition = Position.Left
el.sourcePosition = Position.Right
el.position = { x: nodeWithPosition.x, y: nodeWithPosition.y }
el.class = 'rounded-lg'
- el.style = { boxShadow: `0 0 0 2px ${colorScale(dagreGraph.predecessors(el.id)!.length)}` }
+ el.data.color = color
+ el.style = { boxShadow: `0 0 0 2px ${color}` }
+ } else if (isEdge(el)) {
+ const node = elements.value.find((nodes) => nodes.id === el.source)
+ if (node) {
+ el.style = { stroke: node.data.color }
+ }
}
})
}