Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
c3-closed
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Evgeny
c3-closed
Commits
c3855df1
You need to sign in or sign up before continuing.
Commit
c3855df1
authored
Feb 10, 2015
by
Masayuki Tanaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix parseDate to handle string correctly - #943
parent
d35f0f8b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
76 additions
and
74 deletions
+76
-74
c3.js
c3.js
+2
-2
c3.min.js
c3.min.js
+0
-0
data-spec.js
spec/data-spec.js
+72
-70
core.js
src/core.js
+2
-2
No files found.
c3.js
View file @
c3855df1
...
@@ -946,10 +946,10 @@
...
@@ -946,10 +946,10 @@
var
$$
=
this
,
parsedDate
;
var
$$
=
this
,
parsedDate
;
if
(
date
instanceof
Date
)
{
if
(
date
instanceof
Date
)
{
parsedDate
=
date
;
parsedDate
=
date
;
}
else
if
(
typeof
date
===
'string'
)
{
parsedDate
=
$$
.
dataTimeFormat
(
$$
.
config
.
data_xFormat
).
parse
(
date
);
}
else
if
(
typeof
date
===
'number'
||
!
isNaN
(
date
))
{
}
else
if
(
typeof
date
===
'number'
||
!
isNaN
(
date
))
{
parsedDate
=
new
Date
(
+
date
);
parsedDate
=
new
Date
(
+
date
);
}
else
{
parsedDate
=
$$
.
dataTimeFormat
(
$$
.
config
.
data_xFormat
).
parse
(
date
);
}
}
if
(
!
parsedDate
||
isNaN
(
+
parsedDate
))
{
if
(
!
parsedDate
||
isNaN
(
+
parsedDate
))
{
window
.
console
.
error
(
"Failed to parse x '"
+
date
+
"' to Date object"
);
window
.
console
.
error
(
"Failed to parse x '"
+
date
+
"' to Date object"
);
...
...
c3.min.js
View file @
c3855df1
This source diff could not be displayed because it is too large. You can
view the blob
instead.
spec/data-spec.js
View file @
c3855df1
...
@@ -50,39 +50,82 @@ describe('c3 chart data', function () {
...
@@ -50,39 +50,82 @@ describe('c3 chart data', function () {
});
});
describe
(
'timeseries x'
,
function
()
{
describe
(
'timeseries x'
,
function
()
{
it
(
'should load timeseries data successfully'
,
function
()
{
describe
(
'without xFormat'
,
function
()
{
args
=
{
data
:
{
it
(
'should load timeseries data successfully'
,
function
()
{
x
:
'date'
,
args
=
{
columns
:
[
data
:
{
[
'date'
,
'2013-01-01'
,
'2013-01-02'
,
'2013-01-03'
],
x
:
'date'
,
[
'data1'
,
30
,
200
,
100
],
columns
:
[
[
'data2'
,
130
,
300
,
200
]
[
'date'
,
'2013-01-01'
,
'2013-01-02'
,
'2013-01-03'
],
]
[
'data1'
,
30
,
200
,
100
],
},
[
'data2'
,
130
,
300
,
200
]
axis
:
{
]
x
:
{
},
type
:
'timeseries'
axis
:
{
x
:
{
type
:
'timeseries'
}
}
}
}
};
};
expect
(
true
).
toBeTruthy
();
expect
(
true
).
toBeTruthy
();
});
});
it
(
'should have correct number of xs'
,
function
()
{
it
(
'should have correct number of xs'
,
function
()
{
expect
(
Object
.
keys
(
chart
.
internal
.
data
.
xs
).
length
).
toBe
(
2
);
expect
(
Object
.
keys
(
chart
.
internal
.
data
.
xs
).
length
).
toBe
(
2
);
expect
(
chart
.
internal
.
data
.
xs
.
data1
.
length
).
toBe
(
3
);
expect
(
chart
.
internal
.
data
.
xs
.
data1
.
length
).
toBe
(
3
);
expect
(
chart
.
internal
.
data
.
xs
.
data2
.
length
).
toBe
(
3
);
expect
(
chart
.
internal
.
data
.
xs
.
data2
.
length
).
toBe
(
3
);
});
it
(
'should have Date object as x'
,
function
()
{
var
xs
=
chart
.
internal
.
data
.
xs
;
expect
(
+
xs
.
data1
[
0
]).
toBe
(
+
new
Date
(
2013
,
0
,
1
,
0
,
0
,
0
));
expect
(
+
xs
.
data1
[
1
]).
toBe
(
+
new
Date
(
2013
,
0
,
2
,
0
,
0
,
0
));
expect
(
+
xs
.
data1
[
2
]).
toBe
(
+
new
Date
(
2013
,
0
,
3
,
0
,
0
,
0
));
expect
(
+
xs
.
data2
[
0
]).
toBe
(
+
new
Date
(
2013
,
0
,
1
,
0
,
0
,
0
));
expect
(
+
xs
.
data2
[
1
]).
toBe
(
+
new
Date
(
2013
,
0
,
2
,
0
,
0
,
0
));
expect
(
+
xs
.
data2
[
2
]).
toBe
(
+
new
Date
(
2013
,
0
,
3
,
0
,
0
,
0
));
});
});
});
it
(
'should have Date object as x'
,
function
()
{
describe
(
'with xFormat'
,
function
()
{
var
xs
=
chart
.
internal
.
data
.
xs
;
describe
(
'timeseries x with xFormat'
,
function
()
{
expect
(
+
xs
.
data1
[
0
]).
toBe
(
+
new
Date
(
2013
,
0
,
1
,
0
,
0
,
0
));
it
(
'should load timeseries data successfully'
,
function
()
{
expect
(
+
xs
.
data1
[
1
]).
toBe
(
+
new
Date
(
2013
,
0
,
2
,
0
,
0
,
0
));
args
=
{
expect
(
+
xs
.
data1
[
2
]).
toBe
(
+
new
Date
(
2013
,
0
,
3
,
0
,
0
,
0
));
data
:
{
expect
(
+
xs
.
data2
[
0
]).
toBe
(
+
new
Date
(
2013
,
0
,
1
,
0
,
0
,
0
));
x
:
'date'
,
expect
(
+
xs
.
data2
[
1
]).
toBe
(
+
new
Date
(
2013
,
0
,
2
,
0
,
0
,
0
));
xFormat
:
'%Y%m%d'
,
expect
(
+
xs
.
data2
[
2
]).
toBe
(
+
new
Date
(
2013
,
0
,
3
,
0
,
0
,
0
));
columns
:
[
[
'date'
,
'20130101'
,
'20130102'
,
'20130103'
],
[
'data1'
,
30
,
200
,
100
],
[
'data2'
,
130
,
300
,
200
]
]
},
axis
:
{
x
:
{
type
:
'timeseries'
}
}
};
expect
(
true
).
toBeTruthy
();
});
it
(
'should have correct number of xs'
,
function
()
{
expect
(
Object
.
keys
(
chart
.
internal
.
data
.
xs
).
length
).
toBe
(
2
);
expect
(
chart
.
internal
.
data
.
xs
.
data1
.
length
).
toBe
(
3
);
expect
(
chart
.
internal
.
data
.
xs
.
data2
.
length
).
toBe
(
3
);
});
it
(
'should have Date object as x'
,
function
()
{
var
xs
=
chart
.
internal
.
data
.
xs
;
expect
(
+
xs
.
data1
[
0
]).
toBe
(
+
new
Date
(
2013
,
0
,
1
,
0
,
0
,
0
));
expect
(
+
xs
.
data1
[
1
]).
toBe
(
+
new
Date
(
2013
,
0
,
2
,
0
,
0
,
0
));
expect
(
+
xs
.
data1
[
2
]).
toBe
(
+
new
Date
(
2013
,
0
,
3
,
0
,
0
,
0
));
expect
(
+
xs
.
data2
[
0
]).
toBe
(
+
new
Date
(
2013
,
0
,
1
,
0
,
0
,
0
));
expect
(
+
xs
.
data2
[
1
]).
toBe
(
+
new
Date
(
2013
,
0
,
2
,
0
,
0
,
0
));
expect
(
+
xs
.
data2
[
2
]).
toBe
(
+
new
Date
(
2013
,
0
,
3
,
0
,
0
,
0
));
});
});
});
});
});
});
...
@@ -176,47 +219,6 @@ describe('c3 chart data', function () {
...
@@ -176,47 +219,6 @@ describe('c3 chart data', function () {
});
});
});
});
describe
(
'as unixtime string'
,
function
()
{
it
(
'should upate args'
,
function
()
{
args
=
{
data
:
{
x
:
'date'
,
columns
:
[
[
'date'
,
"1417622461123"
,
"1417622522345"
],
[
'data1'
,
30
,
200
],
[
'data2'
,
130
,
300
]
]
},
axis
:
{
x
:
{
type
:
'timeseries'
,
tick
:
{
format
:
'%Y-%m-%d %H:%M:%S.%L'
,
multiline
:
false
}
}
}
};
expect
(
true
).
toBeTruthy
();
});
it
(
'should have correct number of xs'
,
function
()
{
expect
(
Object
.
keys
(
chart
.
internal
.
data
.
xs
).
length
).
toBe
(
2
);
expect
(
chart
.
internal
.
data
.
xs
.
data1
.
length
).
toBe
(
2
);
expect
(
chart
.
internal
.
data
.
xs
.
data2
.
length
).
toBe
(
2
);
});
it
(
'should have Date object as x'
,
function
()
{
var
xs
=
chart
.
internal
.
data
.
xs
;
expect
(
+
xs
.
data1
[
0
]).
toBe
(
1417622461123
);
expect
(
+
xs
.
data1
[
1
]).
toBe
(
1417622522345
);
expect
(
+
xs
.
data2
[
0
]).
toBe
(
1417622461123
);
expect
(
+
xs
.
data2
[
1
]).
toBe
(
1417622522345
);
});
});
});
});
});
});
...
...
src/core.js
View file @
c3855df1
...
@@ -941,10 +941,10 @@ c3_chart_internal_fn.parseDate = function (date) {
...
@@ -941,10 +941,10 @@ c3_chart_internal_fn.parseDate = function (date) {
var
$$
=
this
,
parsedDate
;
var
$$
=
this
,
parsedDate
;
if
(
date
instanceof
Date
)
{
if
(
date
instanceof
Date
)
{
parsedDate
=
date
;
parsedDate
=
date
;
}
else
if
(
typeof
date
===
'string'
)
{
parsedDate
=
$$
.
dataTimeFormat
(
$$
.
config
.
data_xFormat
).
parse
(
date
);
}
else
if
(
typeof
date
===
'number'
||
!
isNaN
(
date
))
{
}
else
if
(
typeof
date
===
'number'
||
!
isNaN
(
date
))
{
parsedDate
=
new
Date
(
+
date
);
parsedDate
=
new
Date
(
+
date
);
}
else
{
parsedDate
=
$$
.
dataTimeFormat
(
$$
.
config
.
data_xFormat
).
parse
(
date
);
}
}
if
(
!
parsedDate
||
isNaN
(
+
parsedDate
))
{
if
(
!
parsedDate
||
isNaN
(
+
parsedDate
))
{
window
.
console
.
error
(
"Failed to parse x '"
+
date
+
"' to Date object"
);
window
.
console
.
error
(
"Failed to parse x '"
+
date
+
"' to Date object"
);
...
...
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