feat(minimap): node color func

This commit is contained in:
moklick
2019-08-05 18:04:37 +02:00
parent 34a0df46f9
commit 24a296fef9
8 changed files with 48 additions and 9 deletions
+4 -1
View File
@@ -1,6 +1,7 @@
import React, { useRef, useContext, useEffect } from 'react';
import classnames from 'classnames';
import { isFunction } from '../../utils'
import { getNodesInside } from '../../graph-utils';
import { GraphContext } from '../../GraphContext';
@@ -21,6 +22,7 @@ export default ({ style = {}, className, bgColor = '#f8f8f8', nodeColor = '#ddd'
const height = (state.height / (state.width || 1)) * width;
const bbox = { x: 0, y: 0, width: state.width, height: state.height };
const scaleFactor = width / state.width;
const nodeColorFunc = isFunction(nodeColor) ? nodeColor : () => nodeColor;
useEffect(() => {
if (canvasNode) {
@@ -37,7 +39,8 @@ export default ({ style = {}, className, bgColor = '#f8f8f8', nodeColor = '#ddd'
const x = (pos.x * state.transform[2]) + transformX;
const y = (pos.y * state.transform[2]) + transformY;
ctx.fillStyle = nodeColor;
ctx.fillStyle = nodeColorFunc(n);
ctx.fillRect(
(x * scaleFactor),
(y * scaleFactor),
+1
View File
@@ -0,0 +1 @@
export const isFunction = obj => !!(obj && obj.constructor && obj.call && obj.apply);