-
Notifications
You must be signed in to change notification settings - Fork 621
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
fix: apply bandPosition to offset channel for grouped bar (so band size works with grouped bars) #9178
Open
kanitw
wants to merge
5
commits into
main
Choose a base branch
from
kw/9177-grouped-bar-discrete-bandSize
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
fix: apply bandPosition to offset channel for grouped bar (so band size works with grouped bars) #9178
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b4d0566
docs(examples): add broken example for https://github.com/vega/vega-l…
kanitw efacdd0
chore: update examples [CI]
0d7ec05
fix: apply bandPosition to offset channel for grouped bar (so band si…
kanitw 4deb363
chore: update examples [CI]
94c141c
test: unit tests
kanitw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
142 changes: 142 additions & 0 deletions
142
examples/compiled/bar_grouped_discrete_bandsize.vg.json
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,142 @@ | ||
{ | ||
"$schema": "https://vega.github.io/schema/vega/v5.json", | ||
"background": "white", | ||
"padding": 5, | ||
"height": 200, | ||
"style": "cell", | ||
"data": [ | ||
{ | ||
"name": "source_0", | ||
"values": [ | ||
{"category": "A", "group": "x", "value": 0.1}, | ||
{"category": "A", "group": "y", "value": 0.6}, | ||
{"category": "A", "group": "z", "value": 0.9}, | ||
{"category": "B", "group": "x", "value": 0.7}, | ||
{"category": "B", "group": "y", "value": 0.2}, | ||
{"category": "B", "group": "z", "value": 1.1}, | ||
{"category": "C", "group": "x", "value": 0.6}, | ||
{"category": "C", "group": "y", "value": 0.1}, | ||
{"category": "C", "group": "z", "value": 0.2} | ||
] | ||
}, | ||
{ | ||
"name": "data_0", | ||
"source": "source_0", | ||
"transform": [ | ||
{ | ||
"type": "stack", | ||
"groupby": ["category", "group"], | ||
"field": "value", | ||
"sort": {"field": [], "order": []}, | ||
"as": ["value_start", "value_end"], | ||
"offset": "zero" | ||
}, | ||
{ | ||
"type": "filter", | ||
"expr": "isValid(datum[\"value\"]) && isFinite(+datum[\"value\"])" | ||
} | ||
] | ||
} | ||
], | ||
"signals": [ | ||
{ | ||
"name": "x_step", | ||
"update": "20 * bandspace(domain('xOffset').length, 0, 0) / (1-0.2)" | ||
}, | ||
{ | ||
"name": "width", | ||
"update": "bandspace(domain('x').length, 0.2, 0.2) * x_step" | ||
} | ||
], | ||
"marks": [ | ||
{ | ||
"name": "marks", | ||
"type": "rect", | ||
"style": ["bar"], | ||
"from": {"data": "data_0"}, | ||
"encode": { | ||
"update": { | ||
"fill": {"scale": "color", "field": "group"}, | ||
"ariaRoleDescription": {"value": "bar"}, | ||
"description": { | ||
"signal": "\"category: \" + (isValid(datum[\"category\"]) ? datum[\"category\"] : \"\"+datum[\"category\"]) + \"; value: \" + (format(datum[\"value\"], \"\")) + \"; group: \" + (isValid(datum[\"group\"]) ? datum[\"group\"] : \"\"+datum[\"group\"])" | ||
}, | ||
"x": { | ||
"scale": "x", | ||
"field": "category", | ||
"offset": {"scale": "xOffset", "field": "group", "band": 0.25} | ||
}, | ||
"width": {"signal": "max(0.25, 0.5 * bandwidth('xOffset'))"}, | ||
"y": {"scale": "y", "field": "value_end"}, | ||
"y2": {"scale": "y", "field": "value_start"} | ||
} | ||
} | ||
} | ||
], | ||
"scales": [ | ||
{ | ||
"name": "x", | ||
"type": "band", | ||
"domain": {"data": "data_0", "field": "category", "sort": true}, | ||
"range": {"step": {"signal": "x_step"}}, | ||
"paddingInner": 0.2, | ||
"paddingOuter": 0.2 | ||
}, | ||
{ | ||
"name": "y", | ||
"type": "linear", | ||
"domain": {"data": "data_0", "fields": ["value_start", "value_end"]}, | ||
"range": [{"signal": "height"}, 0], | ||
"nice": true, | ||
"zero": true | ||
}, | ||
{ | ||
"name": "xOffset", | ||
"type": "band", | ||
"domain": {"data": "data_0", "field": "group", "sort": true}, | ||
"range": {"step": 20} | ||
}, | ||
{ | ||
"name": "color", | ||
"type": "ordinal", | ||
"domain": {"data": "data_0", "field": "group", "sort": true}, | ||
"range": "category" | ||
} | ||
], | ||
"axes": [ | ||
{ | ||
"scale": "y", | ||
"orient": "left", | ||
"gridScale": "x", | ||
"grid": true, | ||
"tickCount": {"signal": "ceil(height/40)"}, | ||
"domain": false, | ||
"labels": false, | ||
"aria": false, | ||
"maxExtent": 0, | ||
"minExtent": 0, | ||
"ticks": false, | ||
"zindex": 0 | ||
}, | ||
{ | ||
"scale": "x", | ||
"orient": "bottom", | ||
"grid": false, | ||
"title": "category", | ||
"labelAlign": "right", | ||
"labelAngle": 270, | ||
"labelBaseline": "middle", | ||
"zindex": 0 | ||
}, | ||
{ | ||
"scale": "y", | ||
"orient": "left", | ||
"grid": false, | ||
"title": "value", | ||
"labelOverlap": true, | ||
"tickCount": {"signal": "ceil(height/40)"}, | ||
"zindex": 0 | ||
} | ||
], | ||
"legends": [{"fill": "color", "symbolType": "square", "title": "group"}] | ||
} |
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,26 @@ | ||
{ | ||
"$schema": "https://vega.github.io/schema/vega-lite/v5.json", | ||
"data": { | ||
"values": [ | ||
{"category":"A", "group": "x", "value":0.1}, | ||
{"category":"A", "group": "y", "value":0.6}, | ||
{"category":"A", "group": "z", "value":0.9}, | ||
{"category":"B", "group": "x", "value":0.7}, | ||
{"category":"B", "group": "y", "value":0.2}, | ||
{"category":"B", "group": "z", "value":1.1}, | ||
{"category":"C", "group": "x", "value":0.6}, | ||
{"category":"C", "group": "y", "value":0.1}, | ||
{"category":"C", "group": "z", "value":0.2} | ||
] | ||
}, | ||
"mark": "bar", | ||
"encoding": { | ||
"x": {"field": "category"}, | ||
"y": {"field": "value", "type": "quantitative"}, | ||
"xOffset": {"field": "group"}, | ||
"color": {"field": "group"} | ||
}, | ||
"config": { | ||
"bar": {"discreteBandSize": {"band": 0.5}} | ||
} | ||
} |
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested different combinations of
center
andoffsetType
, and found that this is not consistent with the old version.The
bandPosition
used bydefaultRef
issignal-relative
value in the old implementation, but0
in the new implementation, when center isfalse
andoffsetType
check istrue
.This nested ternary expression is already very complex. Consider making it a function and testing it in unit test.