Title: Bindings · Issue #1002 · plotly/plotly.js · GitHub
Open Graph Title: Bindings · Issue #1002 · plotly/plotly.js
X Title: Bindings · Issue #1002 · plotly/plotly.js
Description: As controls get more capable in plotly, two-way binding becomes necessary. That is, a slider can change the frame, but the slider should also reflect the current frame when something else (e.g. a play button) changes it. This could also ...
Open Graph Description: As controls get more capable in plotly, two-way binding becomes necessary. That is, a slider can change the frame, but the slider should also reflect the current frame when something else (e.g. a p...
X Description: As controls get more capable in plotly, two-way binding becomes necessary. That is, a slider can change the frame, but the slider should also reflect the current frame when something else (e.g. a p...
Opengraph URL: https://github.com/plotly/plotly.js/issues/1002
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Bindings","articleBody":"As controls get more capable in plotly, two-way binding becomes necessary. That is, a slider can change the frame, but the slider should also reflect the current frame when something else (e.g. a play button) changes it. This could also be the case for a marker size, a size ref, or a transform parameter. My current [slider PR](https://github.com/plotly/plotly.js/pull/986) does this in sort of [an ad hoc manner](https://github.com/plotly/plotly.js/pull/986/files#diff-8e9a79b541026f6567178f4c9d990c99R81), but I really think it should be more general.\n\n**Proposal**: `bindings`\n\n**Option 1**:\n\nBindings are defined in the layout. For example: \n\n``` json\n\"layout\": {\n \"bindings\": [{\n \"bind\": \"layout.updatemenus[0].active\",\n \"to\": \"data[0].marker.color\",\n \"lookup\": {\n \"red\": 0,\n \"green\": 1,\n \"blue\": 2\n }\n }]\n}\n```\n\nIn this example, `bind` is the data that gets changed, `to` is the item that's observed for changes, and `lookup` is an optional translation table that maps one to the other. Whenever a plotly event is emitted or when a relayout/restyle/update occurs, we quickly look through the bindings to see what's changed (which shouldn't be expensive enough that it's a problem). If an item has changed, that item is written to the state of the plot. A `plotly_bindingchange` event is emitted. _All_ components (that's the best I can do right now) must then look through their data to see if anything has changed and update accordingly.\n\n_Pros_:\n- Bindings link two parts of the plotly state, which accurately represents what's actually happening\n\n_Cons_:\n- Updates take just a bit of thought and bookkeeping to do efficiently since this isn't react\n- requires a separate specification of bindings in addition to just the slider\n- refers to other parts of the plotly json by integer index within the plotly json, which seems probably okay but 10% fragile\n\n**Option 2**:\n\nBindings are defined in the component that needs them, e.g. a slider. The slider has:\n\n``` json\n\"bindto\": \"data[0].marker.color\"\n```\n\nMost of the logic is the same. (I've omitted the lookup table since, though it could be added, we should probably go to great lengths to generally avoid _needing_.) When a component binds to a variable, we register it as needing a lookup. We scan through those liberally since it's fast, and when one changes, we emit an event. This case is a little simpler since we can emit `plotly_bindingchange` with data `{binding: 'data[0].marker.color', value: 'red'}`. The component sees its binding has changed and updates accordingly.\n\n_Pros_:\n- Requires less typing\n- Collocates binding with the thing that uses the binding\n- Avoids extra reference to `updatemenus[0].active`\n- The update pattern is maybe a bit more straightforward since the component directly knows about the binding.\n\n_Cons_:\n- Less general since it specifies a way of hooking up a component to a json item instead of hooking up a json item to a json item\n\ncc: @etpinard @chriddyp @alexcjohnson \n","author":{"url":"https://github.com/rreusser","@type":"Person","name":"rreusser"},"datePublished":"2016-10-04T14:57:10Z","url":"https://github.com/plotly/plotly.js/issues/1002"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:3d982ac0-987c-93ff-1c27-3046de4a5fbc |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B96E:136CDA:10AC623:161C2F1:6B01E1E7 |
| html-safe-nonce | d144a1c796f07ec50a57e0d259c959c92c6944f3648bddd473de8d470a245083 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCOTZFOjEzNkNEQToxMEFDNjIzOjE2MUMyRjE6NkIwMUUxRTciLCJ2aXNpdG9yX2lkIjoiODYwNDIyNzMxNzI0MzQzNzU0MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | c976da20edddf6cf84b992819811594eb871a0dccecf8c105e0c0fce24e145d8 |
| hovercard-subject-tag | issue:180917144 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/plotly/plotly.js/1002/issue_layout |
| twitter:image | https://opengraph.githubassets.com/69c3c56f849bacec31acae0d3f8578e9b0fb1e022b0eb706a28960fea57d8744/plotly/plotly.js/issues/1002 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/69c3c56f849bacec31acae0d3f8578e9b0fb1e022b0eb706a28960fea57d8744/plotly/plotly.js/issues/1002 |
| og:image:alt | As controls get more capable in plotly, two-way binding becomes necessary. That is, a slider can change the frame, but the slider should also reflect the current frame when something else (e.g. a p... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | rreusser |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/plotly/plotly.js git https://github.com/plotly/plotly.js.git |
| octolytics-dimension-user_id | 5997976 |
| octolytics-dimension-user_login | plotly |
| octolytics-dimension-repository_id | 45646037 |
| octolytics-dimension-repository_nwo | plotly/plotly.js |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 45646037 |
| octolytics-dimension-repository_network_root_nwo | plotly/plotly.js |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width