-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.js
134 lines (116 loc) · 2.73 KB
/
tools.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//in this constructor, paracite inherits Date and adds
//datetostring -type method of the form dd.mm.yyyy (string)
//and date2picker of the form yyyy-mm-dd, compatible with datepicker input
function date(date){
if(date==undefined){date=Date.now()};
var newdate=new Date(date)
//if(
//newdate.getHours() ==0 &&
newdate.setMinutes(0)//==0 &&
newdate.setSeconds(0)//==0 &&
newdate.setMilliseconds(0)//==0){
newdate.setHours(3);
//}
newdate.date2str=function(){
return this.getDate().toString()+"."+(this.getMonth()+1).toString()
+"."+this.getFullYear().toString();
}
newdate.date2pltstr=function(){
return this.getFullYear().toString()+"-"+(this.getMonth()+1).toString()
+"-"+this.getDate().toString();
}
newdate.date2picker=function(){
return (0+this.getFullYear().toString()).slice(-4)+"-"+(0+(this.getMonth()+1).toString()).slice(-2)
+"-"+(0+this.getDate().toString()).slice(-2);
}
newdate.floor=function(){
this.setHours(0);
this.setMinutes(0);
this.setSeconds(0);
this.setMilliseconds(0);
return this;
}
newdate.ceil=function(){
if(this.getHours()!=0 || this.getMinutes()!=0 ||
this.getSeconds()!=0 || this.getMilliseconds()!=0){
this.floor();
this.setDate(this.getDate()+1);
}
return this;
}
return newdate;
}
function linspace(a,b){
linsp=[];
if(a%1==0 && b%1==0){
a=parseInt(a);
b=parseInt(b);
if(a>b){
var tmp =a;
a=b;
b=tmp;
}
for (i=a;i<=b;i++){
linsp.push(i);
}
return linsp;
}else{
return -1;
}
}
function linspaceofdays(dt1,dt2){
if(dt1>dt2){
var tmp = dt2;
dt2=dt1;
dt1=tmp;
}
var args=Math.round((dt2-dt1)/days);
var linsp=linspace(0,args);
linsp=linsp.map(
function(i){
return new date(dt2-i*days);
}
);
return linsp;
}
function sum(array){
var sum=0;
for(i of array){
sum=sum+i;
}
return sum;
}
function matrix2csvstr(matrix){
str="";
for (i of matrix){
for (j of i){
str=str.concat(j+",");
}
str=str.slice(0,-1);
str=str.concat("\n");
}
str=str.slice(0,-1);
return strbreak(str);
}
var days=1000*60*60*24;
var dayspermonth = 365/12;
function drag_start(event)
{
var style = window.getComputedStyle(event.target, null);
var str = (parseInt(style.getPropertyValue("left")) - event.clientX) + ',' + (parseInt(style.getPropertyValue("top")) - event.clientY)+ ',' + event.target.id;
event.dataTransfer.setData("Text",str);
}
function drop(event)
{
var offset = event.dataTransfer.getData("Text").split(',');
var dm = document.getElementById(offset[2]);
dm.style.left = (event.clientX + parseInt(offset[0],10)) + 'px';
dm.style.top = (event.clientY + parseInt(offset[1],10)) + 'px';
event.preventDefault();
return false;
}
function drag_over(event)
{
event.preventDefault();
return false;
}