From 03e8f7162dd472cfde6bd282daf980b3e7c16258 Mon Sep 17 00:00:00 2001 From: Kanit Wongsuphasawat Date: Wed, 8 Nov 2023 09:13:57 -0800 Subject: [PATCH 1/4] docs(example): bar_1d_dimension only --- examples/specs/bar_1d_dimension_only.vl.json | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 examples/specs/bar_1d_dimension_only.vl.json diff --git a/examples/specs/bar_1d_dimension_only.vl.json b/examples/specs/bar_1d_dimension_only.vl.json new file mode 100644 index 0000000000..b174acb053 --- /dev/null +++ b/examples/specs/bar_1d_dimension_only.vl.json @@ -0,0 +1,18 @@ +{ + "$schema": "https://vega.github.io/schema/vega-lite/v5.json", + "description": "A simple bar chart with embedded data.", + "data": { + "values": [ + {"b": 0}, + {"b": 10}, + {"b": 10}, + {"b": 10}, + {"b": 10}, + {"b": 20} + ] + }, + "mark": {"type": "bar", "orient": "horizontal"}, + "encoding": { + "y": {"field": "b", "type": "quantitative"} + } +} From 558d6e2c39c7b5dd5e8aaf262369bd12e0593ccd Mon Sep 17 00:00:00 2001 From: GitHub Actions Bot Date: Wed, 8 Nov 2023 17:17:37 +0000 Subject: [PATCH 2/4] chore: update examples [CI] --- examples/compiled/bar_1d_dimension_only.png | Bin 0 -> 3184 bytes examples/compiled/bar_1d_dimension_only.svg | 1 + .../compiled/bar_1d_dimension_only.vg.json | 94 ++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 examples/compiled/bar_1d_dimension_only.png create mode 100644 examples/compiled/bar_1d_dimension_only.svg create mode 100644 examples/compiled/bar_1d_dimension_only.vg.json diff --git a/examples/compiled/bar_1d_dimension_only.png b/examples/compiled/bar_1d_dimension_only.png new file mode 100644 index 0000000000000000000000000000000000000000..5763fa070575dde774a21f7befa60c9aa8c8507c GIT binary patch literal 3184 zcmb7H2T)Vl8qU&-0xQx)5D*-3y4%BEg~QgR9YaBrHLAPM^I^sp(ui(cR~nF zK!Jdf8Xy5gq?gb;1mD%!d9yoj=FPr)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pHEb@ z1R!BWg*kZj1EUQk`&!%pAZ-@UOHzkifTkrSB>^c^=~PloP$(rph>W;{qk|PKukTDz zTq56z(pgMz-oKB`%abX-;p1~2(4D*;eiatjZaetA^=(NBSKOzT*B20)kGJKgr>B`% zSllsY+){<)*qRy*FE6hT@tOt>4i3dn4tLjle0)Yj_Y!)agT-ZJ*Z@a0x3FO6=9bpc zNe9>~e#Z61ix+zO`W271+*?{&@DC;!q>^F)r@vk34cMlMR8p#_ck^2sjkfS1gz?u% zbICMQQBjfA*0%K=F1wOuB9(%{XcwsrQz-fM4GmUM=(B>nyj=vCSDv4<8*)%&no02( zgf#s)I*`9zku#1H5)#_o+k>A!MX5oZDTEcbjE!Z?&AC2#@}#4q<3oFURB9^!30_{2 zP4AUKV-yH3O=)Ry5`-aZW6uF-piin7)-=-pJRsvoa zzf>ecusJ!aZNezfgUva!nJ*cIrbE)w(n&90YRnBB5xcI)9}I~{QE(G0m9%xAXCc%& z|I(QUo=BvWjEsRC=Ay4`e0+QuZpEs^uHgtTUkU8>T~Ag{uKFU0L{bmQqHEs^+fp@4iZeIT+RwJK zvXZyOJCNpe((7((YjO!XXKcqf?=oiabdB_`WP;q$>Y;T#?W@b|xlR2gpRS)l>$$i{V>D1Wt&`qc3uHTj z4?7BlQb&E&kxH*1TsAN@J$KC8GC88xb)fIvbexZDcv+e9_R4r^E;I|`xzV$P zse6%qQ~^dm3&YsqM}SpOg(*ls;#3zh?9t>17#d1YmI@;CMR{tFtyi4C1&v3ii^oKi? zjg75r?P^VRwF*FZ1$xlLbM(}U>oT&kPR*grhpVmJfZI&0tdypV!?-9R$*HOOK$Zch zqsbo^0Zb1&)GN`pOR)OU#79d4Pc->j!r6I&4)ATX*4rdal^F;j_k \ No newline at end of file diff --git a/examples/compiled/bar_1d_dimension_only.vg.json b/examples/compiled/bar_1d_dimension_only.vg.json new file mode 100644 index 0000000000..86fadf6500 --- /dev/null +++ b/examples/compiled/bar_1d_dimension_only.vg.json @@ -0,0 +1,94 @@ +{ + "$schema": "https://vega.github.io/schema/vega/v5.json", + "description": "A simple bar chart with embedded data.", + "background": "white", + "padding": 5, + "width": 20, + "height": 200, + "style": "cell", + "data": [ + { + "name": "source_0", + "values": [ + {"b": 0}, + {"b": 10}, + {"b": 10}, + {"b": 10}, + {"b": 10}, + {"b": 20} + ] + }, + { + "name": "data_0", + "source": "source_0", + "transform": [ + { + "type": "stack", + "groupby": [], + "field": "b", + "sort": {"field": [], "order": []}, + "as": ["b_start", "b_end"], + "offset": "zero" + }, + { + "type": "filter", + "expr": "isValid(datum[\"b\"]) && isFinite(+datum[\"b\"])" + } + ] + } + ], + "marks": [ + { + "name": "marks", + "type": "rect", + "style": ["bar"], + "from": {"data": "data_0"}, + "encode": { + "update": { + "fill": {"value": "#4c78a8"}, + "ariaRoleDescription": {"value": "bar"}, + "description": {"signal": "\"b: \" + (format(datum[\"b\"], \"\"))"}, + "x": {"field": {"group": "width"}}, + "x2": {"value": 0}, + "yc": {"scale": "y", "field": "b"}, + "height": {"value": 5} + } + } + } + ], + "scales": [ + { + "name": "y", + "type": "linear", + "domain": {"data": "data_0", "fields": ["b_start", "b_end"]}, + "range": [{"signal": "height"}, 0], + "nice": true, + "zero": false, + "padding": 5 + } + ], + "axes": [ + { + "scale": "y", + "orient": "left", + "grid": true, + "tickCount": {"signal": "ceil(height/40)"}, + "domain": false, + "labels": false, + "aria": false, + "maxExtent": 0, + "minExtent": 0, + "ticks": false, + "zindex": 0 + }, + { + "scale": "y", + "orient": "left", + "grid": false, + "title": "b", + "labelOverlap": true, + "tickCount": {"signal": "ceil(height/40)"}, + "zindex": 0 + } + ] +} From 0007da518cedfb416b8fa76b3e99a7a4d3eb4fcf Mon Sep 17 00:00:00 2001 From: Kanit Wongsuphasawat Date: Wed, 8 Nov 2023 09:28:33 -0800 Subject: [PATCH 3/4] fix: make 1D bar respect orientation for stack calculation (#9167) --- src/stack.ts | 10 ++++++++-- test/stack.test.ts | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/stack.ts b/src/stack.ts index 00e7bb3b38..98a115d97a 100644 --- a/src/stack.ts +++ b/src/stack.ts @@ -87,7 +87,7 @@ function potentialStackedChannel( ): 'x' | 'y' | 'theta' | 'radius' | undefined { const y = x === 'x' ? 'y' : 'radius'; - const isCartesian = x === 'x'; + const isCartesianBarOrArea = x === 'x' && ['bar', 'area'].includes(mark); const xDef = encoding[x]; const yDef = encoding[y]; @@ -106,7 +106,7 @@ function potentialStackedChannel( return xAggregate ? x : y; } - if (isCartesian && ['bar', 'area'].includes(mark)) { + if (isCartesianBarOrArea) { if (orient === 'vertical') { return y; } else if (orient === 'horizontal') { @@ -119,8 +119,14 @@ function potentialStackedChannel( return y; } } else if (isUnbinnedQuantitative(xDef)) { + if (isCartesianBarOrArea && orient === 'vertical') { + return undefined; + } return x; } else if (isUnbinnedQuantitative(yDef)) { + if (isCartesianBarOrArea && orient === 'horizontal') { + return undefined; + } return y; } return undefined; diff --git a/test/stack.test.ts b/test/stack.test.ts index d215d92250..9a28b5c9de 100644 --- a/test/stack.test.ts +++ b/test/stack.test.ts @@ -56,6 +56,30 @@ describe('stack', () => { } }); + it("doesn't stacked the dimension field on a 1D vertical bar with dimension only", () => { + const spec: TopLevel = { + data: {url: 'data/barley.json'}, + mark: {type: 'bar', orient: 'vertical'}, + encoding: { + x: {field: 'yield', type: 'quantitative'} + } + }; + const stackProps = stack(spec.mark, spec.encoding); + expect(stackProps).toBeNull(); + }); + + it("doesn't stacked the dimension field on a 1D horizontal bar with dimension only", () => { + const spec: TopLevel = { + data: {url: 'data/barley.json'}, + mark: {type: 'bar', orient: 'horizontal'}, + encoding: { + y: {field: 'yield', type: 'quantitative'} + } + }; + const stackProps = stack(spec.mark, spec.encoding); + expect(stackProps).toBeNull(); + }); + it('should be disabled when stack is false', () => { for (const mark of STACKABLE_NON_POLAR_MARKS) { const spec: TopLevel = { From 428e49164510151b30201cbcb631b3d489110513 Mon Sep 17 00:00:00 2001 From: GitHub Actions Bot Date: Wed, 8 Nov 2023 17:33:28 +0000 Subject: [PATCH 4/4] chore: update examples [CI] --- examples/compiled/bar_1d_dimension_only.png | Bin 3184 -> 2298 bytes examples/compiled/bar_1d_dimension_only.svg | 2 +- .../compiled/bar_1d_dimension_only.vg.json | 10 +--------- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/examples/compiled/bar_1d_dimension_only.png b/examples/compiled/bar_1d_dimension_only.png index 5763fa070575dde774a21f7befa60c9aa8c8507c..dfe534e0c05f28c5465366820fb8634e53208f9f 100644 GIT binary patch literal 2298 zcmbtWc{J4P8~=thMaYsY;gX_@X<;lGUCUtP%9=BlrUo-Yh$+iuw77++D@!yQYRW#8 z$reLp&(4f#Vuq}f8m^fvg>k?4{?4yI`tP25-t)fC^Urh6^E{vByvfc^cDr{e?*af| zH`3n56^xeP9fF91ufldpF&M-#r|fKit-ntJttbNkAeBfPOZVtJ9y`HaK0&Qx2^T~0 zE*>{T4wbL%Lf*VWI;e!P!lopj*Hz4cU>;{*)}|w!SNmP;Iq`zZ!~(-4xe~`OR!{%X zLpC^wb~|)C`BrbFzx1qWh)w9^)xx7TT~3h4XlRYkaaf#%x>`?9-&-7~!9OA*;@*}( z&zHMR?guezI+F%oC7JB!Ma+|e zh-g5rY5;%Nd`}8w-t-cUSyY_#XwAhb?jSieH8qC`kKreRr5FsRE@7)lmfe3MMT3hs zx`Aqw|Q?T2H_cX=3HYq6yD4yCm8ICEpT<*G%6!I8(aHaX<2mmy}YH4 zo}Pb5NKfNuE;o=6KTp@KqEe6MI+pv?M~uW%!jC-bn>y5xMj=~ki=oFqs#}k@vskF) z(B=~nqp3eY_8q%_k?5G<)S#>=jI(lD5*ApA&xB>&3s%{adaqO5Z6bj`F1dIhvkbArdoyE!( z3JI#Js%vXYT9%fUdxzJ`PtU#({!#=dAAU3Rv{@~BVPQc`TzqJ7@VqTVLPASVuLnaE z%=Mop#(mXt;q64-c>QW%KnC4RKvXi1o105I!ug}`-r1w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z61ix+zO`W271+*?{&@DC;!q>^F)r@vk34cMlMR8p#_ck^2sjkfS1gz?u% zbICMQQBjfA*0%K=F1wOuB9(%{XcwsrQz-fM4GmUM=(B>nyj=vCSDv4<8*)%&no02( zgf#s)I*`9zku#1H5)#_o+k>A!MX5oZDTEcbjE!Z?&AC2#@}#4q<3oFURB9^!30_{2 zP4AUKV-yH3O=)Ry5`-aZW6uF-piin7)-=-pJRsvoa zzf>ecusJ!aZNezfgUva!nJ*cIrbE)w(n&90YRnBB5xcI)9}I~{QE(G0m9%xAXCc%& z|I(QUo=BvWjEsRC=Ay4`e0+QuZpEs^uHgtTUkU8>T~Ag{uKFU0L{bmQqHEs^+fp@4iZeIT+RwJK zvXZyOJCNpe((7((YjO!XXKcqf?=oiabdB_`WP;q$>Y;T#?W@b|xlR2gpRS)l>$$i{V>D1Wt&`qc3uHTj z4?7BlQb&E&kxH*1TsAN@J$KC8GC88xb)fIvbexZDcv+e9_R4r^E;I|`xzV$P zse6%qQ~^dm3&YsqM}SpOg(*ls;#3zh?9t>17#d1YmI@;CMR{tFtyi4C1&v3ii^oKi? zjg75r?P^VRwF*FZ1$xlLbM(}U>oT&kPR*grhpVmJfZI&0tdypV!?-9R$*HOOK$Zch zqsbo^0Zb1&)GN`pOR)OU#79d4Pc->j!r6I&4)ATX*4rdal^F;j_k \ No newline at end of file +05101520b \ No newline at end of file diff --git a/examples/compiled/bar_1d_dimension_only.vg.json b/examples/compiled/bar_1d_dimension_only.vg.json index 86fadf6500..c438e6594a 100644 --- a/examples/compiled/bar_1d_dimension_only.vg.json +++ b/examples/compiled/bar_1d_dimension_only.vg.json @@ -22,14 +22,6 @@ "name": "data_0", "source": "source_0", "transform": [ - { - "type": "stack", - "groupby": [], - "field": "b", - "sort": {"field": [], "order": []}, - "as": ["b_start", "b_end"], - "offset": "zero" - }, { "type": "filter", "expr": "isValid(datum[\"b\"]) && isFinite(+datum[\"b\"])" @@ -60,7 +52,7 @@ { "name": "y", "type": "linear", - "domain": {"data": "data_0", "fields": ["b_start", "b_end"]}, + "domain": {"data": "data_0", "field": "b"}, "range": [{"signal": "height"}, 0], "nice": true, "zero": false,