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

Separator "." in date data is no longer working #2870

Closed
pietrasagh opened this issue Sep 13, 2020 · 6 comments
Closed

Separator "." in date data is no longer working #2870

pietrasagh opened this issue Sep 13, 2020 · 6 comments
Labels
wontfix For issues we do not plan to address

Comments

@pietrasagh
Copy link

Separator "." in date data (e.g. "2001.12.13") is no longer working . Other combinations of "/", " " and "," are parsed correctly (e.g. "2019 //// 10, ,,,, / 01" or "2019 11 01"). It seems that separator "-" can be only one and not combined with any other.
Problem may be due to some update in d3 or deeper in eslint. I noticed it on wikipedia Graph Extension which is using Vega 2.
I tested it on
in editor for Vega version Vega 5.15.0
and Vega 2 editor

{
  "$schema": "https://vega.github.io/schema/vega/v5.json",
  "width": 500,
  "height": 250,

  "data": [
    {
      "name": "traffic",
      "values": [
        {"date": "2020.01.01", "curr": 3764192, "prev": 3560276},
        {"date": "2019 ////  10, ,,,, / 01", "curr": 4292562, "prev": 4044655},
        {"date": "2019    11     01", "curr": 3892767, "prev": 3817267},
        {"date": "2019-12-01", "curr": 4320042, "prev": 3937790}
      ],
      "format": {
        "type": "json",
        "parse": {"date": "date"}
      },
      "transform": [
        {
          "type": "timeunit",
          "units": ["year", "month"],
          "field": "date"
        }
      ]
    }
  ],

  "scales": [
    {
      "name": "x",
      "type": "time",
      "range": "width",
      "padding": 24,
      "domain": {"data": "traffic", "field": "unit0"}
    },
    {
      "name": "y",
      "type": "linear",
      "range": "height",
      "nice": true,
      "zero": false,
      "domain": {"data": "traffic", "field": "curr"}
    }
  ],


  "axes": [
    {
      "orient": "bottom",
      "scale": "x",
      "format": "%b %Y"
          },
    {
      "orient": "left",
      "scale": "y",
      "grid": true

    }
  ],

  "marks": [
    {
      "type": "line",
      "aria": false,
      "from": {"data": "traffic"},
      "encode": {
        "enter": {
          "x": {"scale": "x", "field": "unit0"},
          "y": {"scale": "y", "field": "curr"},
          "stroke": {"value": "steelblue"},
          "strokeWidth": {"value": 3}
        }
      }
    }
  ]
}
@pietrasagh pietrasagh added the bug For bugs or other software errors label Sep 13, 2020
@pietrasagh pietrasagh changed the title Sseparator "." in date data is no longer working Separator "." in date data is no longer working Sep 13, 2020
@domoritz domoritz added wontfix For issues we do not plan to address and removed bug For bugs or other software errors labels Sep 14, 2020
@domoritz
Copy link
Member

Vega uses standard browser date parsing and only dates in the standard formats are supported.

Vega 2 probably used datalib and may have used different date parsing ut I haven't checked.

@domoritz
Copy link
Member

It would be awesome if you help update the graph extension to the latest Vega versions, btw.

@pietrasagh
Copy link
Author

pietrasagh commented Sep 15, 2020

I checked example code with "." separator on mentioned mozilla website and it works.

const javaScriptRelease = Date.parse('04.12.1995');
console.log(javaScriptRelease);
// expected output: 818035920000

My js skills are on "Hello world" level. Unfortunate Mediawiki developers seems to be overloaded with more urgent issues. They started to work on it but got stucked. If you could help would be great. Please contact Yurik for details

@jheer
Copy link
Member

jheer commented Sep 15, 2020

Unfortunately, '04.12.1995' is simply not a universally valid date. I just tested and it works in Chrome, but not in Firefox. I don't believe this is a Vega-specific issue, but rather a consequence of different browsers supporting inconsistent formats for Date.parse. The solution is to change the input data to use a valid date string accepted by all major browsers.

@jheer
Copy link
Member

jheer commented Sep 15, 2020

Alternatively, you can specify the date format yourself as part of the Vega specification, as described here: https://vega.github.io/vega/docs/data/#format.

You can pass a format parameter like {"myDateField": "date:'%m.%d.%Y'"} to specify a custom date format.
I don't recall offhand but I believe we supported this in Vega 2 as well.

@pietrasagh
Copy link
Author

This could be best solution for me. I will check if it works.
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix For issues we do not plan to address
Projects
None yet
Development

No branches or pull requests

3 participants