Skip to content

Feature: array & objects are difficult to handle #33

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

Open
BQXBQX opened this issue Apr 2, 2025 · 3 comments
Open

Feature: array & objects are difficult to handle #33

BQXBQX opened this issue Apr 2, 2025 · 3 comments

Comments

@BQXBQX
Copy link
Collaborator

BQXBQX commented Apr 2, 2025

When i write some demo for expr, i meet a problem:
If you don't use register to define your own functions and only use template syntax, it is difficult to handle arrays and objects.Here is an example:

const spec = {
        type: 'line',
        height: 400,
        width: 540,
        legend: false,
        y: 300,
        encode: {
            x: 'name',
            y: 'value'
        },
        scale: {
            y: {
                independent: true
            }
        },
        labels: [{
            text: '{a.value}',
           // here is the problem, how to filter this array 🤔
            selector: '{a}',
        }, ],
        axis: {
            y: {
                position: 'right',
                grid: null,
            },
        },
    },
}

I want to filter only the data of a certain index in the labels selector, but it is difficult to handle using only template syntax.

@BQXBQX
Copy link
Collaborator Author

BQXBQX commented Apr 2, 2025

Solution

  1. While using expr to provide template capabilities, open a way to get register capabilities for your developers
  2. We will extend a plugin to provide some array and object processing toolkits that are safer and more suitable for expr template syntax. This toolkit can be provided by us as a dependent package, which can be optionally integrated without increasing the size of the core code.

@hustcc
Copy link
Member

hustcc commented Apr 2, 2025

I don't think it's necessary to consider, the selector itself has a simplified string enum value syntax.

@antvis antvis deleted a comment from BQXBQX Apr 8, 2025
@hustcc
Copy link
Member

hustcc commented Apr 8, 2025

Reference: https://tedboy.github.io/jinja2/templ14.html

data | map(type="sports")

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

No branches or pull requests

2 participants