-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: update deps * chore: merge * chore: merge * refactor: update graph style * feat: fishbone diagram * docs: add fishbone site
- Loading branch information
Showing
36 changed files
with
13,878 additions
and
16,885 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import type { Graph } from '@antv/g6'; | ||
import React, { | ||
ForwardRefExoticComponent, | ||
PropsWithChildren, | ||
PropsWithoutRef, | ||
RefAttributes, | ||
forwardRef, | ||
useMemo, | ||
} from 'react'; | ||
import { BaseGraph } from '../../core/base-graph'; | ||
import { COMMON_OPTIONS } from '../../core/constants'; | ||
import { mergeOptions } from '../../core/utils/options'; | ||
import { DEFAULT_OPTIONS, getFishboneOptions } from './options'; | ||
import type { FishboneOptions } from './types'; | ||
|
||
export const Fishbone: ForwardRefExoticComponent<PropsWithoutRef<PropsWithChildren<FishboneOptions>> & RefAttributes<Graph>> = forwardRef<Graph, PropsWithChildren<FishboneOptions>>(({ children, ...props }, ref) => { | ||
const { type = 'cause', ...restProps } = props; | ||
|
||
const options = useMemo(() => mergeOptions(COMMON_OPTIONS, DEFAULT_OPTIONS, getFishboneOptions({ type }), restProps), [props]); | ||
|
||
return ( | ||
<BaseGraph {...options} ref={ref}> | ||
{children} | ||
</BaseGraph> | ||
); | ||
}) | ||
|
||
export type { FishboneOptions }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import type { ID, NodeData, SingleLayoutOptions, Size } from '@antv/g6'; | ||
import type { FishboneOptions } from "./types"; | ||
import { measureTextSize } from '../../core/utils/measure-text'; | ||
|
||
export const DEFAULT_OPTIONS: FishboneOptions = { | ||
node: { | ||
style: { | ||
size: 10, | ||
labelText: d => d.id, | ||
labelPlacement: 'center', | ||
} | ||
}, | ||
edge: { | ||
type: 'polyline', | ||
}, | ||
layout: { | ||
type: 'fishbone', | ||
hGap: 40, | ||
vGap: 60, | ||
}, | ||
animation: false, | ||
}; | ||
|
||
const FONT_FAMILY = 'system-ui, sans-serif'; | ||
|
||
const getNodeSize = (id: ID, depth: number): Size => { | ||
if (depth === 0) return measureTextSize(id, [80, 48], { fontSize: 24, fontWeight: 600, fontFamily: FONT_FAMILY }); | ||
if (depth === 1) return measureTextSize(id, [80, 30], { fontSize: 18, fontFamily: FONT_FAMILY }); | ||
return [2, 30]; | ||
}; | ||
|
||
const getNodeFill = (node: NodeData): string => { | ||
const depth = node.depth as number; | ||
if (depth === 0) return '#EFF0F0'; | ||
if (depth === 1) return (node.style?.color as string) || '#EFF0F0'; | ||
return 'transparent'; | ||
} | ||
|
||
export function getFishboneOptions({ type }: Pick<FishboneOptions, 'type'>): FishboneOptions { | ||
const options: FishboneOptions = { | ||
node: { | ||
type: 'rect', | ||
style: { | ||
fill: d => getNodeFill(d), | ||
labelFill: d => d.depth === 1 ? '#fff' : '#262626', | ||
labelFillOpacity: 1, | ||
labelFontSize: d => d.depth === 0 ? 24 : d.depth === 1 ? 18 : 16, | ||
labelFontWeight: d => d.depth === 0 ? 600 : 400, | ||
labelLineHeight: d => d.depth === 0 ? 26 : d.depth === 1 ? 20 : 18, | ||
labelText: d => d.id, | ||
radius: 8, | ||
size: d => getNodeSize(d.id, d.depth!), | ||
} | ||
}, | ||
edge: { | ||
type: 'polyline', | ||
style: { | ||
lineWidth: 3, | ||
stroke: function (data) { | ||
return (this.getNodeData(data.target).style!.color as string) || '#99ADD1'; | ||
}, | ||
}, | ||
}, | ||
transforms: (prev) => [ | ||
...prev, | ||
{ | ||
type: 'assign-color-by-branch', | ||
key: 'assign-color-by-branch', | ||
}, | ||
{ | ||
type: 'arrange-edge-z-index', | ||
key: 'arrange-edge-z-index', | ||
}, | ||
] | ||
}; | ||
|
||
options.layout ||= {} as SingleLayoutOptions; | ||
if (type === 'decision') { | ||
// @ts-ignore | ||
options.node.style.labelPlacement = d => d.depth === 0 || d.depth === 1 ? 'center' : 'right'; | ||
Object.assign(options.layout!, { direction: 'LR' }) | ||
} else if (type === 'cause') { | ||
// @ts-ignore | ||
options.node.style.labelPlacement = d => d.depth === 0 || d.depth === 1 ? 'center' : 'left'; | ||
Object.assign(options.layout!, { direction: 'RL' }) | ||
} | ||
|
||
return options; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { GraphOptions } from "../../types"; | ||
import type { NodeData } from '@antv/g6'; | ||
|
||
export interface FishboneOptions extends GraphOptions { | ||
/** | ||
* The type of the fishbone diagram. | ||
* - `'decision'`: direction from left to right. | ||
* - `'cause'`: direction from right to left. | ||
* @default 'cause' | ||
*/ | ||
type?: 'decision' | 'cause'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.