Skip to content
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

legends and scales #484

Closed
wants to merge 44 commits into from
Closed

legends and scales #484

wants to merge 44 commits into from

Conversation

Fil
Copy link
Contributor

@Fil Fil commented Aug 5, 2021

(rebased #432)

build at https://observablehq.com/@fil/plot-color-legend-484

closes #23
closes #236

related: #397 #92 #425

TODO:

Fil and others added 30 commits May 29, 2021 14:59
accepts a function that receives the scale; if that function returns a DOM node, adds it to the figure.
… be used to recreate the scale in another plot. In particular it doesn't show the (D3) scale anymore. Instead, a convenience function Plot.scale(options) is provided, that will turn a scale *options* object into a D3 scale, ready to use in another context. (This also clears the question of mutability.)
Co-authored-by: Mike Bostock <mbostock@gmail.com>
Co-authored-by: Mike Bostock <mbostock@gmail.com>
ensure we don't compute the scale options twice
always return label, clamp, type
…", "identity")

and type ("utc", "time" / "linear", "sqrt", "log"… / "categorical" / "identity")
except the following which are part of the definition of:
scale.domain() // domain, nice,
scale.range() // range, inset, reverse,
scale.interpolate() // interpolate, clamp, round
paddingInner & paddingOuter // padding
@yurivish
Copy link
Contributor

yurivish commented Aug 5, 2021

Is there a way to configure the positioning of the legend with respect to the plot, e.g. above or below, when using the legend: true form?

In the linked notebook, I noticed that all of the examples like the one below had the legend appearing above the plot:

Plot.dot({length: 100}, {x: Math.random, fill: Math.random})
  .plot({ color: {legend: true, label: "random", width: 120, nice: true }})

@Fil
Copy link
Contributor Author

Fil commented Aug 5, 2021

No, there is no such thing for the moment. We'll probably want some configurability but we don't want to invent a new layout engine :) What you can already do, is to create the legend separately (as shown in a few of the examples). Alternatively, move it inside the figure element with d3.select?.

This was referenced Aug 5, 2021
@mbostock
Copy link
Member

mbostock commented Aug 5, 2021

I wanted to work on landing exposing scales first before tackling legends. Ref. #425 (comment)

@Fil
Copy link
Contributor Author

Fil commented Aug 5, 2021

In the two other branches we had accumulated quite a bit of conflict with main, and I wanted to clear that. But feel free to remove anything from this PR (I think the legend part is well separated).

About the issue of exposing Plot.scale(options) or not, I think that there will be a way around in any case if we expose the d3 scale: something like Plot.plot({ color: options }).scales.color.scale.

@mbostock
Copy link
Member

mbostock commented Aug 5, 2021

My preference for scales would be to just expose the materialized options (type, domain, range, etc.) with the goal of being able to take a scale constructed from one chart and propagate it to another chart; I would prefer not to expose a D3 scale instance or a scale function. We removed most of the need for that in #280 by precomputing the scaled channels, though scales still have access to the scale functions… which is a little messy. In my ideal world the implementation of scales would be hidden so that we have more flexibility in changing the implementation.

Edit: Hiding the scale function/instance is not a firmly-held conviction, just my initial inclination.

@Fil
Copy link
Contributor Author

Fil commented Aug 5, 2021

I'm good with this plan (including not exposing the d3 scale); it still gives enough information to re-create the scale outside of Plot if necessary.

Fil and others added 7 commits August 19, 2021 17:46
Fixed conflict: src/scales/quantitative.js
* coerce to the scale’s type

* upgrade isoformat

* document type coercion

* language

* changelog

* update CHANGELOG

* coerce invalid dates to undefined

* update README

* update README

Co-authored-by: Philippe Rivière <fil@rezo.net>
The `src/style.css` file is not kept in the distributed ES module. Keeping it would allow to import it directly and keep it up to date when using Plot from a package manager.
* fix #379; universal dx and dy

On all marks except text, dx and dy are rendered as a transform
(translate) property, possibly with the 0.5px offset on high-density
screens. On text marks, the dx and dy properties are used.

* update README

Co-authored-by: Mike Bostock <mbostock@gmail.com>
This was referenced Sep 10, 2021
@Fil Fil marked this pull request as draft September 16, 2021 11:23
@mbostock
Copy link
Member

mbostock commented Nov 26, 2021

Superseded by #539 #583.

@mbostock mbostock closed this Nov 26, 2021
@Fil Fil deleted the fil/legends-again branch November 27, 2021 10:03
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.

radius legend? Color legend.
4 participants