orgchart 5.0.0 → 6.0.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/.github/workflows/publish.yml +32 -0
- package/README.md +172 -93
- package/README.zh-cn.md +163 -74
- package/README.zh-tw.md +163 -74
- package/bower.json +6 -9
- package/demo/10000-nodes.html +139 -0
- package/demo/ajax-datasource.html +46 -45
- package/demo/bottom2top.html +12 -9
- package/demo/center-on-selected-node.html +21 -17
- package/demo/color-coded.html +12 -9
- package/demo/css/style.css +28 -0
- package/demo/custom-icons.html +12 -9
- package/demo/custom-template.html +12 -9
- package/demo/data-prop-compact.html +11 -8
- package/demo/data-prop-hybrid.html +79 -50
- package/demo/default-collapsed.html +12 -9
- package/demo/drag-drop-hybrid-chart.html +17 -14
- package/demo/drag-drop.html +21 -16
- package/demo/edit-chart.html +148 -94
- package/demo/edit-hybrid-chart.html +178 -135
- package/demo/expand-to-given-depth.html +30 -22
- package/demo/export-chart-pdf.html +12 -9
- package/demo/export-chart-with-pictures.html +19 -12
- package/demo/export-chart.html +12 -9
- package/demo/family-tree.html +14 -11
- package/demo/familytree-custom-properties.html +108 -0
- package/demo/filter-node.html +104 -57
- package/demo/get-hierarchy.html +17 -12
- package/demo/get-related-nodes.html +27 -17
- package/demo/index.html +5 -2
- package/demo/integrate-map.html +32 -27
- package/demo/left2right.html +12 -9
- package/demo/level-offset.html +16 -15
- package/demo/link-node.html +12 -9
- package/demo/local-datasource.html +11 -8
- package/demo/minimap.html +224 -0
- package/demo/nodes-of-different-widths.html +11 -8
- package/demo/ondemand-loading-data.html +88 -91
- package/demo/option-createNode.html +28 -17
- package/demo/pan-zoom.html +20 -11
- package/demo/reload-data.html +17 -14
- package/demo/report-path.html +59 -29
- package/demo/responsive-design.html +14 -11
- package/demo/right2left.html +12 -9
- package/demo/toggle-sibs-resp.html +12 -9
- package/demo/ul-datasource.html +11 -8
- package/demo/vertical-level.html +12 -9
- package/dist/css/{jquery.orgchart.css → orgchart.css} +143 -80
- package/dist/css/orgchart.min.css +1 -0
- package/dist/js/orgchart.js +4101 -0
- package/dist/js/orgchart.min.js +2 -0
- package/dist/js/orgchart.min.js.map +1 -0
- package/gulpfile.js +37 -26
- package/package.json +32 -32
- package/src/css/{jquery.orgchart.css → orgchart.css} +143 -80
- package/src/js/orgchart.js +4101 -0
- package/test/cypress/e2e/demo-interactions.cy.js +91 -0
- package/test/cypress/e2e/demo-rendering.cy.js +100 -0
- package/test/cypress/e2e/drag-drop-hybrid-chart.cy.js +22 -0
- package/test/cypress/e2e/edit-chart.cy.js +20 -0
- package/test/cypress/e2e/level-offset.cy.js +21 -0
- package/test/cypress/e2e/minimap.cy.js +66 -0
- package/test/cypress/e2e/pan-zoom.cy.js +165 -0
- package/test/cypress/e2e/report-path.cy.js +20 -0
- package/test/cypress/e2e/vertical-vevel.cy.js +5 -3
- package/test/e2e/local-datasource/test.js +1 -1
- package/test/integration/init-tests.js +168 -62
- package/test/integration/tests.js +1034 -56
- package/test/unit/lifecycle-builders-export.tests.js +1426 -0
- package/test/unit/minimap.tests.js +210 -0
- package/test/unit/tests.js +2372 -252
- package/dist/css/jquery.orgchart.min.css +0 -1
- package/dist/js/jquery.orgchart.js +0 -1741
- package/dist/js/jquery.orgchart.min.js +0 -5
- package/dist/js/jquery.orgchart.min.js.map +0 -1
- package/src/js/jquery.orgchart.js +0 -1741
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
const chai = require('chai');
|
|
2
|
+
const sinon = require('sinon');
|
|
3
|
+
const sinonChai = require('sinon-chai').default;
|
|
4
|
+
|
|
5
|
+
chai.use(sinonChai);
|
|
6
|
+
require('jsdom-global')();
|
|
7
|
+
process.env.ORGCHART_TEST = '1';
|
|
8
|
+
|
|
9
|
+
const OrgChart = require('../../src/js/orgchart');
|
|
10
|
+
|
|
11
|
+
function query(selector, root) {
|
|
12
|
+
return (root || document).querySelector(selector);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function setClientSize(element, width, height) {
|
|
16
|
+
Object.defineProperty(element, 'clientWidth', {
|
|
17
|
+
configurable: true,
|
|
18
|
+
get: function () {
|
|
19
|
+
return width;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
Object.defineProperty(element, 'clientHeight', {
|
|
23
|
+
configurable: true,
|
|
24
|
+
get: function () {
|
|
25
|
+
return height;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function stubRect(element, rect) {
|
|
31
|
+
return sinon.stub(element, 'getBoundingClientRect').callsFake(function () {
|
|
32
|
+
return {
|
|
33
|
+
left: rect.left,
|
|
34
|
+
top: rect.top,
|
|
35
|
+
width: rect.width,
|
|
36
|
+
height: rect.height,
|
|
37
|
+
right: rect.left + rect.width,
|
|
38
|
+
bottom: rect.top + rect.height
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function parseMatrix(transform) {
|
|
44
|
+
return transform.slice(7, -1).split(',').map(function (value) {
|
|
45
|
+
return parseFloat(value.trim());
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
describe('orgchart minimap unit tests', function () {
|
|
50
|
+
let container;
|
|
51
|
+
let chart;
|
|
52
|
+
let restorableDoubles;
|
|
53
|
+
const ds = {
|
|
54
|
+
id: 'n1',
|
|
55
|
+
name: 'Lao Lao',
|
|
56
|
+
title: 'general manager',
|
|
57
|
+
children: [
|
|
58
|
+
{ id: 'n2', name: 'Bo Miao', title: 'department manager' },
|
|
59
|
+
{
|
|
60
|
+
id: 'n3',
|
|
61
|
+
name: 'Su Miao',
|
|
62
|
+
title: 'department manager',
|
|
63
|
+
children: [
|
|
64
|
+
{ id: 'n5', name: 'Tie Hua', title: 'senior engineer' },
|
|
65
|
+
{ id: 'n6', name: 'Hei Hei', title: 'senior engineer' }
|
|
66
|
+
]
|
|
67
|
+
}
|
|
68
|
+
]
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
beforeEach(function () {
|
|
72
|
+
document.body.innerHTML = '<div id="chart-container"></div>';
|
|
73
|
+
container = document.getElementById('chart-container');
|
|
74
|
+
restorableDoubles = [];
|
|
75
|
+
chart = new OrgChart({
|
|
76
|
+
chartContainer: '#chart-container',
|
|
77
|
+
data: JSON.parse(JSON.stringify(ds)),
|
|
78
|
+
nodeContent: 'title'
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
afterEach(function () {
|
|
83
|
+
restorableDoubles.forEach(function (double) {
|
|
84
|
+
if (double && typeof double.restore === 'function') {
|
|
85
|
+
double.restore();
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
document.body.innerHTML = '';
|
|
89
|
+
chart = null;
|
|
90
|
+
container = null;
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('keeps minimap disabled by default', function () {
|
|
94
|
+
chai.expect(chart.options.minimap).to.equal(false);
|
|
95
|
+
chai.expect(query('.orgchart-minimap', container)).to.equal(null);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('mounts a minimap overlay when minimap is enabled', function () {
|
|
99
|
+
chart.init({
|
|
100
|
+
data: JSON.parse(JSON.stringify(ds)),
|
|
101
|
+
nodeContent: 'title',
|
|
102
|
+
minimap: true
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
chai.expect(query('.orgchart-minimap', container)).to.not.equal(null);
|
|
106
|
+
chai.expect(query('.orgchart-minimap-stage', container)).to.not.equal(null);
|
|
107
|
+
chai.expect(query('.orgchart-minimap-viewport', container)).to.not.equal(null);
|
|
108
|
+
chai.expect(query('.orgchart-minimap-node', container)).to.not.equal(null);
|
|
109
|
+
chai.expect(query('.orgchart-minimap .orgchart', container)).to.equal(null);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('toggles the minimap overlay through setOptions()', function () {
|
|
113
|
+
chart.setOptions('minimap', true);
|
|
114
|
+
chai.expect(query('.orgchart-minimap', container)).to.not.equal(null);
|
|
115
|
+
chai.expect(container.style.position).to.equal('relative');
|
|
116
|
+
|
|
117
|
+
chart.setOptions({ minimap: false });
|
|
118
|
+
chai.expect(query('.orgchart-minimap', container)).to.equal(null);
|
|
119
|
+
chai.expect(container.style.position).to.equal('');
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('updates the minimap viewport from the current chart transform', function () {
|
|
123
|
+
let stage;
|
|
124
|
+
let viewport;
|
|
125
|
+
|
|
126
|
+
chart.setOptions('minimap', true);
|
|
127
|
+
stage = query('.orgchart-minimap-stage', container);
|
|
128
|
+
viewport = query('.orgchart-minimap-viewport', container);
|
|
129
|
+
setClientSize(container, 400, 240);
|
|
130
|
+
setClientSize(stage, 180, 104);
|
|
131
|
+
restorableDoubles.push(stubRect(container, { left: 0, top: 0, width: 400, height: 240 }));
|
|
132
|
+
restorableDoubles.push(stubRect(chart.chart, { left: -100, top: -50, width: 1000, height: 600 }));
|
|
133
|
+
chart.chart.style.transform = 'matrix(1, 0, 0, 1, -100, -50)';
|
|
134
|
+
|
|
135
|
+
chart.updateMinimap(true);
|
|
136
|
+
|
|
137
|
+
chai.expect(parseFloat(viewport.style.width)).to.be.closeTo(69.33333333333333, 0.000001);
|
|
138
|
+
chai.expect(parseFloat(viewport.style.height)).to.be.closeTo(41.6, 0.000001);
|
|
139
|
+
chai.expect(viewport.style.transform).to.equal('translate(20.666666666666664px, 8.666666666666668px)');
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('renders simplified minimap color blocks from the chart nodes', function () {
|
|
143
|
+
let stage;
|
|
144
|
+
let minimapNode;
|
|
145
|
+
const nodeElements = Array.from(chart.chart.querySelectorAll('.node'));
|
|
146
|
+
|
|
147
|
+
nodeElements[0].querySelector('.title').style.backgroundColor = 'rgba(200, 100, 50, 0.4)';
|
|
148
|
+
chart.setOptions('minimap', true);
|
|
149
|
+
stage = query('.orgchart-minimap-stage', container);
|
|
150
|
+
setClientSize(container, 400, 240);
|
|
151
|
+
setClientSize(stage, 180, 104);
|
|
152
|
+
restorableDoubles.push(stubRect(container, { left: 0, top: 0, width: 400, height: 240 }));
|
|
153
|
+
restorableDoubles.push(stubRect(chart.chart, { left: 0, top: 0, width: 1000, height: 600 }));
|
|
154
|
+
nodeElements.forEach(function (nodeElement, index) {
|
|
155
|
+
restorableDoubles.push(stubRect(nodeElement, {
|
|
156
|
+
left: 20 + (index * 40),
|
|
157
|
+
top: 10 + (index * 30),
|
|
158
|
+
width: 130,
|
|
159
|
+
height: 40
|
|
160
|
+
}));
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
chart.updateMinimap(true);
|
|
164
|
+
minimapNode = query('.orgchart-minimap-node', container);
|
|
165
|
+
|
|
166
|
+
chai.expect(query('.orgchart-minimap .orgchart', container)).to.equal(null);
|
|
167
|
+
chai.expect(container.querySelectorAll('.orgchart-minimap-node').length).to.equal(nodeElements.length);
|
|
168
|
+
chai.expect(minimapNode.style.backgroundColor).to.equal('rgb(136, 68, 34)');
|
|
169
|
+
chai.expect(minimapNode.style.height).to.equal('18px');
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('moves the main chart when the minimap viewport is dragged', function () {
|
|
173
|
+
let stage;
|
|
174
|
+
let viewport;
|
|
175
|
+
|
|
176
|
+
chart.setOptions('minimap', true);
|
|
177
|
+
stage = query('.orgchart-minimap-stage', container);
|
|
178
|
+
viewport = query('.orgchart-minimap-viewport', container);
|
|
179
|
+
setClientSize(container, 400, 240);
|
|
180
|
+
setClientSize(stage, 180, 104);
|
|
181
|
+
restorableDoubles.push(stubRect(container, { left: 0, top: 0, width: 400, height: 240 }));
|
|
182
|
+
restorableDoubles.push(stubRect(chart.chart, { left: -100, top: -50, width: 1000, height: 600 }));
|
|
183
|
+
chart.chart.style.transform = 'matrix(1, 0, 0, 1, -100, -50)';
|
|
184
|
+
|
|
185
|
+
chart.updateMinimap(true);
|
|
186
|
+
chart.moveChartFromMinimap(31.333333333333336, 14.666666666666664, parseFloat(viewport.style.width), parseFloat(viewport.style.height));
|
|
187
|
+
|
|
188
|
+
chai.expect(parseMatrix(chart.chart.style.transform)[4]).to.be.closeTo(-161.53846153846158, 0.000001);
|
|
189
|
+
chai.expect(parseMatrix(chart.chart.style.transform)[5]).to.be.closeTo(-84.6153846153846, 0.000001);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it('routes minimap wheel zoom through setChartScale()', function () {
|
|
193
|
+
const scaleSpy = sinon.spy(chart, 'setChartScale');
|
|
194
|
+
|
|
195
|
+
restorableDoubles.push(scaleSpy);
|
|
196
|
+
chart.setOptions('minimap', true);
|
|
197
|
+
setClientSize(container, 400, 240);
|
|
198
|
+
restorableDoubles.push(stubRect(container, { left: 10, top: 20, width: 400, height: 240 }));
|
|
199
|
+
|
|
200
|
+
chart.minimapWheelHandler({
|
|
201
|
+
deltaY: -100,
|
|
202
|
+
preventDefault: function () {}
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
chai.expect(scaleSpy.calledOnce).to.equal(true);
|
|
206
|
+
chai.expect(scaleSpy.firstCall.args[0]).to.equal(chart.chart);
|
|
207
|
+
chai.expect(scaleSpy.firstCall.args[1]).to.equal(1.2);
|
|
208
|
+
chai.expect(scaleSpy.firstCall.args[2]).to.deep.equal({ x: 210, y: 140 });
|
|
209
|
+
});
|
|
210
|
+
});
|