orgchart 3.4.0 → 3.5.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/gulpfile.js CHANGED
@@ -48,7 +48,8 @@ gulp.task('addAssets', gulp.series('integration-tests', function () {
48
48
  'node_modules/jquery/dist/jquery.min.js',
49
49
  'node_modules/jquery-mockjax/dist/jquery.mockjax.min.js',
50
50
  'node_modules/html2canvas/dist/html2canvas.min.js',
51
- 'node_modules/jspdf/dist/jspdf.umd.min.js'
51
+ 'node_modules/jspdf/dist/jspdf.umd.min.js',
52
+ 'node_modules/json-digger/dist/json-digger.js'
52
53
  ])
53
54
  .pipe(gulp.dest(paths.demoJSFolder));
54
55
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orgchart",
3
- "version": "3.4.0",
3
+ "version": "3.5.0",
4
4
  "description": "Simple and direct organization chart(tree-like hierarchy) plugin based on pure DOM and jQuery.",
5
5
  "main": "./dist/js/jquery.orgchart.min.js",
6
6
  "style": [
@@ -40,7 +40,7 @@
40
40
  "html2canvas": "^1.4.1",
41
41
  "jquery": "^3.6.2",
42
42
  "jquery-mockjax": "^2.6.0",
43
- "json-digger": "^1.3.0",
43
+ "json-digger": "^2.0.2",
44
44
  "jspdf": "^2.5.1"
45
45
  },
46
46
  "devDependencies": {
@@ -460,17 +460,9 @@
460
460
  }
461
461
 
462
462
  /* styles for vertical nodes */
463
- .orgchart .hierarchy.hybrid > .node {
464
- margin-bottom: 0;
465
- }
466
-
467
- .orgchart .hierarchy.hybrid > .node::after {
468
- content: none;
469
- }
470
463
 
471
464
  .orgchart .nodes.vertical {
472
465
  display: block;
473
- margin: 0;
474
466
  padding-left: 18px;
475
467
  }
476
468
 
@@ -491,19 +483,10 @@
491
483
  content: none;
492
484
  }
493
485
 
494
- .orgchart .nodes.vertical::before {
495
- content: '';
496
- display: inline-block;
497
- position: relative;
498
- height: 14px;
499
- width: 2px;
500
- left: -9px;
501
- background-color: rgba(217, 83, 79, 0.8);
502
- }
503
486
  .orgchart .nodes.vertical > .hierarchy:first-child::before {
504
487
  box-sizing: border-box;
505
- top: -4px;
506
- height: 30px;
488
+ top: -11px;
489
+ height: 35px;
507
490
  width: calc(50% - 2px);
508
491
  border-width: 2px 0 0 2px;
509
492
  }
@@ -373,6 +373,9 @@
373
373
  data.relationship = flags + (data.children && data.children.length > 0 ? 1 : 0);
374
374
  if (data.children) {
375
375
  data.children.forEach(function(item) {
376
+ if (data.isHybrid || data.isVertical) {
377
+ item.isVertical = true;
378
+ }
376
379
  that.attachRel(item, '1' + (data.children.length > 1 ? 1 : 0));
377
380
  });
378
381
  }
@@ -1093,7 +1096,7 @@
1093
1096
  this.$chart.find('.allowedDrop').removeClass('allowedDrop');
1094
1097
  },
1095
1098
  // when user drops the node, it will be removed from original parent node and be added to new parent node
1096
- dropHandler: function (event) {
1099
+ dropHandler: async function (event) {
1097
1100
  var that = this;
1098
1101
  var $dropZone = $(event.delegateTarget);
1099
1102
  var $dragged = this.$chart.data('dragged');
@@ -1117,52 +1120,50 @@
1117
1120
  return;
1118
1121
  }
1119
1122
  // special process for hybrid chart
1120
- if (this.$chart.data('options').verticalLevel > 1) {
1121
- var datasource = this.$chart.data('options').data;
1122
- var digger = new JSONDigger(datasource, this.$chart.data('options').nodeId, 'children');
1123
- digger.findNodeById($dragged.data('nodeData').id).then(function(draggedNode) {
1124
- var copy = Object.assign({}, draggedNode)
1125
- digger.removeNode(draggedNode.id).then(function() {
1126
- digger.findNodeById($dropZone.data('nodeData').id).then(function(dropNode) {
1127
- if (dropNode.children) {
1128
- dropNode.children.push(copy);
1129
- } else {
1130
- dropNode.children = [copy];
1131
- }
1132
- that.init({ 'data': datasource });
1133
- });
1134
- });
1135
- });
1136
- } else {
1137
- // The folowing code snippets are used to process horizontal chart
1138
- // firstly, deal with the hierarchy of drop zone
1139
- if (!$dropZone.siblings('.nodes').length) { // if the drop zone is a leaf node
1140
- $dropZone.append('<i class="edge verticalEdge bottomEdge oci"></i>')
1141
- .after('<ul class="nodes"></ul>')
1142
- .siblings('.nodes').append($dragged.find('.horizontalEdge').remove().end().closest('.hierarchy'));
1143
- if ($dropZone.children('.title').length) {
1144
- $dropZone.children('.title').prepend('<i class="oci '+ this.$chart.data('options').parentNodeSymbol + ' symbol"></i>');
1123
+ var datasource = this.$chart.data('options').data;
1124
+ var digger = new JSONDigger(datasource, this.$chart.data('options').nodeId, 'children');
1125
+ const hybridNode = digger.findOneNode({ 'isHybrid': true });
1126
+ if (this.$chart.data('options').verticalLevel > 1 || hybridNode) {
1127
+ var draggedNode = digger.findNodeById($dragged.data('nodeData').id);
1128
+ var copy = Object.assign({}, draggedNode);
1129
+ digger.removeNode(draggedNode.id);
1130
+ var dropNode = digger.findNodeById($dropZone.data('nodeData').id);
1131
+ if (dropNode.children) {
1132
+ dropNode.children.push(copy);
1133
+ } else {
1134
+ dropNode.children = [copy];
1145
1135
  }
1136
+ that.init({ 'data': datasource });
1146
1137
  } else {
1147
- var horizontalEdges = '<i class="edge horizontalEdge rightEdge oci"></i><i class="edge horizontalEdge leftEdge oci"></i>';
1148
- if (!$dragged.find('.horizontalEdge').length) {
1149
- $dragged.append(horizontalEdges);
1138
+ // The folowing code snippets are used to process horizontal chart
1139
+ // firstly, deal with the hierarchy of drop zone
1140
+ if (!$dropZone.siblings('.nodes').length) { // if the drop zone is a leaf node
1141
+ $dropZone.append('<i class="edge verticalEdge bottomEdge oci"></i>')
1142
+ .after('<ul class="nodes"></ul>')
1143
+ .siblings('.nodes').append($dragged.find('.horizontalEdge').remove().end().closest('.hierarchy'));
1144
+ if ($dropZone.children('.title').length) {
1145
+ $dropZone.children('.title').prepend('<i class="oci '+ this.$chart.data('options').parentNodeSymbol + ' symbol"></i>');
1146
+ }
1147
+ } else {
1148
+ var horizontalEdges = '<i class="edge horizontalEdge rightEdge oci"></i><i class="edge horizontalEdge leftEdge oci"></i>';
1149
+ if (!$dragged.find('.horizontalEdge').length) {
1150
+ $dragged.append(horizontalEdges);
1151
+ }
1152
+ $dropZone.siblings('.nodes').append($dragged.closest('.hierarchy'));
1153
+ var $dropSibs = $dragged.closest('.hierarchy').siblings().find('.node:first');
1154
+ if ($dropSibs.length === 1) {
1155
+ $dropSibs.append(horizontalEdges);
1156
+ }
1150
1157
  }
1151
- $dropZone.siblings('.nodes').append($dragged.closest('.hierarchy'));
1152
- var $dropSibs = $dragged.closest('.hierarchy').siblings().find('.node:first');
1153
- if ($dropSibs.length === 1) {
1154
- $dropSibs.append(horizontalEdges);
1158
+ // secondly, deal with the hierarchy of dragged node
1159
+ if ($dragZone.siblings('.nodes').children('.hierarchy').length === 1) { // if there is only one sibling node left
1160
+ $dragZone.siblings('.nodes').children('.hierarchy').find('.node:first')
1161
+ .find('.horizontalEdge').remove();
1162
+ } else if ($dragZone.siblings('.nodes').children('.hierarchy').length === 0) {
1163
+ $dragZone.find('.bottomEdge, .symbol').remove()
1164
+ .end().siblings('.nodes').remove();
1155
1165
  }
1156
1166
  }
1157
- // secondly, deal with the hierarchy of dragged node
1158
- if ($dragZone.siblings('.nodes').children('.hierarchy').length === 1) { // if there is only one sibling node left
1159
- $dragZone.siblings('.nodes').children('.hierarchy').find('.node:first')
1160
- .find('.horizontalEdge').remove();
1161
- } else if ($dragZone.siblings('.nodes').children('.hierarchy').length === 0) {
1162
- $dragZone.find('.bottomEdge, .symbol').remove()
1163
- .end().siblings('.nodes').remove();
1164
- }
1165
- }
1166
1167
  },
1167
1168
  //
1168
1169
  touchstartHandler: function (event) {
@@ -1345,11 +1346,16 @@
1345
1346
  $nodeDiv.data('nodeData', nodeData);
1346
1347
  // append 4 direction arrows or expand/collapse buttons
1347
1348
  var flags = data.relationship || '';
1348
- if (opts.verticalLevel && level >= opts.verticalLevel) {
1349
- if ((level + 1) > opts.verticalLevel && Number(flags.substr(2,1))) {
1349
+ if ((opts.verticalLevel && level >= opts.verticalLevel) || data.isVertical) {
1350
+ if (Number(flags.substr(2,1))) {
1350
1351
  $nodeDiv.append('<i class="toggleBtn oci"></i>')
1351
1352
  .children('.title').prepend('<i class="oci '+ opts.parentNodeSymbol + ' symbol"></i>');
1352
1353
  }
1354
+ } else if (data.isHybrid) {
1355
+ if (Number(flags.substr(2,1))) {
1356
+ $nodeDiv.append('<i class="edge verticalEdge bottomEdge oci"></i>')
1357
+ .children('.title').prepend('<i class="oci '+ opts.parentNodeSymbol + ' symbol"></i>');
1358
+ }
1353
1359
  } else {
1354
1360
  if (Number(flags.substr(0,1))) {
1355
1361
  $nodeDiv.append('<i class="edge verticalEdge topEdge oci"></i>');
@@ -1396,25 +1402,20 @@
1396
1402
  }
1397
1403
  // Construct the node
1398
1404
  if (Object.keys(data).length > 2) {
1399
- var $nodeDiv = this.createNode(data);
1400
- if (opts.verticalLevel && level >= opts.verticalLevel) {
1401
- $appendTo.append($nodeDiv);
1402
- } else {
1403
- $appendTo.append($nodeDiv);
1404
- }
1405
+ $appendTo.append(this.createNode(data));
1405
1406
  }
1406
1407
  // Construct the "inferior nodes"
1407
1408
  if (data.children && data.children.length) {
1408
1409
  var isHidden = level + 1 > opts.visibleLevel || (data.collapsed !== undefined && data.collapsed);
1409
- var isVerticalLayer = opts.verticalLevel && (level + 1) >= opts.verticalLevel;
1410
1410
  var $nodesLayer;
1411
- if (isVerticalLayer) {
1411
+ if ((opts.verticalLevel && (level + 1) >= opts.verticalLevel) || data.isHybrid) {
1412
1412
  $nodesLayer = $('<ul class="nodes">');
1413
- if (isHidden && level + 1 >= opts.verticalLevel) {
1413
+ if (isHidden && (opts.verticalLevel && (level + 1) >= opts.verticalLevel)) {
1414
1414
  $nodesLayer.addClass('hidden');
1415
1415
  }
1416
- if (level + 1 === opts.verticalLevel) {
1417
- $appendTo.addClass('hybrid').append($nodesLayer.addClass('vertical'));
1416
+ if (((opts.verticalLevel && level + 1 === opts.verticalLevel) || data.isHybrid)
1417
+ && !$appendTo.closest('.vertical').length) {
1418
+ $appendTo.append($nodesLayer.addClass('vertical'));
1418
1419
  } else {
1419
1420
  $appendTo.append($nodesLayer);
1420
1421
  }
@@ -72,7 +72,7 @@ describe('orgchart -- integration tests', function () {
72
72
  });
73
73
 
74
74
  it('initialize chart with the given vertical level', function () {
75
- var fragment = '<li class="hierarchy hybrid"><div id="n1" class="node"><div class="title">' +
75
+ var fragment = '<li class="hierarchy"><div id="n1" class="node"><div class="title">' +
76
76
  '<i class="oci oci-leader symbol"></i>Lao Lao</div><i class="edge verticalEdge bottomEdge oci">' +
77
77
  '</i></div><ul class="nodes vertical"><li class="hierarchy"><div id="n2" data-parent="n1" class="node">' +
78
78
  '<div class="title">Bo Miao</div></div></li><li class="hierarchy"><div id="n3" data-parent="n1" class="node">' +
@@ -100,7 +100,7 @@ describe('orgchart -- integration tests', function () {
100
100
  };
101
101
 
102
102
  it('verticalLevel=2 and visibleLevel=1', function () {
103
- var fragment = '<div class="orgchart"><ul class="nodes"><li class="hierarchy hybrid">' +
103
+ var fragment = '<div class="orgchart"><ul class="nodes"><li class="hierarchy">' +
104
104
  '<div class="node"><div class="title"><i class="oci oci-leader symbol">' +
105
105
  '</i>Lao Lao</div><i class="edge verticalEdge bottomEdge oci"></i></div>' +
106
106
  '<ul class="nodes hidden vertical"><li class="hierarchy"><div class="node slide-up">' +
@@ -119,7 +119,7 @@ describe('orgchart -- integration tests', function () {
119
119
  });
120
120
 
121
121
  it('verticalLevel=2 and visibleLevel=2', function () {
122
- var fragment = '<div class="orgchart"><ul class="nodes"><li class="hierarchy hybrid">' +
122
+ var fragment = '<div class="orgchart"><ul class="nodes"><li class="hierarchy">' +
123
123
  '<div class="node"><div class="title"><i class="oci oci-leader symbol"></i>Lao Lao</div>' +
124
124
  '<i class="edge verticalEdge bottomEdge oci"></i></div><ul class="nodes vertical">' +
125
125
  '<li class="hierarchy"><div class="node"><div class="title">Bo Miao</div></div></li>' +
@@ -137,7 +137,7 @@ describe('orgchart -- integration tests', function () {
137
137
  });
138
138
 
139
139
  it('verticalLevel=2 and visibleLevel=3', function () {
140
- var fragment = '<div class="orgchart"><ul class="nodes"><li class="hierarchy hybrid">' +
140
+ var fragment = '<div class="orgchart"><ul class="nodes"><li class="hierarchy">' +
141
141
  '<div class="node"><div class="title"><i class="oci oci-leader symbol"></i>Lao Lao</div>' +
142
142
  '<i class="edge verticalEdge bottomEdge oci"></i></div><ul class="nodes vertical">' +
143
143
  '<li class="hierarchy"><div class="node"><div class="title">Bo Miao</div></div></li>' +