Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
F
flot
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
HS-public
flot
Commits
6a02cab9
Commit
6a02cab9
authored
Nov 22, 2012
by
David Schnur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleaned up tabs and whitespace.
parent
0945a1cb
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
333 additions
and
301 deletions
+333
-301
jquery.flot.time.js
jquery.flot.time.js
+333
-301
No files found.
jquery.flot.time.js
View file @
6a02cab9
...
...
@@ -4,20 +4,26 @@ Pretty handling of time axes.
Set axis.mode to "time" to enable. See the section "Time series data" in API.txt
for details.
*/
(
function
(
$
)
{
var
options
=
{};
// round to nearby lower multiple of base
function
floorInBase
(
n
,
base
)
{
return
base
*
Math
.
floor
(
n
/
base
);
}
// Returns a string with the date d formatted according to fmt.
// A subset of the Open Group's strftime format is supported.
function
formatDate
(
d
,
fmt
,
monthNames
,
dayNames
)
{
if
(
typeof
d
.
strftime
==
"function"
)
{
return
d
.
strftime
(
fmt
);
}
var
leftPad
=
function
(
n
,
pad
)
{
n
=
""
+
n
;
pad
=
""
+
(
pad
==
null
?
"0"
:
pad
);
...
...
@@ -28,12 +34,14 @@ for details.
var
escape
=
false
;
var
hours
=
d
.
getHours
();
var
isAM
=
hours
<
12
;
if
(
monthNames
==
null
)
monthNames
=
[
"Jan"
,
"Feb"
,
"Mar"
,
"Apr"
,
"May"
,
"Jun"
,
"Jul"
,
"Aug"
,
"Sep"
,
"Oct"
,
"Nov"
,
"Dec"
];
if
(
dayNames
==
null
)
dayNames
=
[
"Sun"
,
"Mon"
,
"Tue"
,
"Wed"
,
"Thu"
,
"Fri"
,
"Sat"
];
var
hours12
;
if
(
hours
>
12
)
{
hours12
=
hours
-
12
;
}
else
if
(
hours
==
0
)
{
...
...
@@ -43,6 +51,7 @@ for details.
}
for
(
var
i
=
0
;
i
<
fmt
.
length
;
++
i
)
{
var
c
=
fmt
.
charAt
(
i
);
if
(
escape
)
{
...
...
@@ -65,14 +74,14 @@ for details.
}
r
.
push
(
c
);
escape
=
false
;
}
else
{
}
else
{
if
(
c
==
"%"
)
escape
=
true
;
else
r
.
push
(
c
);
}
}
return
r
.
join
(
""
);
}
...
...
@@ -80,31 +89,41 @@ for details.
// zone the client happens to be in we need a date-like object independent
// of time zones. This is done through a wrapper that only calls the UTC
// versions of the accessor methods.
function
makeUtcWrapper
(
d
)
{
function
addProxyMethod
(
sourceObj
,
sourceMethod
,
targetObj
,
targetMethod
)
{
sourceObj
[
sourceMethod
]
=
function
()
{
return
targetObj
[
targetMethod
].
apply
(
targetObj
,
arguments
);
};
};
var
utc
=
{
date
:
d
};
// support strftime, if found
if
(
d
.
strftime
!=
undefined
)
addProxyMethod
(
utc
,
"strftime"
,
d
,
"strftime"
);
addProxyMethod
(
utc
,
"getTime"
,
d
,
"getTime"
);
addProxyMethod
(
utc
,
"setTime"
,
d
,
"setTime"
);
var
props
=
[
"Date"
,
"Day"
,
"FullYear"
,
"Hours"
,
"Milliseconds"
,
"Minutes"
,
"Month"
,
"Seconds"
];
for
(
var
p
=
0
;
p
<
props
.
length
;
p
++
)
{
addProxyMethod
(
utc
,
"get"
+
props
[
p
],
d
,
"getUTC"
+
props
[
p
]);
addProxyMethod
(
utc
,
"set"
+
props
[
p
],
d
,
"setUTC"
+
props
[
p
]);
}
return
utc
;
};
// select time zone strategy. This returns a date-like object tied to the
// desired timezone
function
dateGenerator
(
ts
,
opts
)
{
if
(
opts
.
timezone
==
"browser"
)
{
return
new
Date
(
ts
);
...
...
@@ -123,6 +142,7 @@ for details.
}
// map of app. size of time units in milliseconds
var
timeUnitSize
=
{
"second"
:
1000
,
"minute"
:
60
*
1000
,
...
...
@@ -134,6 +154,7 @@ for details.
// the allowed tick sizes, after 1 year we use
// an integer algorithm
var
spec
=
[
[
1
,
"second"
],
[
2
,
"second"
],
[
5
,
"second"
],
[
10
,
"second"
],
[
30
,
"second"
],
...
...
@@ -150,7 +171,9 @@ for details.
function
init
(
plot
)
{
plot
.
hooks
.
processDatapoints
.
push
(
function
(
plot
,
series
,
datapoints
)
{
$
.
each
(
plot
.
getAxes
(),
function
(
axisName
,
axis
)
{
var
opts
=
axis
.
options
;
if
(
opts
.
mode
==
"time"
)
{
axis
.
tickGenerator
=
function
(
axis
)
{
var
ticks
=
[],
...
...
@@ -169,13 +192,17 @@ for details.
+
spec
[
i
+
1
][
0
]
*
timeUnitSize
[
spec
[
i
+
1
][
1
]])
/
2
&&
spec
[
i
][
0
]
*
timeUnitSize
[
spec
[
i
][
1
]]
>=
minSize
)
break
;
var
size
=
spec
[
i
][
0
];
var
unit
=
spec
[
i
][
1
];
// special-case the possibility of several years
if
(
unit
==
"year"
)
{
// if given a minTickSize in years, just use it,
// ensuring that it's an integer
if
(
opts
.
minTickSize
!=
null
&&
opts
.
minTickSize
[
1
]
==
"year"
)
{
size
=
Math
.
floor
(
opts
.
minTickSize
[
0
]);
}
else
{
...
...
@@ -216,7 +243,9 @@ for details.
d
.
setFullYear
(
floorInBase
(
d
.
getFullYear
(),
tickSize
));
// reset smaller components
d
.
setMilliseconds
(
0
);
if
(
step
>=
timeUnitSize
.
minute
)
d
.
setSeconds
(
0
);
if
(
step
>=
timeUnitSize
.
hour
)
...
...
@@ -228,8 +257,8 @@ for details.
if
(
step
>=
timeUnitSize
.
year
)
d
.
setMonth
(
0
);
var
carry
=
0
,
v
=
Number
.
NaN
,
prev
;
do
{
prev
=
v
;
v
=
d
.
getTime
();
...
...
@@ -273,6 +302,7 @@ for details.
var
hourCode
=
(
opts
.
twelveHourClock
)
?
"%I"
:
"%H"
;
var
fmt
;
if
(
t
<
timeUnitSize
.
minute
)
fmt
=
hourCode
+
":%M:%S"
+
suffix
;
else
if
(
t
<
timeUnitSize
.
day
)
{
...
...
@@ -293,6 +323,7 @@ for details.
fmt
=
"%Y"
;
var
rt
=
formatDate
(
d
,
fmt
,
opts
.
monthNames
,
opts
.
dayNames
);
return
rt
;
};
}
...
...
@@ -306,4 +337,5 @@ for details.
name
:
'time'
,
version
:
'1.0'
});
})(
jQuery
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment