Applying the extent transform to a field that contains Date instances returns an array of timestamps
See original GitHub issueApplying the extent
transform to a field that contains Date
instances returns an array of timestamps rather than an array of Date
instances.
To recreate, paste the following specification into the Vega Editor. Notice that the value of the dateDomain
signal is an array of timestamps rather than an array of Date
instances, even though the date
field contains Date
instances.
{
"$schema": "https://vega.github.io/schema/vega/v5.json",
"data": [
{
"name": "table",
"transform": [
{"type": "sequence", "start": 1, "stop": 8, "as": "index"},
{
"type": "formula",
"expr": "datetime(2021, 0, datum.index)",
"as": "date"
},
{"type": "formula", "expr": "time(datum.date)", "as": "timestamp"},
{"type": "extent", "field": "date", "signal": "dateDomain"}
]
}
]
}
I’ve raised this bug because I think that the extent of a field should have the same type as the field: one would expect a field of numbers to have an extent that was also numbers, for example. However, I appreciate that Date
instances can be problematic and that returning timestamps may be preferable. If this is a feature rather than a bug, then I will open a PR on the documentation.
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (7 by maintainers)
Top GitHub Comments
Yes, or just
+date
suffices for date-to-number coercion in most situations, assuming nonull
values are involved.You are right, Vega does not transparently handle timestamps/datetime in custom expressions.