📄 timeline.js
字号:
item._min=false;
// caculate left and width
item._left = self._getX(profile, item.from);
item._width=Math.max(self._getX(profile, item.to) - item._left, 0);
if(t.multiTasks){
if(item._width<=16){
item._width=16;
item._min=true;
}
}
item._minDisplay=item._min?'':'display:none';
item._normalDisplay=item._min?'display:none':'';
// caculate top and set task to lines cache
index = self._getLinePos(profile, item);
//min region is alway 16 + 3
item._top = t.multiTasks? 'top:' + (item._min?0:((t.taskHeight+3) * (index-1) + 16 + 3)) + 'px' : '';
item._height = 'height:' + (t.multiTasks?item._min?'16px':t.taskHeight+'px':'100%');
item._border = t.multiTasks?'':'border-top:0;border-bottom:0';
item._background = item.background?'background:'+item.background+';':'';
t._lines = t._lines || [{}];
//set double link
t._lines[index][item.id]=item;
item._line = index;
oitem._left=item._left;
oitem._width=item._width;
oitem._min=item._min;
oitem._line=item._line;
},
$zoom:[
/*
*[
* id,
* small span unit count,
* small span unit,
* small span to big span function,
* small span lable format,
* big span lable format,
* value format
*]
*/
['10 ms', 54, 10, 'ms', 'ms', 100, 'ms','hnsms','hnsms'],
['100 ms',54, 100, 'ms', 'ms', 1, 's','hns','hnsms'],
['1 s',30, 1, 's','s', 10, 's','hns','hnsms'],
['10 s', 30, 10, 's', 's',60, 's','hns','hnsms'],
['1 n',30, 1, 'n','n', 10, 'n','dhn','hns'],
['5 n', 30, 5, 'n','n', 30, 'n','mdhn','hns'],
['10 n', 30, 10, 'n','n', 60, 'n','mdhn','hns'],
['30 n', 30, 30, 'n','n', 4, 'h','ymdh','mdhn'],
['1 h', 30, 1, 'h','h', 6, 'h','ymdh','mdhn'],
['2 h', 30, 2, 'h','h', 12, 'h','ymdh','mdhn'],
['6 h', 30, 6, 'h','h', 24, 'h','ymd','mdhn'],
['1 d', 24, 1, 'd','w', 1, 'ww','ymd','ymdh'],
['1 w', 30, 1, 'ww','ww', 4, 'ww','ymd','ymd'],
['15 d', 30, 15, 'd','d', 2, 'm','ymd','ymd'],
//Not every unit width is the same value:
['1 m', 30,1, 'm','m', 1, 'q','yq','ymd'],
['1 q', 30,1, 'q','q', 1, 'y','y','ymd'],
['1 y', 48,1, 'y','y', 10, 'y','y','ym'],
['1 de', 48, 1, 'de','de', 100, 'y','y','ym'],
['1 c', 48, 1, 'c', 'c', 1000, 'y','y','y']
],
_focus:function(profile){
profile.getSubNode('FOCUS').focus(1);
},
_getTips:function(profile){
var t,s='$dd_tooltip';
if(t = profile[s] || (profile[s] = profile.getSubNode('TIPS').get(0).childNodes[0]))
return t.nodeValue;
else
return profile.getSubNode('TIPS').get(0).innerHTML;
},
_rr:/\<[^>]*\>/g,
_setTips:function(profile, text, force){
if(!force && profile.pauseA)return;
var t,s='$dd_tooltip';
text=text.replace(this._rr,'');
if(t = profile[s] || (profile[s] = profile.getSubNode('TIPS').get(0).childNodes[0])){
if(t.nodeValue!=text)t.nodeValue=text;
}else
profile.getSubNode('TIPS').get(0).innerHTML=text;
},
_getX:function(profile, time){
var t=profile.properties,d=new Date;
d.setTime(time);
return (Math.ceil(linb.Date.diff(t._smallLabelStart, d, 'ms')||0) / t._rate);
},
_getTime:function(profile, x, flag){
var t=profile.properties;
t = linb.Date.add(t._smallLabelStart, 'ms', x*t._rate);
return flag?t:t.getTime();
},
_moveActive:function(profile, src, x, w){
var p=Math.ceil,
t=profile.properties,
d=linb.Date,
s=t._smallLabelStart,
r=t._rate,
u=t._timeFormat,
ms='ms',
y=src.style,
z='px',
m,n,increment;
if(increment=t.increment){
m=x;
x=Math.floor(x/increment)*increment;
w=Math.floor((w-x+m+increment-1)/increment)*increment;
}
m = (p(x)||0);
n = ((p(w)||0)-2);
if(n>0){
y.left= m+z;
y.width= n+z;
if(t.showTips)
profile.box._setTips(profile, d.getText(d.add(s, ms, x*r),u)
+ " - "
+ d.getText(d.add(s, ms, (x+w)*r),u)
)
}
},
_deActive:function(profile){
var t=profile.$active.style, x=parseInt(t.left)||0, w=(parseInt(t.width)||0)+2;
t.left='-1000px';
if(profile.properties.showTips)
profile.box._setTips(profile, '');
return {left :x, width :w};
},
_minusLeft:function(profile,marks,node,offsetCount){
var t=profile.properties;
while((offsetCount--)>0){
node.first().remove();
temp=marks.shift();
}
},
_minusRight:function(profile,marks,node,offsetCount){
var t=profile.properties;
while((offsetCount--)>0){
node.last().remove();
temp=marks.pop();
}
},
_addLeft:function(profile, tag, node, offsetCount, offset){
// get additional bars
var t=profile.properties,
date=linb.Date,
key=tag+'Marks',
marks=t[key],
labelStart=t[tag+'LabelStart'],
labelUnit=t[tag+'LabelUnit'],
labelCount=t[tag+'LabelCount'],
labelFormat=t[tag+'LabelFormat'],
rate=t._rate,
addLb=[],
temp,label,_date,i;
temp=0;
label=date.getText(labelStart, labelFormat);
for(i=0; i< offsetCount; i++){
_date = date.add(labelStart, labelUnit, labelCount*(i+1));
width = date.diff(labelStart, _date, 'ms')/rate;
addLb.push({
left : Math.ceil(temp + (offset||0)-0.0000000000003),
width : Math.ceil(width - temp),
text : label
});
temp=width;
label=date.getText(_date, labelFormat);
}
addLb.reverse();
// add to band UI
node.prepend(_.str.toDom(profile.buildItems(key, addLb)));
// add to memory list
_.arr.insertAny(marks,addLb.reverse(),0);
},
_addRight:function(profile, labelEnd, tag, node, offsetCount, offset){
var t=profile.properties,
date=linb.Date,
key=tag+'Marks',
marks=t[key],
labelStart=t[tag+'LabelStart'],
labelUnit=t[tag+'LabelUnit'],
labelCount=t[tag+'LabelCount'],
labelFormat=t[tag+'LabelFormat'],
rate=t._rate,
addLb=[],_d1,
_date,i;
_d1=labelEnd;
for(i=0; i<offsetCount; i++){
_date = date.add(labelEnd, labelUnit, labelCount*(i+1));
addLb.push({
left : Math.ceil(date.diff(labelStart,_d1,'ms')/rate+ (offset||0)-0.0000000000003),
width : Math.ceil(date.diff(_d1, _date, 'ms')/rate),
text : date.getText(_d1, labelFormat)
});
_d1=_date;
}
// build
// add to band UI
node.append(_.str.toDom(profile.buildItems(key, addLb)));
// add to memory list
_.arr.insertAny(marks,addLb,-1);
},
_getMoveNodes:function(profile){
return profile.$moveban = profile.$moveban || profile.getSubNodes(['BAND','ITEMS']);
},
//if left is numb, force to move
_rePosition:function(profile, left){
profile.pause=true;
var self=this,
date = linb.Date,
t=profile.properties,
rate=t._rate,
label,m,n,
labelsBottom = profile.getSubNode('SMALLLABEL'),
band = self._getMoveNodes(profile),
x = left || band.left(),
//ralated to the fix position
offset = x - t._band_left_fix;
// if offset out a bar width
if(Math.abs(offset)/t._unitPixs >=1 || left){
var offsetCount = parseInt(offset/t._unitPixs),
bak_s = t._smallLabelStart,
bak_e = t._smallLabelEnd,
_c=-offsetCount*t._smallLabelCount,
offsetPxs,
_smallLabelStart,
_smallLabelEnd;
_smallLabelStart=t._smallLabelStart = date.add(t._smallLabelStart, t._smallLabelUnit, _c);
_smallLabelEnd=t._smallLabelEnd = date.add(t._smallLabelEnd, t._smallLabelUnit, _c);
offsetPxs = Math.ceil(date.diff(_smallLabelStart, bak_s, 'ms')/rate);
band.left(x - offsetPxs);
// reset band paras
t._band_width = Math.ceil(date.diff(_smallLabelStart, _smallLabelEnd, 'ms')/rate);
//reset tasks position var
_.arr.each(t.items,function(o){
o._left += offsetPxs;
profile.box._trimTask(profile,o);
});
labelsBottom.children().each(function(o){
o.style.left = (parseFloat(o.style.left)||0) + offsetPxs + "px";
});
_.arr.each(t._smallMarks,function(o){
o.left += offsetPxs;
});
// delete out, andd add to blank
if(offsetCount>0){
self._minusRight(profile,t._smallMarks, labelsBottom,offsetCount);
self._addLeft(profile, '_small', labelsBottom, offsetCount);
}else{
self._minusLeft(profile,t._smallMarks, labelsBottom, -offsetCount);
self._addRight(profile, bak_e, '_small', labelsBottom, -offsetCount);
}
if(t.multiTasks){
var arr=[];
// remove tasks
_.arr.each(t.items,function(o){
if(o._left >= t._band_width || (o._left+o._width) <= 0){
//delete from lines
delete t._lines[o._line][o.id];
arr.push(o.id);
}
});
profile.boxing().removeItems(arr);
if(profile.onGetContent)
profile.boxing()._getContent(offsetCount>0 ? _smallLabelStart : bak_e,
offsetCount>0 ? bak_s : _smallLabelEnd,
t._rate,
offsetCount>0 ? 'left' : 'right');
//adjust the items
self._reArrage(profile);
}
if(t.showBigLabel){
var labelsTop = profile.getSubNode('BIGLABEL'),
bigLabelUnit=t._bigLabelUnit,
bigLabelCount=t._bigLabelCount,
off,
offsetCount2,offsetCount3,
bigLabelStart,bigLabelEnd;
bak_e=t._bigLabelEnd;
labelsTop.children().each(function(o){
o.style.left = (parseFloat(o.style.left)||0) + offsetPxs + "px";
});
_.arr.each(t._bigMarks,function(o){
o.left += offsetPxs;
});
bigLabelStart=date.getTimSpanStart(_smallLabelStart, bigLabelUnit, bigLabelCount);
offsetCount2 = Math.ceil(date.diff(_smallLabelStart, t._bigLabelStart, bigLabelUnit)/bigLabelCount);
offsetCount3 = Math.ceil(date.diff(t._bigLabelEnd, _smallLabelEnd, bigLabelUnit)/bigLabelCount);
//reset offset of big and small
if(offsetCount2){
off = date.diff(_smallLabelStart, bigLabelStart, 'ms')/rate;
t._bigLabelStart=bigLabelStart;
if(offsetCount2>0)
self._addLeft(profile, '_big',labelsTop, offsetCount2, off);
else
self._minusLeft(profile,t._bigMarks, labelsTop, -offsetCount2);
}
//reset offset of big and small
if(offsetCount3){
off = date.diff(_smallLabelStart, bigLabelStart, 'ms')/rate;
t._bigLabelEnd
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -