-
Notifications
You must be signed in to change notification settings - Fork 590
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support axis
labelExpr
+ add example with month initial
- Loading branch information
Showing
11 changed files
with
229 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
{ | ||
"$schema": "https://vega.github.io/schema/vega/v5.json", | ||
"description": "Using `labelExpr` to show only initial letters of month names.", | ||
"autosize": "pad", | ||
"padding": 5, | ||
"width": 200, | ||
"height": 200, | ||
"style": "cell", | ||
"data": [ | ||
{ | ||
"name": "source_0", | ||
"url": "data/seattle-weather.csv", | ||
"format": {"type": "csv", "parse": {"date": "date"}}, | ||
"transform": [ | ||
{ | ||
"type": "formula", | ||
"as": "month_date", | ||
"expr": "datetime(0, month(datum[\"date\"]), 1, 0, 0, 0, 0)" | ||
}, | ||
{ | ||
"type": "formula", | ||
"as": "month_date_end", | ||
"expr": "datetime(0, month(datum[\"date\"])+1, 1, 0, 0, 0, 0)" | ||
}, | ||
{ | ||
"type": "aggregate", | ||
"groupby": ["month_date", "month_date_end"], | ||
"ops": ["mean"], | ||
"fields": ["precipitation"], | ||
"as": ["mean_precipitation"] | ||
}, | ||
{ | ||
"type": "filter", | ||
"expr": "datum[\"month_date\"] !== null && !isNaN(datum[\"month_date\"])" | ||
} | ||
] | ||
} | ||
], | ||
"marks": [ | ||
{ | ||
"name": "marks", | ||
"type": "rect", | ||
"style": ["bar"], | ||
"from": {"data": "source_0"}, | ||
"encode": { | ||
"update": { | ||
"fill": {"value": "#4c78a8"}, | ||
"x2": [ | ||
{ | ||
"test": "datum[\"month_date\"] === null || isNaN(datum[\"month_date\"])", | ||
"value": 0 | ||
}, | ||
{"scale": "x", "field": "month_date", "offset": 1} | ||
], | ||
"x": [ | ||
{ | ||
"test": "datum[\"month_date\"] === null || isNaN(datum[\"month_date\"])", | ||
"value": 0 | ||
}, | ||
{"scale": "x", "field": "month_date_end"} | ||
], | ||
"y": {"scale": "y", "field": "mean_precipitation"}, | ||
"y2": {"scale": "y", "value": 0} | ||
} | ||
} | ||
} | ||
], | ||
"scales": [ | ||
{ | ||
"name": "x", | ||
"type": "time", | ||
"domain": { | ||
"data": "source_0", | ||
"fields": ["month_date", "month_date_end"] | ||
}, | ||
"range": [0, {"signal": "width"}] | ||
}, | ||
{ | ||
"name": "y", | ||
"type": "linear", | ||
"domain": {"data": "source_0", "field": "mean_precipitation"}, | ||
"range": [{"signal": "height"}, 0], | ||
"nice": true, | ||
"zero": true | ||
} | ||
], | ||
"axes": [ | ||
{ | ||
"scale": "x", | ||
"orient": "bottom", | ||
"gridScale": "y", | ||
"grid": true, | ||
"domain": false, | ||
"labels": false, | ||
"maxExtent": 0, | ||
"minExtent": 0, | ||
"ticks": false, | ||
"zindex": 0 | ||
}, | ||
{ | ||
"scale": "y", | ||
"orient": "left", | ||
"gridScale": "x", | ||
"grid": true, | ||
"tickCount": {"signal": "ceil(height/40)"}, | ||
"domain": false, | ||
"labels": false, | ||
"maxExtent": 0, | ||
"minExtent": 0, | ||
"ticks": false, | ||
"zindex": 0 | ||
}, | ||
{ | ||
"scale": "x", | ||
"orient": "bottom", | ||
"grid": false, | ||
"title": "date (month)", | ||
"labelAlign": "left", | ||
"labelFlush": true, | ||
"labelOverlap": true, | ||
"encode": { | ||
"labels": { | ||
"update": {"text": {"signal": "timeFormat(datum.value, '%b')[0]"}} | ||
} | ||
}, | ||
"zindex": 0 | ||
}, | ||
{ | ||
"scale": "y", | ||
"orient": "left", | ||
"grid": false, | ||
"title": "Mean of precipitation", | ||
"labelOverlap": true, | ||
"tickCount": {"signal": "ceil(height/40)"}, | ||
"zindex": 0 | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"$schema": "https://vega.github.io/schema/vega-lite/v3.json", | ||
"description": "Using `labelExpr` to show only initial letters of month names.", | ||
"data": {"url": "data/seattle-weather.csv"}, | ||
"mark": "bar", | ||
"encoding": { | ||
"x": { | ||
"timeUnit": "month", | ||
"field": "date", | ||
"type": "temporal", | ||
"axis": { | ||
"labelAlign": "left", | ||
"labelExpr": "datum.label[0]" | ||
} | ||
}, | ||
"y": { | ||
"aggregate": "mean", | ||
"field": "precipitation", | ||
"type": "quantitative" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.