simple two node dag
This commit is contained in:
1 parent
d8747a7ee2
commit
69edca7685
11 files changed
+431
-15
No files matched your search
@@ -27,10 +27,6 @@ export const DAGEdge = ({
|
||||
cx1 = x1 + 2 * l1 * Math.cos(theta)
|
||||
cy2 = y2 + 0.5 * l2 * Math.sin(theta)
|
||||
cx2 = x2 - 2 * l2 * Math.cos(theta)
|
||||
} else if (theta === Math.PI) {
|
||||
cy1 *= 1.5
|
||||
cx1 = x1 - 2 * l1 * Math.cos(theta)
|
||||
cy2 *= 0.9
|
||||
} else if ((theta > Math.PI / 2) && (theta < Math.PI)) {
|
||||
cy2 += l2 * Math.sin(theta)
|
||||
cx2 += 10 * l2 * Math.cos(theta)
|
||||
|
||||
@@ -25,19 +25,29 @@ export const Basic: ComponentStory<typeof DAGNode> = args => <SVGBoard
|
||||
<DAGNode {...args}/>
|
||||
</SVGBoard>
|
||||
|
||||
export const WithEdge: ComponentStory<typeof DAGNode> = args => <SVGBoard
|
||||
export const WithFromEdge: ComponentStory<typeof DAGNode> = args => <SVGBoard
|
||||
graphHeight={GRAPH_HEIGHT}
|
||||
>
|
||||
<DAGNode {...args} />
|
||||
</SVGBoard>
|
||||
WithEdge.args = {
|
||||
...(WithEdge.args ?? {}),
|
||||
WithFromEdge.args = {
|
||||
...(WithFromEdge.args ?? {}),
|
||||
edge: {
|
||||
color: 'white',
|
||||
loc: [ NODE_WIDTH * 4, NODE_HEIGHT * 2 ]
|
||||
loc: [NODE_WIDTH * 4, NODE_HEIGHT * 2],
|
||||
direction: '1->2',
|
||||
}
|
||||
}
|
||||
|
||||
export const WithToEdge: ComponentStory<typeof DAGNode> = args => <SVGBoard
|
||||
graphHeight={GRAPH_HEIGHT}
|
||||
>
|
||||
<DAGNode {...args} edge={{
|
||||
color: 'white',
|
||||
loc: [args.loc[0] - args.width, args.loc[1] + args.height / 2],
|
||||
direction: '1<-2',
|
||||
}}/>
|
||||
</SVGBoard>
|
||||
export const WithManyEdges: ComponentStory<typeof DAGNode> = args => <SVGBoard
|
||||
graphHeight={GRAPH_HEIGHT}
|
||||
>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import Color from "chroma-js";
|
||||
import { PencilIcon } from "components/Icons"
|
||||
import { useNodeStyles } from "./styles"
|
||||
import { Node, Point } from "types/graphs";
|
||||
import { Edge, Node, Point } from "types/graphs";
|
||||
import { DAGEdge } from "./DAGEdge";
|
||||
|
||||
|
||||
@@ -11,9 +11,11 @@ export interface NodeProp extends Node {
|
||||
width: number;
|
||||
onXClick?: () => void;
|
||||
onOpenClick?: () => void;
|
||||
debug?: boolean;
|
||||
edge?: {
|
||||
color: string;
|
||||
loc: Point;
|
||||
direction: Edge['direction'];
|
||||
}
|
||||
}
|
||||
export const DAGNode = ({
|
||||
@@ -25,6 +27,7 @@ export const DAGNode = ({
|
||||
onOpenClick = () => { },
|
||||
color,
|
||||
edge,
|
||||
debug=false,
|
||||
}: NodeProp) => {
|
||||
const { classes, theme } = useNodeStyles({
|
||||
color,
|
||||
@@ -51,11 +54,22 @@ export const DAGNode = ({
|
||||
</div>
|
||||
</div>
|
||||
</foreignObject>
|
||||
{edge && <DAGEdge
|
||||
p1={[x + width, y + height/ 2]}
|
||||
p2={edge.loc}
|
||||
direction="1->2"
|
||||
color={edge.color}
|
||||
/>}
|
||||
{
|
||||
edge && (edge.direction === '1->2' ?
|
||||
<DAGEdge
|
||||
p1={[x + width, y + height/ 2]}
|
||||
p2={edge.loc}
|
||||
direction={edge.direction}
|
||||
color={edge.color}
|
||||
debug={debug}
|
||||
/> :
|
||||
<DAGEdge
|
||||
p1={[x, y + height/ 2]}
|
||||
p2={edge.loc}
|
||||
direction={edge.direction}
|
||||
color={edge.color}
|
||||
debug={debug}
|
||||
/>)
|
||||
}
|
||||
</>
|
||||
}
|
||||
Reference in new issue
Block a user