Skip to content

Commit fde3dfb

Browse files
committed
add horional mode
1 parent 7699f55 commit fde3dfb

4 files changed

Lines changed: 176 additions & 18 deletions

File tree

‎lencharts/css/orgtree.css‎

Lines changed: 68 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
list-style-type:none;
1717
margin:0;
1818
padding:10px 5px 0 5px;
19-
position:relative
19+
position:relative;
2020
}
2121
.tree li::before, .tree li::after {
2222
content:'';
@@ -38,6 +38,21 @@
3838
top:30px;
3939
width:25px
4040
}
41+
42+
/* 横向 */
43+
.horizonal{
44+
padding-top:40px;
45+
position: relative;
46+
}
47+
.horizonal>li{
48+
display: inline-block;
49+
vertical-align: top;
50+
padding-top:0;
51+
}
52+
.horizonal>li::after,.horizonal>li::before{
53+
border: none;
54+
}
55+
4156
.tree li span {
4257
/* -moz-border-radius:5px;
4358
-webkit-border-radius:5px;
@@ -107,13 +122,35 @@ body{
107122
display: block;
108123
border-left: 1px solid #a9a9a9;
109124
height: 20px;
110-
111125
position: absolute;
112126
top:calc(100% + 3px);
113127
left:50%;
114128
z-index: 0;
115129

116130
}
131+
.horizonal>li>.content{
132+
margin-bottom: 20px;
133+
position: relative;
134+
}
135+
.horizonal>li:not(.noneChild):not(.oneChild1)>.content::after{
136+
content: '';
137+
display: block;
138+
border-left: 1px solid #a9a9a9;
139+
height: 20px;
140+
position: absolute;
141+
top:calc(100% + 3px);
142+
left:50%;
143+
z-index: 10;
144+
}
145+
.vertical li .content::after{
146+
content: '';
147+
border:none;
148+
}
149+
.vertical{
150+
z-index: 11;
151+
background: #fff;
152+
position: relative;
153+
}
117154
/*第二层*/
118155
.level2s{
119156
position: relative;
@@ -130,20 +167,43 @@ body{
130167
position: relative;
131168
background: #fff;
132169
}
170+
ul>.divider{
171+
position: absolute;
172+
top:20px;
173+
}
174+
/* 只有一个子元素 */
175+
176+
.horizonal.onChild,.oneChild1>.horizonal{
177+
padding-top:20px!important;
178+
}
179+
.horizonal.onChild .divider,.oneChild1>.horizonal .divider{
180+
display: none;
181+
}
182+
/* 没有子元素 */
183+
.horizonal.noneChild .divider{
184+
display: none;
185+
}
186+
133187
.level2s .level2{
134188
display: inline-block;
135189
position:absolute ;
136190
list-style: none;
137191
}
138-
.level2s .level2 .content{
192+
.orgWrap .content{
193+
border: 2px solid #a9a9a9;
194+
position: relative;
195+
margin:0;
196+
}
197+
.horizonal>li>.content{
139198
/* width: 170px; */
140199
border: 2px solid #a9a9a9;
141200
position: relative;
201+
margin: 0 auto;
142202
}
143203
.level2s .level2.noneChild{
144204
padding-right: 40px;
145205
}
146-
.level2s .level2>.content::before{
206+
.horizonal>li>.content::before{
147207
content: '';
148208
display: block;
149209
position: absolute;
@@ -153,7 +213,7 @@ body{
153213
top:-22px;
154214
z-index:2;
155215
}
156-
.level2s .level2:first-child .content::before, .level2s .level2:last-child .content::before{
216+
.horizonal>li:first-of-type>.content::before, .horizonal>li:last-child>.content::before{
157217
content: '';
158218
border-left: none;
159219
}
@@ -163,6 +223,9 @@ body{
163223
padding: 0;
164224
background: #fff;
165225
}
226+
.hashorizonal .tree{
227+
padding-top:40px;
228+
}
166229
/* .tree span{
167230
width: 250px;
168231
height: 100px;

‎lencharts/examples/index.html‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80283,6 +80283,7 @@
8028380283
data:obj,
8028480284
drag:true,
8028580285
depth:depth,
80286+
hlevel:3, //水平放置的层级>2
8028680287
renderdata:function(data,$dom){
8028780288
var value = data.data;
8028880289
if (value && Object.keys(value).length) {

‎lencharts/index.html‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,40 @@
192192
]
193193
},
194194
]
195+
},
196+
{
197+
id: 001,
198+
data: {
199+
name: '特区建发',
200+
plait: 20,
201+
onduty: 10,
202+
type: "organization"
203+
},
204+
children: [
205+
{
206+
id: 001,
207+
data: {
208+
name: '特区建发',
209+
plait: 20,
210+
onduty: 10,
211+
type: "organization"
212+
},
213+
children: [
214+
215+
]
216+
}, {
217+
id: 001,
218+
data: {
219+
name: '特区建发',
220+
plait: 20,
221+
onduty: 10,
222+
type: "organization"
223+
},
224+
children: [
225+
226+
]
227+
},
228+
]
195229
}
196230
]
197231
},
@@ -218,12 +252,25 @@
218252
},
219253
]
220254
},
255+
{
256+
id: 001,
257+
data: {
258+
name: '特区建发',
259+
plait: 20,
260+
onduty: 10,
261+
type: "organization"
262+
},
263+
children: [
264+
265+
]
266+
},
221267
]
222268
}
223269

224270
$('.orgWrap').lenChart({
225271
data:obj,
226272
drag:true,
273+
hlevel:3, //水平放置的层级>2
227274
renderdata:function(data,$dom){
228275
var value = data.data;
229276
if (value && Object.keys(value).length) {

‎lencharts/js/jquery.lenchart.js‎

Lines changed: 60 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
var defaults = {};
55
var opts = $.extend({}, defaults, options);
66
var obj = opts.data;
7-
self = this;
7+
self = this;
8+
if(opts.hlevel&&opts.hlevel>=3){
9+
self.addClass('hashorizonal')
10+
}
811
if(obj&&Object.keys(obj).length>0){
9-
var level1s = '<div class="level1s"><div class="level1"><div class="content"></div></div></div>';
12+
var level1s = '<div class="level1s" data-level="1"><div class="level1"><div class="content"></div></div></div>';
1013
var $level1s = $(level1s);
1114
var devider = '<div class="divider"></div>';
1215
var $devider = $(devider);
13-
var level2s = '<ul class="level2s"></ul>';
16+
var level2s = '<ul class="level2s" data-level="2"></ul>';
1417
var $level2s = $(level2s);
1518
this.attr('id', '')
1619
if (obj.data && opts.renderdata) {
@@ -24,6 +27,9 @@
2427
addIcon($level1s, false, 1);
2528
}
2629
}
30+
if(opts.hlevel&&opts.hlevel>=3){
31+
$level2s.addClass('horizonal')
32+
}
2733
this.append($level1s);
2834
this.append($devider);
2935

@@ -61,15 +67,33 @@
6167
var levels = 'level' + loopIndex + 's';
6268
var level = 'level' + loopIndex;
6369

64-
var level3s = '<ul class="level' + loopIndex + 's"></ul>';
70+
var level3s = '<ul class="level' + loopIndex + 's" data-level="'+loopIndex+'"></ul>';
6571
var level3 = '<li class="level' + loopIndex + '" data-level=""><div class="content"></div></li>';
6672
var $level3s = $(level3s);
6773
var $level3 = $(level3);
6874
$level3.attr('data-level', loopIndex);
6975
if (loopIndex == 3) {
7076
$level3s.addClass('tree')
7177
}
78+
//水平放置
79+
if(opts.hlevel&&opts.hlevel>=loopIndex){
80+
$level3s.addClass('horizonal');
81+
$level3s.append($devider.clone());
82+
}else{
83+
$level3s.addClass('vertical');
84+
}
85+
// if(opts.hlevel&&opts.hlevel>=(loopIndex + 1)){
86+
// $level3.addClass('horizonalwrap');
87+
// }else{
88+
// $level3.addClass('verticalwrap');
89+
// }
7290
if (obj.children.length) {
91+
if(obj.children.length===1){
92+
$level3s.addClass('onChild');
93+
}
94+
if(obj.children.length===2){
95+
$level3s.addClass('twoChild');
96+
}
7397
$.each(obj.children, function (item, value) {
7498
var $level3 = $(level3);/*错*/
7599
if (value.data && opts.renderdata) {
@@ -94,6 +118,8 @@
94118
renderLevel3(value, $level3, $level3s, loopIndex + 1);
95119
});
96120

121+
}else{
122+
$level3s.addClass('noneChild');
97123
}
98124

99125
$level.append($level3s);
@@ -126,12 +152,15 @@
126152
}else{
127153
$icon.on('click', function (e) {
128154
var children = $(this).closest('li.parent_li').find(' > ul > li');
155+
$(this).closest('li.parent_li').addClass('oneChild1');
156+
129157
if (children.is(":visible")) {
130158
children.hide('fast', function () {
131159
avoid();
132160
});
133161
$(this).attr('title', 'Expand this branch').addClass('glyphicon-plus-sign').removeClass('glyphicon-minus-sign');
134162
} else {
163+
$(this).closest('li.parent_li').removeClass('oneChild1');
135164
children.show('fast', function () {
136165
avoid();
137166
});
@@ -145,7 +174,9 @@
145174
}
146175
// 加减按钮点击事件
147176
$('.orgWrap li:has(ul>li)').addClass('parent_li').find(' > span').attr('title', 'Collapse this branch');
177+
148178
avoid();
179+
149180
if (opts.drag) {
150181
drag(this)
151182
}
@@ -156,8 +187,8 @@
156187
}//$.fn结束
157188

158189
/*防止第二层折行*/
159-
function avoid() {
160-
var $level2 = $('.level2s').children('.level2');
190+
function avoidinner($wrap,flag,level) {
191+
var $level2 = $wrap.children('li');
161192
var _width = parseInt($level2.width());
162193
var maxHeight = $level2.height();
163194
var allWidth = 0;/*累加第二层宽度*/
@@ -171,7 +202,7 @@
171202
}
172203

173204
$level2.each(function () {
174-
if (!$(this).find('li.level3').size()) {
205+
if (!$(this).children('ul').children('li').size()) {
175206
$(this).addClass('noneChild')
176207
}
177208

@@ -191,15 +222,31 @@
191222
/*为没有子节点的第二层添加右padding*/
192223

193224
/**/
194-
var lastlevel2 = $('.level2:last-child');
225+
var classname = ".level"+level;
226+
var lastlevel2 = $wrap.children(classname).eq($wrap.children(classname).length-1);
227+
var firstlevel2 = $wrap.children(classname).eq(0);
195228
var lastWidth = parseInt(lastlevel2.css('width'));
229+
var firstWidth = parseInt(firstlevel2.css('width'));
196230

197-
$('.divider').css('width', allWidth - lastWidth);
198-
$('.divider').css('left', parseInt($level2.find('.content').css('width')) / 2);
231+
var $devider = null;
232+
if(flag) {
233+
$devider = $wrap.parent().children('.divider');
234+
self.css('width', allWidth + 200);
235+
self.css('margin-left', -allWidth / 2 - 100);
236+
}else{
237+
$devider = $wrap.children('.divider');
238+
}
239+
$devider.css('width', allWidth - lastWidth/2 - firstWidth/2);
240+
$devider.css('left', parseInt($level2.css('width')) / 2);
199241
/*防止第二层折行*/
200-
$('.level2s').css('width', allWidth + 200);
201-
self.css('width', allWidth + 200);
202-
self.css('margin-left', -allWidth / 2 - 100);
242+
// $('.level2s').css('width', allWidth + 200);
243+
244+
}
245+
function avoid(){
246+
avoidinner($('.level2s'),true,2)
247+
$('.horizonal').each(function(index,horizonal){
248+
avoidinner($(horizonal),false,$(horizonal).attr('data-level'));
249+
})
203250
}
204251
//拖拽
205252
/*网页拖拽*/

0 commit comments

Comments
 (0)