Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

date parsing fails when using number #311

Closed
danelkhen opened this issue Jun 3, 2014 · 9 comments
Closed

date parsing fails when using number #311

danelkhen opened this issue Jun 3, 2014 · 9 comments
Labels
C-bug Category: This is a bug resolved maybe

Comments

@danelkhen
Copy link
Contributor

I'm not sure I understand this line of code:

parsedDate = date instanceof Date ? new Date(date) : d3.time.format(__data_x_format).parse(date);

How will date be instaceof Date, and why would we need to instantiate a new Date instance for it? Wasn't it supposed to be:

parsedDate = typeof(date)=="number" ? new Date(date) : d3.time.format(__data_x_format).parse(date);
@masayuki0812
Copy link
Member

Hi, Thank you for reporting. This is a bug and now c3 can't accept date as number as you wrote. The code needs to be fixed to accept a number.

The condition date instanceof Date is needed because c3 accpets Date object and this code needs to be changed to accept number and Date object. I fixed this code as so and now it seems working well.

I added a sample for this issue:
https://github.com/masayuki0812/c3/blob/master/htdocs/samples/timeseries_raw.html
https://github.com/masayuki0812/c3/blob/master/htdocs/samples/timeseries_date.html

@danelkhen
Copy link
Contributor Author

Excellent, thanks!

@danelkhen danelkhen reopened this Jun 5, 2014
@danelkhen
Copy link
Contributor Author

I think that this issue still exists - have a look at parseDate function, my graph crashes there on the very same error. Let me know if you need a sample to reproduce this.

@masayuki0812
Copy link
Member

Oh.. Could you give a code to reproduce this? It seems working well in my examples. Thanks.

@danelkhen
Copy link
Contributor Author

Here's a reproduction:

var chart = c3.generate({
    "bindto": "#chart", "axis": { "x": { "type": "timeseries", "min": 1401879600000, "max": 1401969600000, } },
    "grid": { "x": { "lines": [{ "value": 1401880524000, "text": "a", "color": "#f00" }, { "value": 1401880566000, "text": "b", "color": "#f00" }] } },
    "data": {
        "type": "line",
        "columns": [
            ["epoch", 1401879600000, 1401883200000, 1401886800000],
            ["y", 1955, 2419, 2262]],
        "xs": { "y": "epoch" }
    }
});

Please note: when removing the custom gridlines, and min/max it works again. So the the parseDate function is probably used when using these features.

@smeyfroi
Copy link

smeyfroi commented Jun 5, 2014

I think I just ran into this as well. I'm using axis.x.max and gridlines on a time-series chart with the flow() API. It's intermittent for me though, so I can't add much to this conversation at the moment.

@masayuki0812
Copy link
Member

Hi, Thanks for the code and I'm sorry I noticed that in the previous commit I fixed the different point from where you pointed out. I think now we can parse number correctly on grid and max/min.

@danelkhen
Copy link
Contributor Author

Great, thanks!

@smeyfroi
Copy link

smeyfroi commented Jun 6, 2014

Thanks! Fixed over here. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug resolved maybe
Projects
None yet
Development

No branches or pull requests

3 participants