Skip to content

Commit

Permalink
fix(#8327): Boxplot set null quantitative to 0 (#8409)
Browse files Browse the repository at this point in the history
* add example

* Take markDef.invalid into boxplot's markdef.

* chore: update schema [CI]

* update doc

* refactor

* chore: update examples [CI]

Co-authored-by: GitHub Actions Bot <vega-actions-bot@users.noreply.github.com>
  • Loading branch information
yhoonkim and GitHub Actions Bot committed Sep 13, 2022
1 parent c2f7b74 commit 62bee7e
Show file tree
Hide file tree
Showing 38 changed files with 1,491 additions and 1,082 deletions.
11 changes: 11 additions & 0 deletions build/vega-lite-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4536,6 +4536,17 @@
],
"description": "The extent of the whiskers. Available options include:\n- `\"min-max\"`: min and max are the lower and upper whiskers respectively.\n- A number representing multiple of the interquartile range. This number will be multiplied by the IQR to determine whisker boundary, which spans from the smallest data to the largest data within the range _[Q1 - k * IQR, Q3 + k * IQR]_ where _Q1_ and _Q3_ are the first and third quartiles while _IQR_ is the interquartile range (_Q3-Q1_).\n\n__Default value:__ `1.5`."
},
"invalid": {
"description": "Defines how Vega-Lite should handle marks for invalid values (`null` and `NaN`).\n- If set to `\"filter\"` (default), all data items with null values will be skipped (for line, trail, and area marks) or filtered (for other marks).\n- If `null`, all data items are included. In this case, invalid values will be interpreted as zeroes.",
"enum": [
"filter",
null
],
"type": [
"string",
"null"
]
},
"median": {
"anyOf": [
{
Expand Down
116 changes: 57 additions & 59 deletions examples/compiled/boxplot_1D_horizontal.vg.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,26 @@
},
{
"name": "data_3",
"source": "data_2",
"transform": [
{
"type": "filter",
"expr": "isValid(datum[\"lower_whisker_Body Mass (g)\"]) && isFinite(+datum[\"lower_whisker_Body Mass (g)\"])"
}
]
},
{
"name": "data_4",
"source": "data_2",
"transform": [
{
"type": "filter",
"expr": "isValid(datum[\"upper_box_Body Mass (g)\"]) && isFinite(+datum[\"upper_box_Body Mass (g)\"])"
}
]
},
{
"name": "data_5",
"source": "source_0",
"transform": [
{
Expand All @@ -90,6 +110,26 @@
]
}
]
},
{
"name": "data_6",
"source": "data_5",
"transform": [
{
"type": "filter",
"expr": "isValid(datum[\"lower_box_Body Mass (g)\"]) && isFinite(+datum[\"lower_box_Body Mass (g)\"])"
}
]
},
{
"name": "data_7",
"source": "data_5",
"transform": [
{
"type": "filter",
"expr": "isValid(datum[\"mid_box_Body Mass (g)\"]) && isFinite(+datum[\"mid_box_Body Mass (g)\"])"
}
]
}
],
"marks": [
Expand Down Expand Up @@ -117,27 +157,15 @@
"type": "rule",
"style": ["rule", "boxplot-rule"],
"aria": false,
"from": {"data": "data_2"},
"from": {"data": "data_3"},
"encode": {
"update": {
"stroke": {"value": "black"},
"tooltip": {
"signal": "{\"Upper Whisker of Body Mass (g)\": format(datum[\"upper_whisker_Body Mass (g)\"], \"\"), \"Lower Whisker of Body Mass (g)\": format(datum[\"lower_whisker_Body Mass (g)\"], \"\")}"
},
"x": [
{
"test": "!isValid(datum[\"lower_whisker_Body Mass (g)\"]) || !isFinite(+datum[\"lower_whisker_Body Mass (g)\"])",
"value": 0
},
{"scale": "x", "field": "lower_whisker_Body Mass (g)"}
],
"x2": [
{
"test": "!isValid(datum[\"lower_box_Body Mass (g)\"]) || !isFinite(+datum[\"lower_box_Body Mass (g)\"])",
"value": 0
},
{"scale": "x", "field": "lower_box_Body Mass (g)"}
],
"x": {"scale": "x", "field": "lower_whisker_Body Mass (g)"},
"x2": {"scale": "x", "field": "lower_box_Body Mass (g)"},
"y": {"signal": "height", "mult": 0.5}
}
}
Expand All @@ -147,27 +175,15 @@
"type": "rule",
"style": ["rule", "boxplot-rule"],
"aria": false,
"from": {"data": "data_2"},
"from": {"data": "data_4"},
"encode": {
"update": {
"stroke": {"value": "black"},
"tooltip": {
"signal": "{\"Upper Whisker of Body Mass (g)\": format(datum[\"upper_whisker_Body Mass (g)\"], \"\"), \"Lower Whisker of Body Mass (g)\": format(datum[\"lower_whisker_Body Mass (g)\"], \"\")}"
},
"x": [
{
"test": "!isValid(datum[\"upper_box_Body Mass (g)\"]) || !isFinite(+datum[\"upper_box_Body Mass (g)\"])",
"value": 0
},
{"scale": "x", "field": "upper_box_Body Mass (g)"}
],
"x2": [
{
"test": "!isValid(datum[\"upper_whisker_Body Mass (g)\"]) || !isFinite(+datum[\"upper_whisker_Body Mass (g)\"])",
"value": 0
},
{"scale": "x", "field": "upper_whisker_Body Mass (g)"}
],
"x": {"scale": "x", "field": "upper_box_Body Mass (g)"},
"x2": {"scale": "x", "field": "upper_whisker_Body Mass (g)"},
"y": {"signal": "height", "mult": 0.5}
}
}
Expand All @@ -176,7 +192,7 @@
"name": "layer_1_layer_0_marks",
"type": "rect",
"style": ["bar", "boxplot-box"],
"from": {"data": "data_3"},
"from": {"data": "data_6"},
"encode": {
"update": {
"ariaRoleDescription": {"value": "box"},
Expand All @@ -187,20 +203,8 @@
"description": {
"signal": "\"Body Mass (g): \" + (format(datum[\"lower_box_Body Mass (g)\"], \"\")) + \"; upper_box_Body Mass (g): \" + (format(datum[\"upper_box_Body Mass (g)\"], \"\")) + \"; Max of Body Mass (g): \" + (format(datum[\"max_Body Mass (g)\"], \"\")) + \"; Q3 of Body Mass (g): \" + (format(datum[\"upper_box_Body Mass (g)\"], \"\")) + \"; Median of Body Mass (g): \" + (format(datum[\"mid_box_Body Mass (g)\"], \"\")) + \"; Q1 of Body Mass (g): \" + (format(datum[\"lower_box_Body Mass (g)\"], \"\")) + \"; Min of Body Mass (g): \" + (format(datum[\"min_Body Mass (g)\"], \"\"))"
},
"x": [
{
"test": "!isValid(datum[\"lower_box_Body Mass (g)\"]) || !isFinite(+datum[\"lower_box_Body Mass (g)\"])",
"value": 0
},
{"scale": "x", "field": "lower_box_Body Mass (g)"}
],
"x2": [
{
"test": "!isValid(datum[\"upper_box_Body Mass (g)\"]) || !isFinite(+datum[\"upper_box_Body Mass (g)\"])",
"value": 0
},
{"scale": "x", "field": "upper_box_Body Mass (g)"}
],
"x": {"scale": "x", "field": "lower_box_Body Mass (g)"},
"x2": {"scale": "x", "field": "upper_box_Body Mass (g)"},
"yc": {"signal": "height", "mult": 0.5},
"height": {"value": 14}
}
Expand All @@ -211,21 +215,15 @@
"type": "rect",
"style": ["tick", "boxplot-median"],
"aria": false,
"from": {"data": "data_3"},
"from": {"data": "data_7"},
"encode": {
"update": {
"opacity": {"value": 0.7},
"fill": {"value": "white"},
"tooltip": {
"signal": "{\"Max of Body Mass (g)\": format(datum[\"max_Body Mass (g)\"], \"\"), \"Q3 of Body Mass (g)\": format(datum[\"upper_box_Body Mass (g)\"], \"\"), \"Median of Body Mass (g)\": format(datum[\"mid_box_Body Mass (g)\"], \"\"), \"Q1 of Body Mass (g)\": format(datum[\"lower_box_Body Mass (g)\"], \"\"), \"Min of Body Mass (g)\": format(datum[\"min_Body Mass (g)\"], \"\")}"
},
"xc": [
{
"test": "!isValid(datum[\"mid_box_Body Mass (g)\"]) || !isFinite(+datum[\"mid_box_Body Mass (g)\"])",
"value": 0
},
{"scale": "x", "field": "mid_box_Body Mass (g)"}
],
"xc": {"scale": "x", "field": "mid_box_Body Mass (g)"},
"yc": {"signal": "height", "mult": 0.5},
"height": {"value": 14},
"width": {"value": 1}
Expand All @@ -240,13 +238,13 @@
"domain": {
"fields": [
{"data": "data_1", "field": "Body Mass (g)"},
{"data": "data_2", "field": "lower_whisker_Body Mass (g)"},
{"data": "data_2", "field": "lower_box_Body Mass (g)"},
{"data": "data_2", "field": "upper_box_Body Mass (g)"},
{"data": "data_2", "field": "upper_whisker_Body Mass (g)"},
{"data": "data_3", "field": "lower_whisker_Body Mass (g)"},
{"data": "data_3", "field": "lower_box_Body Mass (g)"},
{"data": "data_3", "field": "upper_box_Body Mass (g)"},
{"data": "data_3", "field": "mid_box_Body Mass (g)"}
{"data": "data_4", "field": "upper_box_Body Mass (g)"},
{"data": "data_4", "field": "upper_whisker_Body Mass (g)"},
{"data": "data_6", "field": "lower_box_Body Mass (g)"},
{"data": "data_6", "field": "upper_box_Body Mass (g)"},
{"data": "data_7", "field": "mid_box_Body Mass (g)"}
]
},
"range": [0, {"signal": "width"}],
Expand Down
Loading

0 comments on commit 62bee7e

Please sign in to comment.