@ctrl/react-orgchart 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/index.d.mts +65 -0
- package/dist/index.d.ts +65 -0
- package/dist/index.js +463 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +462 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +69 -53
- package/.circleci/config.yml +0 -46
- package/.editorconfig +0 -13
- package/.eslintignore +0 -5
- package/.eslintrc +0 -16
- package/.nvmrc +0 -1
- package/.prettierrc +0 -8
- package/demo/App.tsx +0 -20
- package/demo/assets/avatar-personnel.svg +0 -1
- package/demo/index.css +0 -28
- package/demo/index.html +0 -15
- package/demo/index.tsx +0 -19
- package/demo/testdata.tsx +0 -1231
- package/snowpack.config.js +0 -14
- package/src/chart/components/iconLink.jsx +0 -46
- package/src/chart/config.ts +0 -83
- package/src/chart/index.js +0 -172
- package/src/chart/onClick.js +0 -37
- package/src/chart/render.js +0 -253
- package/src/chart/renderLines.js +0 -119
- package/src/index.ts +0 -1
- package/src/orgChart.tsx +0 -66
- package/src/utils/collapse.js +0 -7
- package/src/utils/helpers.js +0 -25
- package/src/utils/index.js +0 -3
- package/src/utils/wrapText.js +0 -73
- package/tsconfig.build.json +0 -4
- package/tsconfig.json +0 -23
- package/vercel.json +0 -5
package/src/chart/renderLines.js
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { curveLinear, line } from 'd3-shape';
|
|
2
|
-
|
|
3
|
-
const margin = 10;
|
|
4
|
-
|
|
5
|
-
export function renderLines(config) {
|
|
6
|
-
const {
|
|
7
|
-
svg,
|
|
8
|
-
links,
|
|
9
|
-
nodeWidth,
|
|
10
|
-
nodeHeight,
|
|
11
|
-
borderColor,
|
|
12
|
-
sourceNode,
|
|
13
|
-
treeData,
|
|
14
|
-
animationDuration,
|
|
15
|
-
} = config;
|
|
16
|
-
|
|
17
|
-
const parentNode = sourceNode || treeData;
|
|
18
|
-
|
|
19
|
-
// Select all the links to render the lines
|
|
20
|
-
const link = svg.selectAll('path.link').data(links, ({ source, target }) => {
|
|
21
|
-
return `${source.data.id}-${target.data.id}`;
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
// Define the angled line function
|
|
25
|
-
const angle = line()
|
|
26
|
-
.x(d => d.x)
|
|
27
|
-
.y(d => d.y)
|
|
28
|
-
.curve(curveLinear);
|
|
29
|
-
|
|
30
|
-
// Enter any new links at the parent's previous position.
|
|
31
|
-
const linkEnter = link
|
|
32
|
-
.enter()
|
|
33
|
-
.insert('path', 'g')
|
|
34
|
-
.attr('class', 'link')
|
|
35
|
-
.attr('fill', 'none')
|
|
36
|
-
.attr('stroke', borderColor)
|
|
37
|
-
.attr('stroke-opacity', 1)
|
|
38
|
-
.attr('stroke-width', 1.25)
|
|
39
|
-
.attr('d', d => {
|
|
40
|
-
const linePoints = [
|
|
41
|
-
{
|
|
42
|
-
x: d.source.x + parseInt(nodeWidth / 2, 10),
|
|
43
|
-
y: d.source.y + margin,
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
x: d.source.x + parseInt(nodeWidth / 2, 10),
|
|
47
|
-
y: d.source.y + margin,
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
x: d.source.x + parseInt(nodeWidth / 2, 10),
|
|
51
|
-
y: d.source.y + margin,
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
x: d.source.x + parseInt(nodeWidth / 2, 10),
|
|
55
|
-
y: d.source.y + margin,
|
|
56
|
-
},
|
|
57
|
-
];
|
|
58
|
-
|
|
59
|
-
return angle(linePoints);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
const linkUpdate = linkEnter.merge(link);
|
|
63
|
-
|
|
64
|
-
// Transition links to their new position.
|
|
65
|
-
linkUpdate
|
|
66
|
-
.transition()
|
|
67
|
-
.duration(animationDuration)
|
|
68
|
-
.attr('d', d => {
|
|
69
|
-
const linePoints = [
|
|
70
|
-
{
|
|
71
|
-
x: d.source.x + parseInt(nodeWidth / 2, 10),
|
|
72
|
-
y: d.source.y + nodeHeight,
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
x: d.source.x + parseInt(nodeWidth / 2, 10),
|
|
76
|
-
y: d.target.y - margin,
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
x: d.target.x + parseInt(nodeWidth / 2, 10),
|
|
80
|
-
y: d.target.y - margin,
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
x: d.target.x + parseInt(nodeWidth / 2, 10),
|
|
84
|
-
y: d.target.y,
|
|
85
|
-
},
|
|
86
|
-
];
|
|
87
|
-
|
|
88
|
-
return angle(linePoints);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
// Animate the existing links to the parent's new position
|
|
92
|
-
link
|
|
93
|
-
.exit()
|
|
94
|
-
.transition()
|
|
95
|
-
.duration(animationDuration)
|
|
96
|
-
.attr('d', () => {
|
|
97
|
-
const lineNode = config.sourceNode ? config.sourceNode : parentNode;
|
|
98
|
-
const linePoints = [
|
|
99
|
-
{
|
|
100
|
-
x: lineNode.x + parseInt(nodeWidth / 2, 10),
|
|
101
|
-
y: lineNode.y + nodeHeight + 2,
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
x: lineNode.x + parseInt(nodeWidth / 2, 10),
|
|
105
|
-
y: lineNode.y + nodeHeight + 2,
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
x: lineNode.x + parseInt(nodeWidth / 2, 10),
|
|
109
|
-
y: lineNode.y + nodeHeight + 2,
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
x: lineNode.x + parseInt(nodeWidth / 2, 10),
|
|
113
|
-
y: lineNode.y + nodeHeight + 2,
|
|
114
|
-
},
|
|
115
|
-
];
|
|
116
|
-
|
|
117
|
-
return angle(linePoints);
|
|
118
|
-
});
|
|
119
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './orgChart';
|
package/src/orgChart.tsx
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
import { init } from './chart/index';
|
|
4
|
-
import { Config, config as defaultConfig } from './chart/config';
|
|
5
|
-
|
|
6
|
-
const defaultId = 'react-org-chart';
|
|
7
|
-
|
|
8
|
-
export interface TreeItem {
|
|
9
|
-
[key: string]: TreeItem[] | any;
|
|
10
|
-
id?: string | number;
|
|
11
|
-
parentId?: string | number | null;
|
|
12
|
-
children?: TreeItem[] | null;
|
|
13
|
-
entity?: {
|
|
14
|
-
[key: string]: any;
|
|
15
|
-
avatar?: string;
|
|
16
|
-
link?: string;
|
|
17
|
-
name?: string;
|
|
18
|
-
title?: string;
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
type Props = Partial<Config> & {
|
|
23
|
-
id?: string;
|
|
24
|
-
disableCanvasMouseMove?: boolean;
|
|
25
|
-
disableCanvasMouseWheelZoom?: boolean;
|
|
26
|
-
tree: TreeItem[] | TreeItem;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export class OrgChart extends React.PureComponent<Props> {
|
|
30
|
-
anchor = React.createRef();
|
|
31
|
-
onDestroy!: () => void;
|
|
32
|
-
|
|
33
|
-
componentDidMount() {
|
|
34
|
-
const {
|
|
35
|
-
id = defaultId,
|
|
36
|
-
disableCanvasMouseMove = false,
|
|
37
|
-
disableCanvasMouseWheelZoom = false,
|
|
38
|
-
tree,
|
|
39
|
-
...options
|
|
40
|
-
} = this.props;
|
|
41
|
-
|
|
42
|
-
this.onDestroy = init({
|
|
43
|
-
...defaultConfig,
|
|
44
|
-
id: `#${id}`,
|
|
45
|
-
elem: this.anchor.current,
|
|
46
|
-
data: tree,
|
|
47
|
-
disableCanvasMouseMove,
|
|
48
|
-
disableCanvasMouseWheelZoom,
|
|
49
|
-
...options,
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
componentWillUnmount() {
|
|
54
|
-
this.onDestroy();
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
render() {
|
|
58
|
-
const { id = defaultId } = this.props;
|
|
59
|
-
|
|
60
|
-
return React.createElement('div', {
|
|
61
|
-
id,
|
|
62
|
-
ref: this.anchor,
|
|
63
|
-
style: { width: '100%', height: '100%' },
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
}
|
package/src/utils/collapse.js
DELETED
package/src/utils/helpers.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export const getName = data => data.data.entity && data.data.entity.name;
|
|
2
|
-
|
|
3
|
-
export const getTitle = data => data.data.entity && data.data.entity.title;
|
|
4
|
-
|
|
5
|
-
export const getCount = data => {
|
|
6
|
-
const children = (data.children || []).length || (data._children || []).length;
|
|
7
|
-
if (!children) {
|
|
8
|
-
return '';
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
return `Team (${children})`;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export const getCursorForNode = data =>
|
|
15
|
-
data.data.children || data.data._children ? 'pointer' : 'default';
|
|
16
|
-
|
|
17
|
-
export const customOnClick = (fn, onClick, config) => (event, data) => {
|
|
18
|
-
if (typeof fn === 'function') {
|
|
19
|
-
if (fn(data, event)) {
|
|
20
|
-
onClick(config);
|
|
21
|
-
} else {
|
|
22
|
-
event.stopPropagation();
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
};
|
package/src/utils/index.js
DELETED
package/src/utils/wrapText.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { select } from 'd3-selection';
|
|
2
|
-
import truncate from 'lodash.truncate';
|
|
3
|
-
|
|
4
|
-
const getTruncatedText = (text, maxWordLength) => truncate(text, { length: maxWordLength });
|
|
5
|
-
|
|
6
|
-
// One way of achieving text-wrapping capability in SVG
|
|
7
|
-
// Text is broken down to words, each word is added to a line and then the lines width is checked
|
|
8
|
-
// If the line width is less than the max we move to the next word, if more we add new line etc
|
|
9
|
-
// until the max number of lines is reached.
|
|
10
|
-
export function wrapText(text, maxLineWidth, maxNumberOfLines = 3, maxWordLength = 17) {
|
|
11
|
-
if (!text._groups || !text._groups[0] || !text._groups[0].length) {
|
|
12
|
-
return '';
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
let editedClass = '';
|
|
16
|
-
|
|
17
|
-
text._groups[0].forEach(textNode => {
|
|
18
|
-
const text = select(textNode);
|
|
19
|
-
const x = text.attr('x');
|
|
20
|
-
const y = text.attr('y');
|
|
21
|
-
const dy = parseFloat(text.attr('dy'));
|
|
22
|
-
const lineHeight = 1.1;
|
|
23
|
-
const words = text.text().split(/\s+/).reverse();
|
|
24
|
-
|
|
25
|
-
let lineNumber = 0;
|
|
26
|
-
let curLineWidth;
|
|
27
|
-
let word;
|
|
28
|
-
let line = [];
|
|
29
|
-
let tspan = text
|
|
30
|
-
.text(null)
|
|
31
|
-
.append('tspan')
|
|
32
|
-
.style('text-anchor', 'middle')
|
|
33
|
-
.attr('x', x)
|
|
34
|
-
.attr('y', y)
|
|
35
|
-
.attr('dy', `${dy}em`);
|
|
36
|
-
|
|
37
|
-
while (lineNumber < maxNumberOfLines && words.length) {
|
|
38
|
-
word = words.pop();
|
|
39
|
-
line.push(word);
|
|
40
|
-
tspan.text(line.join(' '));
|
|
41
|
-
|
|
42
|
-
curLineWidth = tspan.node().getComputedTextLength();
|
|
43
|
-
|
|
44
|
-
if (curLineWidth > maxLineWidth) {
|
|
45
|
-
if (lineNumber + 1 === maxNumberOfLines) {
|
|
46
|
-
tspan.text(getTruncatedText(line.join(' '), maxWordLength));
|
|
47
|
-
break;
|
|
48
|
-
} else {
|
|
49
|
-
line.pop();
|
|
50
|
-
tspan.text(line.join(' '));
|
|
51
|
-
line = [word];
|
|
52
|
-
tspan = text
|
|
53
|
-
.append('tspan')
|
|
54
|
-
.style('text-anchor', 'middle')
|
|
55
|
-
.attr('x', x)
|
|
56
|
-
.attr('y', y)
|
|
57
|
-
.attr('dy', ++lineNumber * lineHeight + dy + 'em')
|
|
58
|
-
.text(getTruncatedText(word, maxWordLength));
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (word.length > maxWordLength) {
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (!editedClass) {
|
|
68
|
-
editedClass = text.attr('class').replace(' unedited', '');
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
text.attr('class', editedClass);
|
|
72
|
-
});
|
|
73
|
-
}
|
package/tsconfig.build.json
DELETED
package/tsconfig.json
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compileOnSave": false,
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"allowJs": true,
|
|
5
|
-
"moduleResolution": "node",
|
|
6
|
-
"lib": ["es2015", "dom"],
|
|
7
|
-
"target": "es2015",
|
|
8
|
-
"module": "esnext",
|
|
9
|
-
"esModuleInterop": true,
|
|
10
|
-
"strict": true,
|
|
11
|
-
"newLine": "lf",
|
|
12
|
-
"noImplicitAny": false,
|
|
13
|
-
"noImplicitReturns": true,
|
|
14
|
-
"noFallthroughCasesInSwitch": true,
|
|
15
|
-
"jsx": "react",
|
|
16
|
-
"noEmitOnError": true,
|
|
17
|
-
"noUnusedLocals": true,
|
|
18
|
-
"declaration": true,
|
|
19
|
-
"sourceMap": true,
|
|
20
|
-
"outDir": "dist",
|
|
21
|
-
"skipLibCheck": true
|
|
22
|
-
}
|
|
23
|
-
}
|