I have a signal initiated as an empty array and I'd like to add and remove string values from this array dynamically.
The array functions in Vega seem limited, for example it seems I can check if a value is in the array:
indexof(array, value) >= 0
Is it possible to somehow add and remove values from this array? For example:
indexof(array, value) >= 0 ? array.remove(value) : array.add(value)
As I don't care about position, this would be acting like a set, but I'm not aware if Vega has a set data structure.
Not really. From memory, there are very clunky, non-performant ways to do it with strings but they are not recommended at all.
The best way to do it is to create a dataset and add, modify or remove data from it (possibly using triggers). For example, the Gantt chart needs to keep track of which phases are collapsed and add or remove elements (like an array). These are stored in the collapsedPhases dataset. This is also how VL handles selections by using a dedicated dataset to store objects.
https://github.com/PBI-David/Deneb-Showcase?tab=readme-ov-file#gantt-chart