[Feat] Advanced expressions for view positioning
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 14.6k
- Forks
- 2.3k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 42
Description
Target Use Case
As of v8.7, a View constructor can specify its position (x, y, width and height) as either an absolute value (number of pixels) or a relative value (percentage of with/height). With the current system, it is not possible to achieve the following without constructing new View instances on each resize:
- Place a fixed-sized view at the bottom right corner
- Make a view that has relative width/height, but no bigger than an absolute value
- Make a view that has responsive width/height, but fixed aspect ratio
- Hide a minimap when the window is too small
- More generically, define a layout with "breakpoints" -- use different values based on the canvas width
Proposal
Solution 1: Accept callback functions
We can allow callback functions to be passed to a View's x, y, width and height. The callback may receive the canvas width and height as arguments at the time of evaluation. This will be very easy to implement and gives users the maximum flexibility when it comes to dynamic positioning.
I have experimented with this approach in a custom View class. My observation is that when trying to create sophisticated layouts, an application ends up having to pass separate functions to all four props, in which it repeats the same branching logic, then returns the respective values. The definition of a view can therefore be quite verbose. Moreover, callbacks in general are not as readable as CSS-like strings, and becomes harder to maintain over time.
@ibgreen has also brought up the use case of declarative/pydeck/JSON transport, where callbacks are not an option.
Solution 2: Extended syntax for expressions
This approach allows other string values to be passed to the positioning props. Under the hood, the parser will create a callback function from the expression. Here I'm attempting to start a list of such possible expressions, drawing inspiration from CSS math functions:
+and-operators, e.g.100% - 100pxmin,maxandclampfunctions, e.g.max(25%, 50px)- New units
w(canvas width) andh(canvas height), e.g.min(0.5w, 0.5h)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the View constructor's x, y, width, and height positioning implementation introduced in v8.7. The issue presents callback and expression approaches but names no files, tests, chosen syntax, or acceptance criteria; first resolve that design decision, then define how completion will be verified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- data-visualization, frontend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100