Skip to content
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

feat: add filter and sort support for tooltips #9148

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

sfc-gh-cheliu
Copy link

@sfc-gh-cheliu sfc-gh-cheliu commented Oct 22, 2023

Parameter signatures:
Filter - added as a parameter for each tooltip object in the tooltip array:
{"field": "type1", "type": "quantitative", "**filter**": {"operator": ">", "literal": 0}

Sort - added as a parameter for encoding:
"encoding": { "opacity": { "condition": { "empty": false, "param": "param_46", "value": 0.2 }, "value": 0 }, "size": { "value": 4 }, "tooltip": [ { "field": "Date", "type": "nominal" }, { "field": "type1", "type": "quantitative" }, { "field": "type2", "type": "quantitative" }, { "field": "type3", "type": "quantitative" }, { "field": "type4", "type": "quantitative" }, { "field": "type5", "type": "quantitative" }, { "field": "type6", "type": "quantitative" }, { "field": "type7", "type": "quantitative" }, { "field": "type8", "type": "quantitative" } ], "**sort_tooltip**": {"value": "descending"}, "x": { "field": "Date", "title": null, "type": "ordinal" } }, "mark": { "type": "rule" }, "params": [ { "name": "param_46", "select": { "clear": "mouseout", "fields": [ "Date" ], "nearest": true, "on": "mouseover", "type": "point" } } ]

Original vega-lite specification:

{
    "config": {
        "view": {
            "continuousHeight": 300,
            "continuousWidth": 300
        }
    },
    "layer": [{
            "data": {
                "values": [{
                        "Date": "2021-06-29",
                        "Type": "type7",
                        "Value": 0
                    },
                    {
                        "Date": "2021-06-29",
                        "Type": "type4",
                        "Value": 0
                    },
                    {
                        "Date": "2021-06-29",
                        "Type": "type5",
                        "Value": 10687
                    },
                    {
                        "Date": "2021-06-29",
                        "Type": "type1",
                        "Value": 11501
                    },
                    {
                        "Date": "2021-06-29",
                        "Type": "type3",
                        "Value": 0
                    },
                    {
                        "Date": "2021-06-22",
                        "Type": "type7",
                        "Value": 5735
                    },
                    {
                        "Date": "2021-06-22",
                        "Type": "type8",
                        "Value": 7486
                    },
                    {
                        "Date": "2021-06-22",
                        "Type": "type1",
                        "Value": 8283
                    },
                    {
                        "Date": "2021-06-22",
                        "Type": "type4",
                        "Value": 8283
                    },
                    {
                        "Date": "2021-06-22",
                        "Type": "type6",
                        "Value": 8917
                    },
                    {
                        "Date": "2021-06-22",
                        "Type": "type2",
                        "Value": 9856
                    }
                ]

            },
            "encoding": {
                "color": {
                    "field": "Type",
                    "type": "nominal"
                },
                "order": {
                    "field": "Value",
                    "sort": "ascending",
                    "type": "quantitative"
                },
                "x": {
                    "field": "Date",
                    "type": "ordinal"
                },
                "y": {
                    "field": "Value",
                    "type": "quantitative"
                }
            },
            "mark": {
                "type": "bar"
            }

        },
        {
            "data": {
                "values": [{
                        "Date": "2021-06-22",
                        "type1": 8283,
                        "type2": 9856,
                        "type3": 0,
                        "type4": 8283,
                        "type5": 0,
                        "type6": 8917,
                        "type7": 5735,
                        "type8": 7486
                    },
                    {
                        "Date": "2021-06-29",
                        "type1": 11501,
                        "type2": 0,
                        "type3": 0,
                        "type4": 0,
                        "type5": 10687,
                        "type6": 0,
                        "type7": 0,
                        "type8": 0
                    }
                ]
            },
            "encoding": {
                "opacity": {
                    "condition": {
                        "empty": false,
                        "param": "param_46",
                        "value": 0.2
                    },
                    "value": 0
                },
                "size": {
                    "value": 4
                },
                "tooltip": [{
                    "field": "Date",
                    "type": "nominal"
                }, {
                    "field": "type1",
                    "type": "quantitative"
                }, {
                    "field": "type2",
                    "type": "quantitative"
                }, {
                    "field": "type3",
                    "type": "quantitative"
                }, {
                    "field": "type4",
                    "type": "quantitative"
                }, {
                    "field": "type5",
                    "type": "quantitative"
                }, {
                    "field": "type6",
                    "type": "quantitative"
                }, {
                    "field": "type7",
                    "type": "quantitative"
                }, {
                    "field": "type8",
                    "type": "quantitative"
                }],
                "x": {
                    "field": "Date",
                    "title": null,
                    "type": "ordinal"
                }
            },
            "mark": {
                "type": "rule"
            },
            "params": [{
                "name": "param_46",
                "select": {
                    "clear": "mouseout",
                    "fields": ["Date"],
                    "nearest": true,
                    "on": "mouseover",
                    "type": "point"
                }
            }]
        }
    ]
}
original1 original2

With filter:

{
    "config": {
        "view": {
            "continuousHeight": 300,
            "continuousWidth": 300
        }
    },
    "layer": [{
            "data": {
                "values": [{
                        "Date": "2021-06-29",
                        "Type": "type7",
                        "Value": 0
                    },
                    {
                        "Date": "2021-06-29",
                        "Type": "type4",
                        "Value": 0
                    },
                    {
                        "Date": "2021-06-29",
                        "Type": "type5",
                        "Value": 10687
                    },
                    {
                        "Date": "2021-06-29",
                        "Type": "type1",
                        "Value": 11501
                    },
                    {
                        "Date": "2021-06-29",
                        "Type": "type3",
                        "Value": 0
                    },
                    {
                        "Date": "2021-06-22",
                        "Type": "type7",
                        "Value": 5735
                    },
                    {
                        "Date": "2021-06-22",
                        "Type": "type8",
                        "Value": 7486
                    },
                    {
                        "Date": "2021-06-22",
                        "Type": "type1",
                        "Value": 8283
                    },
                    {
                        "Date": "2021-06-22",
                        "Type": "type4",
                        "Value": 8283
                    },
                    {
                        "Date": "2021-06-22",
                        "Type": "type6",
                        "Value": 8917
                    },
                    {
                        "Date": "2021-06-22",
                        "Type": "type2",
                        "Value": 9856
                    }
                ]

            },
            "encoding": {
                "color": {
                    "field": "Type",
                    "type": "nominal"
                },
                "order": {
                    "field": "Value",
                    "sort": "ascending",
                    "type": "quantitative"
                },
                "x": {
                    "field": "Date",
                    "type": "ordinal"
                },
                "y": {
                    "field": "Value",
                    "type": "quantitative"
                }
            },
            "mark": {
                "type": "bar"
            }

        },
        {
            "data": {
                "values": [{
                        "Date": "2021-06-22",
                        "type1": 8283,
                        "type2": 9856,
                        "type3": 0,
                        "type4": 8283,
                        "type5": 0,
                        "type6": 8917,
                        "type7": 5735,
                        "type8": 7486
                    },
                    {
                        "Date": "2021-06-29",
                        "type1": 11501,
                        "type2": 0,
                        "type3": 0,
                        "type4": 0,
                        "type5": 10687,
                        "type6": 0,
                        "type7": 0,
                        "type8": 0
                    }
                ]
            },
            "encoding": {
                "opacity": {
                    "condition": {
                        "empty": false,
                        "param": "param_46",
                        "value": 0.2
                    },
                    "value": 0
                },
                "size": {
                    "value": 4
                },
                "tooltip": [{
                    "field": "Date",
                    "type": "nominal"
                }, {
                    "field": "type1",
                    "type": "quantitative",
                    "**filter**": {
                        "operator": ">",
                        "literal": 0
                    }
                }, {
                    "field": "type2",
                    "type": "quantitative",
                    "**filter**": {
                        "operator": ">",
                        "literal": 0
                    }
                }, {
                    "field": "type3",
                    "type": "quantitative",
                    "**filter**": {
                        "operator": ">",
                        "literal": 0
                    }
                }, {
                    "field": "type4",
                    "type": "quantitative",
                    "**filter**": {
                        "operator": ">",
                        "literal": 0
                    }
                }, {
                    "field": "type5",
                    "type": "quantitative",
                    "**filter**": {
                        "operator": ">",
                        "literal": 0
                    }
                }, {
                    "field": "type6",
                    "type": "quantitative",
                    "**filter**": {
                        "operator": ">",
                        "literal": 0
                    }
                }, {
                    "field": "type7",
                    "type": "quantitative",
                    "**filter**": {
                        "operator": ">",
                        "literal": 0
                    }
                }, {
                    "field": "type8",
                    "type": "quantitative",
                    "**filter**": {
                        "operator": ">",
                        "literal": 0
                    }
                }],
                "x": {
                    "field": "Date",
                    "title": null,
                    "type": "ordinal"
                }
            },
            "mark": {
                "type": "rule"
            },
            "params": [{
                "name": "param_46",
                "select": {
                    "clear": "mouseout",
                    "fields": ["Date"],
                    "nearest": true,
                    "on": "mouseover",
                    "type": "point"
                }
            }]
        }
    ]
}
filter1 filter2

With sort:

{
    "config": {
        "view": {
            "continuousHeight": 300,
            "continuousWidth": 300
        }
    },
    "layer": [{
            "data": {
                "values": [{
                        "Date": "2021-06-29",
                        "Type": "type7",
                        "Value": 0
                    },
                    {
                        "Date": "2021-06-29",
                        "Type": "type4",
                        "Value": 0
                    },
                    {
                        "Date": "2021-06-29",
                        "Type": "type5",
                        "Value": 10687
                    },
                    {
                        "Date": "2021-06-29",
                        "Type": "type1",
                        "Value": 11501
                    },
                    {
                        "Date": "2021-06-29",
                        "Type": "type3",
                        "Value": 0
                    },
                    {
                        "Date": "2021-06-22",
                        "Type": "type7",
                        "Value": 5735
                    },
                    {
                        "Date": "2021-06-22",
                        "Type": "type8",
                        "Value": 7486
                    },
                    {
                        "Date": "2021-06-22",
                        "Type": "type1",
                        "Value": 8283
                    },
                    {
                        "Date": "2021-06-22",
                        "Type": "type4",
                        "Value": 8283
                    },
                    {
                        "Date": "2021-06-22",
                        "Type": "type6",
                        "Value": 8917
                    },
                    {
                        "Date": "2021-06-22",
                        "Type": "type2",
                        "Value": 9856
                    }
                ]

            },
            "encoding": {
                "color": {
                    "field": "Type",
                    "type": "nominal"
                },
                "order": {
                    "field": "Value",
                    "sort": "ascending",
                    "type": "quantitative"
                },
                "x": {
                    "field": "Date",
                    "type": "ordinal"
                },
                "y": {
                    "field": "Value",
                    "type": "quantitative"
                }
            },
            "mark": {
                "type": "bar"
            }

        },
        {
            "data": {
                "values": [{
                        "Date": "2021-06-22",
                        "type1": 8283,
                        "type2": 9856,
                        "type3": 0,
                        "type4": 8283,
                        "type5": 0,
                        "type6": 8917,
                        "type7": 5735,
                        "type8": 7486
                    },
                    {
                        "Date": "2021-06-29",
                        "type1": 11501,
                        "type2": 0,
                        "type3": 0,
                        "type4": 0,
                        "type5": 10687,
                        "type6": 0,
                        "type7": 0,
                        "type8": 0
                    }
                ]
            },
            "encoding": {
                "opacity": {
                    "condition": {
                        "empty": false,
                        "param": "param_46",
                        "value": 0.2
                    },
                    "value": 0
                },
                "size": {
                    "value": 4
                },
                "tooltip": [{
                    "field": "Date",
                    "type": "nominal"
                }, {
                    "field": "type1",
                    "type": "quantitative"
                }, {
                    "field": "type2",
                    "type": "quantitative"
                }, {
                    "field": "type3",
                    "type": "quantitative"
                }, {
                    "field": "type4",
                    "type": "quantitative"
                }, {
                    "field": "type5",
                    "type": "quantitative"
                }, {
                    "field": "type6",
                    "type": "quantitative"
                }, {
                    "field": "type7",
                    "type": "quantitative"
                }, {
                    "field": "type8",
                    "type": "quantitative"
                }],
                "**sort_tooltip**": {
                    "value": "ascending"
                },
                "x": {
                    "field": "Date",
                    "title": null,
                    "type": "ordinal"
                }
            },
            "mark": {
                "type": "rule"
            },
            "params": [{
                "name": "param_46",
                "select": {
                    "clear": "mouseout",
                    "fields": ["Date"],
                    "nearest": true,
                    "on": "mouseover",
                    "type": "point"
                }
            }]
        }
    ]
}
sort1 sort2

With filter & sort:

{
    "config": {
        "view": {
            "continuousHeight": 300,
            "continuousWidth": 300
        }
    },
    "layer": [{
            "data": {
                "values": [{
                        "Date": "2021-06-29",
                        "Type": "type7",
                        "Value": 0
                    },
                    {
                        "Date": "2021-06-29",
                        "Type": "type4",
                        "Value": 0
                    },
                    {
                        "Date": "2021-06-29",
                        "Type": "type5",
                        "Value": 10687
                    },
                    {
                        "Date": "2021-06-29",
                        "Type": "type1",
                        "Value": 11501
                    },
                    {
                        "Date": "2021-06-29",
                        "Type": "type3",
                        "Value": 0
                    },
                    {
                        "Date": "2021-06-22",
                        "Type": "type7",
                        "Value": 5735
                    },
                    {
                        "Date": "2021-06-22",
                        "Type": "type8",
                        "Value": 7486
                    },
                    {
                        "Date": "2021-06-22",
                        "Type": "type1",
                        "Value": 8283
                    },
                    {
                        "Date": "2021-06-22",
                        "Type": "type4",
                        "Value": 8283
                    },
                    {
                        "Date": "2021-06-22",
                        "Type": "type6",
                        "Value": 8917
                    },
                    {
                        "Date": "2021-06-22",
                        "Type": "type2",
                        "Value": 9856
                    }
                ]

            },
            "encoding": {
                "color": {
                    "field": "Type",
                    "type": "nominal"
                },
                "order": {
                    "field": "Value",
                    "sort": "ascending",
                    "type": "quantitative"
                },
                "x": {
                    "field": "Date",
                    "type": "ordinal"
                },
                "y": {
                    "field": "Value",
                    "type": "quantitative"
                }
            },
            "mark": {
                "type": "bar"
            }

        },
        {
            "data": {
                "values": [{
                        "Date": "2021-06-22",
                        "type1": 8283,
                        "type2": 9856,
                        "type3": 0,
                        "type4": 8283,
                        "type5": 0,
                        "type6": 8917,
                        "type7": 5735,
                        "type8": 7486
                    },
                    {
                        "Date": "2021-06-29",
                        "type1": 11501,
                        "type2": 0,
                        "type3": 0,
                        "type4": 0,
                        "type5": 10687,
                        "type6": 0,
                        "type7": 0,
                        "type8": 0
                    }
                ]
            },
            "encoding": {
                "opacity": {
                    "condition": {
                        "empty": false,
                        "param": "param_46",
                        "value": 0.2
                    },
                    "value": 0
                },
                "size": {
                    "value": 4
                },
                "tooltip": [{
                    "field": "Date",
                    "type": "nominal"
                }, {
                    "field": "type1",
                    "type": "quantitative",
                    "**filter**": {
                        "operator": ">",
                        "literal": 0
                    }
                }, {
                    "field": "type2",
                    "type": "quantitative",
                    "**filter**": {
                        "operator": ">",
                        "literal": 0
                    }
                }, {
                    "field": "type3",
                    "type": "quantitative",
                    "**filter**": {
                        "operator": ">",
                        "literal": 0
                    }
                }, {
                    "field": "type4",
                    "type": "quantitative",
                    "**filter**": {
                        "operator": ">",
                        "literal": 0
                    }
                }, {
                    "field": "type5",
                    "type": "quantitative",
                    "**filter**": {
                        "operator": ">",
                        "literal": 0
                    }
                }, {
                    "field": "type6",
                    "type": "quantitative",
                    "**filter**": {
                        "operator": ">",
                        "literal": 0
                    }
                }, {
                    "field": "type7",
                    "type": "quantitative",
                    "**filter**": {
                        "operator": ">",
                        "literal": 0
                    }
                }, {
                    "field": "type8",
                    "type": "quantitative",
                    "**filter**": {
                        "operator": ">",
                        "literal": 0
                    }
                }],
                "**sort_tooltip**": {
                    "value": "descending"
                },
                "x": {
                    "field": "Date",
                    "title": null,
                    "type": "ordinal"
                }
            },
            "mark": {
                "type": "rule"
            },
            "params": [{
                "name": "param_46",
                "select": {
                    "clear": "mouseout",
                    "fields": ["Date"],
                    "nearest": true,
                    "on": "mouseover",
                    "type": "point"
                }
            }]
        }
    ]
}
filtersort1 filtersort2

To make the new parameters robust, both filter & sort_tooltip can only be some enum values.
filter.operator: one of '==', '!=', '<', '<=', '>', '>='
filter.literal: one of type string, number or boolean.
"filter": {"operator": "><", "literal": 0}:
Screenshot 2023-10-23 at 10 27 08 AM

sort_tooltip.value: 'ascending' or 'descending' only:
"sort_tooltip": {"value": "whatever"}
Screenshot 2023-10-23 at 10 26 35 AM

PR to vega-tooltip: vega/vega-tooltip#820

This along with vega/vega-tooltip#820 are to fix #9152

cc: @joelostblom @jakevdp @kanitw @domoritz @arvind @jheer

@domoritz
Copy link
Member

Thanks for the pull request. Can you explain the reasoning for his change and the proposed API changes in the description of the pull request? Please also highlight the changes in the specs and format them to be readable. I don't think I can quite follow the suggestion here.

Once we have reviewed the API proposal, please make sure the tests and CI runs pass.

@domoritz
Copy link
Member

Is this supposed to fix #9152? If so, please reference the issue in the description.

@domoritz domoritz changed the title Add filter and sort support for vega tooltip. feat: add filter and sort support for tooltips Oct 23, 2023
@domoritz
Copy link
Member

I think we need a more detailed API proposal in #9152. I added comments there. Let's put this pull request on hold until we resolved the API discussion.

@domoritz domoritz marked this pull request as draft October 23, 2023 00:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Filtering out zero/null values in tooltip and sort the tooltip by field values
2 participants