Skip to content

Commit ad80c37

Browse files
authored
improvement: altair legend selection for composite charts (#6971)
This update introduces functionality to add legend selection to composite charts: layed, vconcat and hconcat specs. Fixes #6676
1 parent 84a992b commit ad80c37

File tree

5 files changed

+741
-4
lines changed

5 files changed

+741
-4
lines changed

frontend/src/plugins/impl/vega/__tests__/__snapshots__/make-selectable.test.ts.snap

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,176 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3+
exports[`makeSelectable > should add legend selection to composite charts (issue #6676) 1`] = `
4+
{
5+
"layer": [
6+
{
7+
"encoding": {
8+
"color": {
9+
"field": "category",
10+
"type": "nominal",
11+
},
12+
"opacity": {
13+
"condition": {
14+
"test": {
15+
"and": [
16+
{
17+
"param": "legend_selection_category",
18+
},
19+
{
20+
"param": "select_point_0",
21+
},
22+
{
23+
"param": "select_interval_0",
24+
},
25+
],
26+
},
27+
"value": 1,
28+
},
29+
"value": 0.2,
30+
},
31+
"x": {
32+
"field": "x_value",
33+
"type": "quantitative",
34+
},
35+
"y": {
36+
"field": "upper",
37+
"type": "quantitative",
38+
},
39+
"y2": {
40+
"field": "lower",
41+
},
42+
},
43+
"mark": {
44+
"cursor": "pointer",
45+
"tooltip": true,
46+
"type": "rule",
47+
},
48+
"params": [
49+
{
50+
"bind": "legend",
51+
"name": "legend_selection_category",
52+
"select": {
53+
"fields": [
54+
"category",
55+
],
56+
"type": "point",
57+
},
58+
},
59+
{
60+
"name": "select_point_0",
61+
"select": {
62+
"encodings": [
63+
"x",
64+
"y",
65+
],
66+
"on": "click[!event.metaKey]",
67+
"type": "point",
68+
},
69+
},
70+
{
71+
"name": "select_interval_0",
72+
"select": {
73+
"encodings": [
74+
"x",
75+
"y",
76+
],
77+
"mark": {
78+
"fill": "#669EFF",
79+
"fillOpacity": 0.07,
80+
"stroke": "#669EFF",
81+
"strokeOpacity": 0.4,
82+
},
83+
"on": "[mousedown[!event.metaKey], mouseup] > mousemove[!event.metaKey]",
84+
"translate": "[mousedown[!event.metaKey], mouseup] > mousemove[!event.metaKey]",
85+
"type": "interval",
86+
},
87+
},
88+
{
89+
"bind": "scales",
90+
"name": "pan_zoom",
91+
"select": {
92+
"on": "[mousedown[event.metaKey], window:mouseup] > window:mousemove!",
93+
"translate": "[mousedown[event.metaKey], window:mouseup] > window:mousemove!",
94+
"type": "interval",
95+
"zoom": "wheel![event.metaKey]",
96+
},
97+
},
98+
],
99+
},
100+
{
101+
"encoding": {
102+
"color": {
103+
"field": "category",
104+
"type": "nominal",
105+
},
106+
"opacity": {
107+
"condition": {
108+
"test": {
109+
"and": [
110+
{
111+
"param": "select_point_1",
112+
},
113+
{
114+
"param": "select_interval_1",
115+
},
116+
],
117+
},
118+
"value": 1,
119+
},
120+
"value": 0.2,
121+
},
122+
"x": {
123+
"field": "x_value",
124+
"type": "quantitative",
125+
},
126+
"y": {
127+
"field": "value",
128+
"type": "quantitative",
129+
},
130+
},
131+
"mark": {
132+
"cursor": "pointer",
133+
"filled": true,
134+
"size": 60,
135+
"tooltip": true,
136+
"type": "point",
137+
},
138+
"params": [
139+
{
140+
"name": "select_point_1",
141+
"select": {
142+
"encodings": [
143+
"x",
144+
"y",
145+
],
146+
"on": "click[!event.metaKey]",
147+
"type": "point",
148+
},
149+
},
150+
{
151+
"name": "select_interval_1",
152+
"select": {
153+
"encodings": [
154+
"x",
155+
"y",
156+
],
157+
"mark": {
158+
"fill": "#669EFF",
159+
"fillOpacity": 0.07,
160+
"stroke": "#669EFF",
161+
"strokeOpacity": 0.4,
162+
},
163+
"on": "[mousedown[!event.metaKey], mouseup] > mousemove[!event.metaKey]",
164+
"translate": "[mousedown[!event.metaKey], mouseup] > mousemove[!event.metaKey]",
165+
"type": "interval",
166+
},
167+
},
168+
],
169+
},
170+
],
171+
}
172+
`;
173+
3174
exports[`makeSelectable > should return correctly if existing legend selection 1`] = `
4175
{
5176
"config": {
@@ -774,6 +945,19 @@ exports[`makeSelectable > should work for layered charts, with existing selectio
774945
},
775946
"value": "lightgray",
776947
},
948+
"opacity": {
949+
"condition": {
950+
"test": {
951+
"and": [
952+
{
953+
"param": "legend_selection_stage",
954+
},
955+
],
956+
},
957+
"value": 1,
958+
},
959+
"value": 0.2,
960+
},
777961
"x": {
778962
"field": "Level1",
779963
"sort": {
@@ -789,10 +973,22 @@ exports[`makeSelectable > should work for layered charts, with existing selectio
789973
},
790974
},
791975
"mark": {
976+
"cursor": "pointer",
977+
"tooltip": true,
792978
"type": "bar",
793979
},
794980
"name": "view_21",
795981
"params": [
982+
{
983+
"bind": "legend",
984+
"name": "legend_selection_stage",
985+
"select": {
986+
"fields": [
987+
"stage",
988+
],
989+
"type": "point",
990+
},
991+
},
796992
{
797993
"bind": "scales",
798994
"name": "pan_zoom",

0 commit comments

Comments
 (0)