Skip to content

idea: introduce a callback mechanism? #67

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

Closed
wants to merge 2 commits into from
Closed

idea: introduce a callback mechanism? #67

wants to merge 2 commits into from

Conversation

Fil
Copy link
Contributor

@Fil Fil commented Dec 22, 2020

…or maybe a Promise system?

so we can easily tweak the returned layer, for example here to introduce a bar width’s transition.

This is mostly for discussion (there is no API in this PR to send the callback!)

In this commit, the callback receives the SVG layer node (or null if there is no node), and index, scales, channels, dimensions.

Application: the following callback fades-in the bars

        callback: (node) => d3.select(node).selectAll("rect").attr("width", function() {
          this.setAttribute("__w", this.getAttribute("width"))
          return 0;
        }).transition().attr("width", function() {
          const w = this.getAttribute("__w");
          this.removeAttribute("__w");
          return w;
        })
Enregistrement.de.l.ecran.2020-12-22.a.15.44.09.mov

Another use case would be in Plot.carto where I’d probably want to return a map with the data points, but load a detailed topojson background asynchronously.

Or… append a force simulation to Plot.dot and Plot.text and avoid superpositions or label occlusion.

…or maybe a Promise system?

so we can easily tweak the returned layer, for example here to introduce a bar width’s transition.
@Fil Fil changed the title idea: introduce a callback mechanism idea: introduce a callback mechanism? Dec 22, 2020
@Fil
Copy link
Contributor Author

Fil commented Feb 14, 2021

Here's another example where a callback could be useful (though it also works if I just massage the mark's {render} ):
https://observablehq.com/d/d2bb9c593bd5dd98#topAreaY

@Fil
Copy link
Contributor Author

Fil commented May 1, 2021

a simple (hackish?) method is to wrap the mark in a function that calls the original render and plays with the result

@Fil Fil closed this May 1, 2021
@Fil Fil deleted the callback branch May 1, 2021 05:13
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.

1 participant