Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,268 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`makeSelectable > should add bin_coloring param for 2D binned histogram 1`] = `
{
"encoding": {
"color": {
"aggregate": "count",
"type": "quantitative",
},
"opacity": {
"condition": {
"test": {
"and": [
{
"param": "bin_coloring",
},
],
},
"value": 1,
},
"value": 0.2,
},
"x": {
"bin": true,
"field": "x",
"type": "quantitative",
},
"y": {
"bin": true,
"field": "y",
"type": "quantitative",
},
},
"mark": {
"cursor": "pointer",
"tooltip": true,
"type": "rect",
},
"params": [
{
"name": "select_point",
"select": {
"encodings": [
"x",
"y",
],
"on": "click[!event.metaKey]",
"type": "point",
},
},
{
"name": "bin_coloring",
"select": {
"on": "click[!event.metaKey]",
"type": "point",
},
},
{
"bind": "scales",
"name": "pan_zoom",
"select": {
"on": "[mousedown[event.metaKey], window:mouseup] > window:mousemove!",
"translate": "[mousedown[event.metaKey], window:mouseup] > window:mousemove!",
"type": "interval",
"zoom": "wheel![event.metaKey]",
},
},
],
}
`;

exports[`makeSelectable > should add bin_coloring param for binned charts 1`] = `
{
"encoding": {
"opacity": {
"condition": {
"test": {
"and": [
{
"param": "bin_coloring",
},
],
},
"value": 1,
},
"value": 0.2,
},
"x": {
"bin": true,
"field": "x",
"type": "quantitative",
},
"y": {
"aggregate": "count",
"type": "quantitative",
},
},
"mark": {
"cursor": "pointer",
"tooltip": true,
"type": "bar",
},
"params": [
{
"name": "select_point",
"select": {
"encodings": [
"x",
],
"on": "click[!event.metaKey]",
"type": "point",
},
},
{
"name": "bin_coloring",
"select": {
"on": "click[!event.metaKey]",
"type": "point",
},
},
{
"bind": "scales",
"name": "pan_zoom",
"select": {
"on": "[mousedown[event.metaKey], window:mouseup] > window:mousemove!",
"translate": "[mousedown[event.metaKey], window:mouseup] > window:mousemove!",
"type": "interval",
"zoom": "wheel![event.metaKey]",
},
},
],
}
`;

exports[`makeSelectable > should add bin_coloring param for layered binned charts 1`] = `
{
"layer": [
{
"encoding": {
"opacity": {
"condition": {
"test": {
"and": [
{
"param": "bin_coloring_0",
},
],
},
"value": 1,
},
"value": 0.2,
},
"x": {
"bin": true,
"field": "x",
"type": "quantitative",
},
"y": {
"aggregate": "count",
"type": "quantitative",
},
},
"mark": {
"cursor": "pointer",
"tooltip": true,
"type": "bar",
},
"params": [
{
"name": "select_point_0",
"select": {
"encodings": [
"x",
],
"on": "click[!event.metaKey]",
"type": "point",
},
},
{
"name": "bin_coloring_0",
"select": {
"on": "click[!event.metaKey]",
"type": "point",
},
},
{
"bind": "scales",
"name": "pan_zoom",
"select": {
"on": "[mousedown[event.metaKey], window:mouseup] > window:mousemove!",
"translate": "[mousedown[event.metaKey], window:mouseup] > window:mousemove!",
"type": "interval",
"zoom": "wheel![event.metaKey]",
},
},
],
},
{
"encoding": {
"color": {
"value": "red",
},
"opacity": {
"condition": {
"test": {
"and": [
{
"param": "select_point_1",
},
{
"param": "select_interval_1",
},
],
},
"value": 1,
},
"value": 0.2,
},
"x": {
"aggregate": "mean",
"field": "x",
"type": "quantitative",
},
},
"mark": {
"cursor": "pointer",
"tooltip": true,
"type": "rule",
},
"params": [
{
"name": "select_point_1",
"select": {
"encodings": [
"x",
"y",
],
"on": "click[!event.metaKey]",
"type": "point",
},
},
{
"name": "select_interval_1",
"select": {
"encodings": [
"x",
"y",
],
"mark": {
"fill": "#669EFF",
"fillOpacity": 0.07,
"stroke": "#669EFF",
"strokeOpacity": 0.4,
},
"on": "[mousedown[!event.metaKey], mouseup] > mousemove[!event.metaKey]",
"translate": "[mousedown[!event.metaKey], mouseup] > mousemove[!event.metaKey]",
"type": "interval",
},
},
],
},
],
}
`;

exports[`makeSelectable > should add legend selection to composite charts (issue #6676) 1`] = `
{
"layer": [
Expand Down
93 changes: 93 additions & 0 deletions frontend/src/plugins/impl/vega/__tests__/encodings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,97 @@ describe("makeEncodingInteractive", () => {
),
).toEqual(expected);
});

it("should use only bin_coloring param when present", () => {
const encodings: Encodings = {
color: {
field: "someField",
type: "quantitative",
},
};

const expected = {
...encodings,
opacity: {
condition: {
test: {
and: [{ param: "bin_coloring" }],
},
value: 1,
},
value: 0.2,
},
};

expect(
makeEncodingInteractive(
"opacity",
encodings,
["select_point", "bin_coloring"],
"point",
),
).toEqual(expected);
});

it("should use only bin_coloring params when multiple are present", () => {
const encodings: Encodings = {
color: {
field: "someField",
type: "quantitative",
},
};

const expected = {
...encodings,
opacity: {
condition: {
test: {
and: [{ param: "bin_coloring_0" }, { param: "bin_coloring_1" }],
},
value: 1,
},
value: 0.2,
},
};

expect(
makeEncodingInteractive(
"opacity",
encodings,
["select_point", "bin_coloring_0", "select_interval", "bin_coloring_1"],
"point",
),
).toEqual(expected);
});

it("should fall back to all params when no bin_coloring params present", () => {
const encodings: Encodings = {
color: {
field: "someField",
type: "quantitative",
},
};

const expected = {
...encodings,
opacity: {
condition: {
test: {
and: [{ param: "select_point" }, { param: "select_interval" }],
},
value: 1,
},
value: 0.2,
},
};

expect(
makeEncodingInteractive(
"opacity",
encodings,
["select_point", "select_interval"],
"point",
),
).toEqual(expected);
});
});
Loading
Loading