Merge pull request #213 from wbkd/develop

fix(connectionline): set stroke color
This commit is contained in:
Moritz
2020-05-11 17:50:10 +02:00
committed by GitHub
8 changed files with 35 additions and 29 deletions
+5 -5
View File
@@ -1,4 +1,4 @@
import React, { useEffect, useState, SVGAttributes } from 'react'; import React, { useEffect, useState, CSSProperties } from 'react';
import cx from 'classnames'; import cx from 'classnames';
import { ElementId, Node, Transform, HandleElement } from '../../types'; import { ElementId, Node, Transform, HandleElement } from '../../types';
@@ -11,7 +11,7 @@ interface ConnectionLineProps {
nodes: Node[]; nodes: Node[];
transform: Transform; transform: Transform;
isInteractive: boolean; isInteractive: boolean;
connectionLineStyle?: SVGAttributes<{}>; connectionLineStyle?: CSSProperties;
className?: string; className?: string;
} }
@@ -41,7 +41,7 @@ export default ({
return null; return null;
} }
const edgeClasses: string = cx('react-flow__edge', 'react-flow__connection', className); const connectionLineClasses: string = cx('react-flow__connection', className);
const hasSource = sourceNode.__rg.handleBounds.source !== null; const hasSource = sourceNode.__rg.handleBounds.source !== null;
// output nodes don't have source handles so we need to use the target one // output nodes don't have source handles so we need to use the target one
@@ -69,8 +69,8 @@ export default ({
} }
return ( return (
<g className={edgeClasses}> <g className={connectionLineClasses}>
<path d={dAttr} {...connectionLineStyle} /> <path d={dAttr} className="react-flow__connection-path" style={connectionLineStyle} />
</g> </g>
); );
}; };
+2 -2
View File
@@ -44,10 +44,10 @@ export default memo(
) : null; ) : null;
return ( return (
<g> <>
<path style={style} d={dAttr} className="react-flow__edge-path" /> <path style={style} d={dAttr} className="react-flow__edge-path" />
{text} {text}
</g> </>
); );
} }
); );
+2 -2
View File
@@ -23,14 +23,14 @@ export default memo(
) : null; ) : null;
return ( return (
<g> <>
<path <path
style={style} style={style}
className="react-flow__edge-path" className="react-flow__edge-path"
d={`M ${sourceX},${sourceY}L ${sourceX},${centerY}L ${targetX},${centerY}L ${targetX},${targetY}`} d={`M ${sourceX},${sourceY}L ${sourceX},${centerY}L ${targetX},${centerY}L ${targetX},${targetY}`}
/> />
{text} {text}
</g> </>
); );
} }
); );
+2 -2
View File
@@ -23,10 +23,10 @@ export default memo(
) : null; ) : null;
return ( return (
<g> <>
<path style={style} className="react-flow__edge-path" d={`M ${sourceX},${sourceY}L ${targetX},${targetY}`} /> <path style={style} className="react-flow__edge-path" d={`M ${sourceX},${sourceY}L ${targetX},${targetY}`} />
{text} {text}
</g> </>
); );
} }
); );
+2 -2
View File
@@ -1,4 +1,4 @@
import React, { memo, SVGAttributes } from 'react'; import React, { memo, CSSProperties } from 'react';
import { useStoreState } from '../../store/hooks'; import { useStoreState } from '../../store/hooks';
import ConnectionLine from '../../components/ConnectionLine/index'; import ConnectionLine from '../../components/ConnectionLine/index';
@@ -9,7 +9,7 @@ interface EdgeRendererProps {
width: number; width: number;
height: number; height: number;
edgeTypes: any; edgeTypes: any;
connectionLineStyle?: SVGAttributes<{}>; connectionLineStyle?: CSSProperties;
connectionLineType?: string; connectionLineType?: string;
onElementClick?: () => void; onElementClick?: () => void;
} }
+8 -8
View File
@@ -1,4 +1,4 @@
import React, { useEffect, useRef, memo, SVGAttributes } from 'react'; import React, { useEffect, useRef, memo, CSSProperties } from 'react';
import classnames from 'classnames'; import classnames from 'classnames';
import { useStoreState, useStoreActions } from '../../store/hooks'; import { useStoreState, useStoreActions } from '../../store/hooks';
@@ -27,7 +27,7 @@ export interface GraphViewProps {
nodeTypes: NodeTypesType; nodeTypes: NodeTypesType;
edgeTypes: EdgeTypesType; edgeTypes: EdgeTypesType;
connectionLineType: string; connectionLineType: string;
connectionLineStyle: SVGAttributes<{}>; connectionLineStyle: CSSProperties;
deleteKeyCode: number; deleteKeyCode: number;
showBackground: boolean; showBackground: boolean;
backgroundGap: number; backgroundGap: number;
@@ -65,7 +65,7 @@ const GraphView = memo(
}: GraphViewProps) => { }: GraphViewProps) => {
const zoomPane = useRef<HTMLDivElement>(null); const zoomPane = useRef<HTMLDivElement>(null);
const rendererNode = useRef<HTMLDivElement>(null); const rendererNode = useRef<HTMLDivElement>(null);
const state = useStoreState(s => ({ const state = useStoreState((s) => ({
width: s.width, width: s.width,
height: s.height, height: s.height,
nodes: s.nodes, nodes: s.nodes,
@@ -73,11 +73,11 @@ const GraphView = memo(
d3Initialised: s.d3Initialised, d3Initialised: s.d3Initialised,
nodesSelectionActive: s.nodesSelectionActive, nodesSelectionActive: s.nodesSelectionActive,
})); }));
const updateSize = useStoreActions(actions => actions.updateSize); const updateSize = useStoreActions((actions) => actions.updateSize);
const setNodesSelection = useStoreActions(actions => actions.setNodesSelection); const setNodesSelection = useStoreActions((actions) => actions.setNodesSelection);
const setOnConnect = useStoreActions(a => a.setOnConnect); const setOnConnect = useStoreActions((a) => a.setOnConnect);
const setSnapGrid = useStoreActions(actions => actions.setSnapGrid); const setSnapGrid = useStoreActions((actions) => actions.setSnapGrid);
const setInteractive = useStoreActions(actions => actions.setInteractive); const setInteractive = useStoreActions((actions) => actions.setInteractive);
const selectionKeyPressed = useKeyPress(selectionKeyCode); const selectionKeyPressed = useKeyPress(selectionKeyCode);
const rendererClasses = classnames('react-flow__renderer', { 'is-interactive': isInteractive }); const rendererClasses = classnames('react-flow__renderer', { 'is-interactive': isInteractive });
+2 -2
View File
@@ -1,4 +1,4 @@
import React, { useMemo, SVGAttributes, HTMLAttributes } from 'react'; import React, { useMemo, CSSProperties, HTMLAttributes } from 'react';
import { StoreProvider } from 'easy-peasy'; import { StoreProvider } from 'easy-peasy';
const nodeEnv: string = process.env.NODE_ENV as string; const nodeEnv: string = process.env.NODE_ENV as string;
@@ -33,7 +33,7 @@ export interface ReactFlowProps extends Omit<HTMLAttributes<HTMLDivElement>, 'on
nodeTypes: NodeTypesType; nodeTypes: NodeTypesType;
edgeTypes: EdgeTypesType; edgeTypes: EdgeTypesType;
connectionLineType: string; connectionLineType: string;
connectionLineStyle: SVGAttributes<{}>; connectionLineStyle: CSSProperties;
deleteKeyCode: number; deleteKeyCode: number;
selectionKeyCode: number; selectionKeyCode: number;
showBackground: boolean; showBackground: boolean;
+12 -6
View File
@@ -48,6 +48,12 @@
.react-flow__edge { .react-flow__edge {
pointer-events: all; pointer-events: all;
&.selected {
.react-flow__edge-path {
stroke: #555;
}
}
&.animated path { &.animated path {
stroke-dasharray: 5; stroke-dasharray: 5;
animation: dashdraw 0.5s linear infinite; animation: dashdraw 0.5s linear infinite;
@@ -55,19 +61,19 @@
} }
.react-flow__connection { .react-flow__connection {
fill: none;
stroke: '#ddd';
pointer-events: none; pointer-events: none;
} }
.react-flow__connection-path {
fill: none;
stroke: #ddd;
stroke-width: 2;
}
.react-flow__edge-path { .react-flow__edge-path {
fill: none; fill: none;
stroke: #bbb; stroke: #bbb;
stroke-width: 2; stroke-width: 2;
&.selected {
stroke: #555;
}
} }
.react-flow__edge-text { .react-flow__edge-text {