MCPcopy
hub / github.com/HKUDS/LightRAG / resolveNodeColor

Function resolveNodeColor

lightrag_webui/src/utils/graphColor.ts:183–226  ·  view source on GitHub ↗
(
  nodeType: string | undefined,
  currentMap: Map<string, string> | undefined
)

Source from the content-addressed store, hash-verified

181}
182
183export const resolveNodeColor = (
184 nodeType: string | undefined,
185 currentMap: Map<string, string> | undefined
186): ResolveNodeColorResult => {
187 const typeColorMap = currentMap ?? new Map<string, string>()
188 const normalizedType = nodeType ? nodeType.toLowerCase() : 'unknown'
189 const standardType = TYPE_SYNONYMS[normalizedType]
190 const cacheKey = standardType || normalizedType
191
192 if (typeColorMap.has(cacheKey)) {
193 return {
194 color: typeColorMap.get(cacheKey) || DEFAULT_NODE_COLOR,
195 map: typeColorMap,
196 updated: false
197 }
198 }
199
200 if (standardType) {
201 const color = NODE_TYPE_COLORS[standardType] || DEFAULT_NODE_COLOR
202 const newMap = new Map(typeColorMap)
203 newMap.set(standardType, color)
204 return {
205 color,
206 map: newMap,
207 updated: true
208 }
209 }
210
211 const usedExtendedColors = new Set(
212 Array.from(typeColorMap.values()).filter((color) => !PREDEFINED_COLOR_SET.has(color))
213 )
214
215 const unusedColor = EXTENDED_COLORS.find((color) => !usedExtendedColors.has(color))
216 const color = unusedColor || DEFAULT_NODE_COLOR
217
218 const newMap = new Map(typeColorMap)
219 newMap.set(normalizedType, color)
220
221 return {
222 color,
223 map: newMap,
224 updated: true
225 }
226}
227
228export { DEFAULT_NODE_COLOR }

Callers 2

graph.tsFile · 0.90
colorForFunction · 0.90

Calls 6

hasMethod · 0.45
getMethod · 0.45
setMethod · 0.45
filterMethod · 0.45
valuesMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected