File size: 10,061 Bytes
1e92f2d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 | import { commonDefaultProps as defaults, svgDefaultProps } from '@nivo/network'
import { groupProperties, themeProperty, motionProperties } from '../../../lib/componentProperties'
import {
chartDimensions,
chartRef,
isInteractive,
commonAccessibilityProps,
blendMode,
annotations,
} from '../../../lib/chart-properties'
import { ChartProperty, Flavor } from '../../../types'
import {
dynamicNodeSizeValue,
dynamicActiveNodeSizeValue,
dynamicLinkThicknessValue,
} from './mapper'
const allFlavors: Flavor[] = ['svg', 'canvas']
const props: ChartProperty[] = [
{
key: 'data',
group: 'Base',
type: '{ nodes: NetworkInputNode[], links: NetworkInputLink[] }',
required: true,
help: 'Chart data defining nodes and links.',
flavors: allFlavors,
description: `
Chart data, which must conform to this structure:
\`\`\`
{
nodes: {
id: string
}[]
links: {
source: string // ref to node id
target: string // ref to node id
}[]
}
\`\`\`
Please note that each node id **must** be unique.
`,
},
...chartDimensions(allFlavors),
chartRef(['svg', 'canvas']),
{
key: 'linkDistance',
group: 'Simulation',
type: 'number | string | (link: Link) => number',
help: `Control links' distance.`,
flavors: allFlavors,
description: `
If you set a **number**, this value will be used for all links.
If you use a **function**, it will receive a link and must return
the desired distance.
Please note that in most cases you won't get links having the
exact distance you specified as it also depends on the other forces.
`,
},
{
key: 'centeringStrength',
group: 'Simulation',
type: 'number',
help: 'Control how much the centering force affects nodes positioning.',
description: `
This value will also affect the strength
of \`distanceMin\` and \`distanceMax\`.
`,
flavors: allFlavors,
defaultValue: defaults.centeringStrength,
control: {
type: 'range',
min: 0,
max: 2,
step: 0.1,
},
},
{
key: 'repulsivity',
group: 'Simulation',
type: 'number',
help: 'Control how nodes repel each other.',
description: `
This value will also affect the strength
of \`distanceMin\` and \`distanceMax\`.
`,
flavors: allFlavors,
defaultValue: defaults.repulsivity,
control: {
type: 'range',
min: 1,
max: 100,
},
},
{
key: 'distanceMin',
group: 'Simulation',
type: 'number',
help: 'Sets the minimum distance between nodes for the many-body force.',
flavors: allFlavors,
defaultValue: defaults.distanceMin,
},
{
key: 'distanceMax',
group: 'Simulation',
type: 'number',
help: 'Sets the maximum disteance between nodes for the many-body force.',
flavors: allFlavors,
defaultValue: defaults.distanceMax,
},
{
key: 'iterations',
group: 'Simulation',
help: 'Adjust the simulation quality.',
description: `
Increasing this number will result in a **more accurate simulation**,
however it will also involve more computing.
`,
type: 'number',
flavors: allFlavors,
defaultValue: defaults.iterations,
control: {
type: 'range',
min: 30,
max: 260,
},
},
themeProperty(allFlavors),
{
key: 'nodeComponent',
group: 'Nodes',
type: 'NetworkNodeComponent',
help: `Custom node component for the SVG implementation.`,
flavors: ['svg'],
defaultValue: 'NetworkNode',
},
{
key: 'renderNode',
group: 'Nodes',
type: 'NetworkNodeCanvasRenderer',
help: `Custom node rendering for the canvas implementation.`,
flavors: ['canvas'],
},
{
key: 'nodeSize',
group: 'Nodes',
type: 'number | (node: InputNode) => number',
help: `Control nodes' size.`,
flavors: allFlavors,
defaultValue: defaults.nodeSize,
control: {
type: 'switchableRange',
disabledValue: dynamicNodeSizeValue,
defaultValue: defaults.nodeSize as number,
unit: 'px',
min: 4,
max: 64,
},
},
{
key: 'activeNodeSize',
group: 'Nodes',
type: 'number | (node: InputNode) => number',
help: `Control active nodes' size.`,
flavors: allFlavors,
defaultValue: defaults.activeNodeSize,
control: {
type: 'switchableRange',
disabledValue: dynamicActiveNodeSizeValue,
defaultValue: defaults.activeNodeSize as number,
unit: 'px',
min: 4,
max: 64,
},
},
{
key: 'inactiveNodeSize',
group: 'Nodes',
type: 'number | (node: InputNode) => number',
help: `Control inactive nodes' size.`,
flavors: allFlavors,
defaultValue: defaults.inactiveNodeSize,
control: {
type: 'range',
unit: 'px',
min: 4,
max: 64,
},
},
{
key: 'nodeColor',
group: 'Nodes',
type: 'string | (node: InputNode) => string',
help: `Control nodes' color.`,
flavors: allFlavors,
defaultValue: defaults.nodeColor,
},
{
key: 'nodeBorderWidth',
group: 'Nodes',
type: 'number | (node: NetworkComputedNode) => number',
help: `Control nodes' border width.`,
flavors: allFlavors,
defaultValue: defaults.nodeBorderWidth,
control: { type: 'lineWidth' },
},
{
key: 'nodeBorderColor',
group: 'Nodes',
type: 'InheritedColorConfig<NetworkComputedNode>',
help: `Control nodes' border color.`,
flavors: allFlavors,
defaultValue: defaults.nodeBorderColor,
control: { type: 'inheritedColor' },
},
{
key: 'linkComponent',
group: 'Links',
type: 'NetworkLinkComponent',
help: `Custom link component for the SVG implementation.`,
flavors: ['svg'],
defaultValue: 'NetworkLink',
},
{
key: 'renderLink',
group: 'Links',
type: 'NetworkLinkCanvasRenderer',
help: `Custom link rendering for the canvas implementation.`,
flavors: ['canvas'],
},
{
key: 'linkThickness',
group: 'Links',
type: 'number | (link: NetworkComputedLink) => number',
help: `Control links' thickness.`,
flavors: allFlavors,
defaultValue: defaults.linkThickness,
control: {
type: 'switchableRange',
disabledValue: dynamicLinkThicknessValue,
defaultValue: defaults.linkThickness as number,
unit: 'px',
min: 1,
max: 12,
},
},
{
key: 'linkColor',
group: 'Links',
type: 'InheritedColorConfig<ComputedLink>',
help: `Control links' color.`,
flavors: allFlavors,
defaultValue: defaults.linkColor,
control: {
type: 'inheritedColor',
inheritableProperties: ['source.color', 'target.color'],
},
},
blendMode({
group: 'Links',
key: 'linkBlendMode',
target: 'links',
flavors: ['svg'],
defaultValue: svgDefaultProps.linkBlendMode,
}),
isInteractive({ flavors: allFlavors, defaultValue: defaults.isInteractive }),
{
key: 'nodeTooltip',
group: 'Interactivity',
type: 'NetworkNodeTooltipComponent',
help: 'Custom tooltip component for nodes.',
flavors: allFlavors,
description: `
An optional component allowing complete tooltip customisation,
it must return a valid HTML element and will receive
the node's data as a property.
`,
},
{
key: 'onClick',
group: 'Interactivity',
help: 'onClick handler.',
type: '(node: NetworkComputedNode, event: MouseEvent) => void',
flavors: allFlavors,
},
{
key: 'onMouseEnter',
group: 'Interactivity',
help: 'onMouseEnter handler.',
type: '(node: ComputedNode, event: MouseEvent) => void',
flavors: ['svg'],
},
{
key: 'onMouseMove',
group: 'Interactivity',
help: 'onMouseMove handler.',
type: '(node: ComputedNode, event: MouseEvent) => void',
flavors: ['svg'],
},
{
key: 'onMouseLeave',
group: 'Interactivity',
help: 'onMouseLeave handler.',
type: '(node: ComputedNode, event: MouseEvent) => void',
flavors: ['svg'],
},
annotations({
target: 'nodes',
flavors: allFlavors,
createDefaults: {
type: 'circle',
match: { id: 'Node 0' },
note: 'New annotation',
noteX: 160,
noteY: 36,
offset: 6,
noteTextOffset: 5,
},
}),
{
key: 'layers',
type: `('links' | 'nodes')[] | FunctionComponent<LayerProps>`,
group: 'Customization',
help: 'Defines the order of layers and add custom layers.',
defaultValue: defaults.layers,
flavors: ['svg', 'canvas'],
},
...commonAccessibilityProps(['svg']),
...motionProperties(['svg'], defaults),
]
export const groups = groupProperties(props)
|