Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow link stroke width customization #199

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/components/Link/Link.default.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@ export const LinkDefault = (props: ILinkDefaultProps) => {
const linkColor: string =
(fromPort.properties && fromPort.properties.linkColor) || 'cornflowerblue'

const linkStrokeWidth: string =
(fromPort.properties && fromPort.properties.linkStrokeWidth) || '3'

const linkProps = {
config,
points,
linkColor,
startPos,
endPos,
linkStrokeWidth,
...props,
}

return config.showArrowHead
? <ArrowLink {...linkProps} />
: <RegularLink {...linkProps} />
Expand Down
4 changes: 3 additions & 1 deletion src/components/Link/variants/ArrowLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface IArrowLinkProps {
link: ILink
config: IConfig
linkColor: string
linkStrokeWidth: string
points: string
isHovered: boolean
isSelected: boolean
Expand All @@ -22,6 +23,7 @@ export const ArrowLink = ({
link,
config,
linkColor,
linkStrokeWidth,
points,
isHovered,
isSelected,
Expand Down Expand Up @@ -72,7 +74,7 @@ export const ArrowLink = ({
<path
d={points}
stroke={linkColor}
strokeWidth="3"
strokeWidth={linkStrokeWidth}
fill="none"
{...marker}
/>
Expand Down
4 changes: 3 additions & 1 deletion src/components/Link/variants/RegularLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface IRegularLinkProps {
className?: string
points: string
linkColor: string
linkStrokeWidth: string
config: IConfig
link: ILink
startPos: IPosition
Expand All @@ -20,6 +21,7 @@ export const RegularLink = ({
className,
points,
linkColor,
linkStrokeWidth,
config,
link,
startPos,
Expand All @@ -43,7 +45,7 @@ export const RegularLink = ({
>
<circle r="4" cx={startPos.x} cy={startPos.y} fill={linkColor} />
{/* Main line */}
<path d={points} stroke={linkColor} strokeWidth="3" fill="none" />
<path d={points} stroke={linkColor} strokeWidth={linkStrokeWidth} fill="none" />
{/* Thick line to make selection easier */}
<path
d={points}
Expand Down
138 changes: 138 additions & 0 deletions stories/LinkStrokeWidths.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import * as React from 'react'

import { FlowChartWithState, IChart } from '../src'
import { Page } from './components'

const chartSimpleWithLinkStrokeWidhts: IChart = {
offset: {
x: 0,
y: 0,
},
scale: 1,
nodes: {
node1: {
id: 'node1',
type: 'output-only',
position: {
x: 300,
y: 100,
},
ports: {
port1: {
id: 'port1',
type: 'output',
properties: {
value: 'no',
linkStrokeWidth: '30',
},
},
},
},
node2: {
id: 'node2',
type: 'input-output',
position: {
x: 300,
y: 300,
},
ports: {
port1: {
id: 'port1',
type: 'input',
},
port2: {
id: 'port2',
type: 'output',
properties: {
linkStrokeWidth: '10',
},
},
port3: {
id: 'port3',
type: 'output',
},
},
},
node3: {
id: 'node3',
type: 'input-output',
position: {
x: 100,
y: 600,
},
ports: {
port1: {
id: 'port1',
type: 'input',
},
port2: {
id: 'port2',
type: 'output',
},
},
},
node4: {
id: 'node4',
type: 'input-output',
position: {
x: 500,
y: 600,
},
ports: {
port1: {
id: 'port1',
type: 'input',
},
port2: {
id: 'port2',
type: 'output',
},
},
},
},
links: {
link1: {
id: 'link1',
from: {
nodeId: 'node1',
portId: 'port1',
},
to: {
nodeId: 'node2',
portId: 'port1',
},
},
link2: {
id: 'link2',
from: {
nodeId: 'node2',
portId: 'port2',
},
to: {
nodeId: 'node3',
portId: 'port1',
},
},
link3: {
id: 'link3',
from: {
nodeId: 'node2',
portId: 'port3',
},
to: {
nodeId: 'node4',
portId: 'port1',
},
},
},
selected: {},
hovered: {},
}

export const LinkStrokeWidths = () => {
return (
<Page>
<FlowChartWithState initialValue={chartSimpleWithLinkStrokeWidhts} />
</Page>
)
}
2 changes: 2 additions & 0 deletions stories/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { DragAndDropSidebar } from './DragAndDropSidebar'
import { ExternalReactState } from './ExternalReactState'
import { InternalReactState } from './InternalReactState'
import { LinkColors } from './LinkColors'
import { LinkStrokeWidths } from './LinkStrokeWidths'
import { NodeReadonly } from './NodeReadonly'
import { LinkWithArrowHead } from './LinkWithArrowHead'
import { ReadonlyMode } from './ReadonlyMode'
Expand All @@ -32,6 +33,7 @@ storiesOf('Custom Components', module)
.add('Canvas Outer', CustomCanvasOuterDemo)
.add('Canvas Link', () => <CustomLinkDemo />)
.add('Link Colors', () => <LinkColors />)
.add('Link Stroke Widths', () => <LinkStrokeWidths />)

storiesOf('Stress Testing', module).add('default', StressTestDemo)

Expand Down