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

Scale convenience constructors. #157

Closed
65 tasks done
mbostock opened this issue Jan 6, 2019 · 4 comments
Closed
65 tasks done

Scale convenience constructors. #157

mbostock opened this issue Jan 6, 2019 · 4 comments

Comments

@mbostock
Copy link
Member

mbostock commented Jan 6, 2019

It’d be lovely to say

x = d3.scaleLinear(domain, range)

as shorthand for

x = d3.scaleLinear().domain(domain).range(range)

Fleshing out the full list, including the new transformed scales #156:

  • scaleBand() // domain = [], range = [0, 1]
  • scaleBand(range) // domain = []
  • scaleBand(domain, range)
  • scalePoint() // domain = [], range = [0, 1]
  • scalePoint(range) // domain = []
  • scalePoint(domain, range)
  • scaleIdentity() // domain = range = [0, 1]
  • scaleIdentity(range) // domain = range
  • scaleLinear() // domain = [0, 1], range = [0, 1]
  • scaleLinear(range) // domain = [0, 1]
  • scaleLinear(domain, range)
  • scaleLog() // domain = [1, 10], range = [0, 1], base = 10
  • scaleLog(range) // domain = [1, 10], base = 10
  • scaleLog(domain, range) // base = 10
  • scaleOrdinal() // domain = [], range = []
  • scaleOrdinal(range) // domain = []
  • scaleOrdinal(domain, range)
  • scalePow() // domain = [0, 1], range = [0, 1], exponent = 1
  • scalePow(range) // domain = [0, 1], exponent = 1
  • scalePow(domain, range) // exponent = 1
  • scaleSqrt() // domain = [0, 1], range = [0, 1]
  • scaleSqrt(range) // domain = [0, 1]
  • scaleSqrt(domain, range)
  • scaleQuantile() // domain = [], range = []
  • scaleQuantile(range) // domain = []
  • scaleQuantile(domain, range)
  • scaleQuantize() // domain = [0.5], range = [0, 1]
  • scaleQuantize(range) // domain = [0.5]
  • scaleQuantize(domain, range)
  • scaleThreshold() // domain = [0.5], range = [0, 1]
  • scaleThreshold(range) // domain = [0.5]
  • scaleThreshold(domain, range)
  • scaleTime() // domain = [2000-01-01, 2000-01-02], range = [0, 1]
  • scaleTime(range) // domain = [2000-01-01, 2000-01-02]
  • scaleTime(domain, range)
  • scaleUtc() // domain = [2000-01-01Z, 2000-01-02Z], range = [0, 1]
  • scaleUtc(range) // domain = [2000-01-01Z, 2000-01-02Z]
  • scaleUtc(domain, range)
  • scaleSequential() // interpolator = identity
  • scaleSequential(interpolator) // domain = [0, 1]
  • scaleSequential(domain, interpolator)
  • scaleSequentialLog() // interpolator = identity, domain = [1, 10], base = 10
  • scaleSequentialLog(interpolator) // domain = [1, 10], base = 10
  • scaleSequentialLog(domain, interpolator) // base = 10
  • scaleSequentialPow() // interpolator = identity, domain = [0, 1], exponent = 1
  • scaleSequentialPow(interpolator) // domain = [0, 1], exponent = 1
  • scaleSequentialPow(domain, interpolator) // exponent = 1
  • scaleSequentialSqrt() // interpolator = identity, domain = [0, 1]
  • scaleSequentialSqrt(interpolator) // domain = [0, 1]
  • scaleSequentialSqrt(domain, interpolator)
  • scaleSequentialQuantile() // interpolator = identity, domain = []
  • scaleSequentialQuantile(interpolator) // domain = []
  • scaleSequentialQuantile(domain, interpolator)
  • scaleDiverging() // interpolator = identity, domain = [0, 0.5, 1]
  • scaleDiverging(interpolator) // domain = [0, 0.5, 1]
  • scaleDiverging(domain, interpolator)
  • scaleDivergingLog() // interpolator = identity, domain = [0.1, 1, 10], base = 10
  • scaleDivergingLog(interpolator) // domain = [0.1, 1, 10], base = 10
  • scaleDivergingLog(domain, interpolator) // base = 10
  • scaleDivergingPow() // interpolator = identity, domain = [0, 0.5, 1], exponent = 1
  • scaleDivergingPow(interpolator) // domain = [0, 0.5, 1], exponent = 1
  • scaleDivergingPow(domain, interpolator) // exponent = 1
  • scaleDivergingSqrt() // interpolator = identity, domain = [0, 0.5, 1]
  • scaleDivergingSqrt(interpolator) // domain = [0, 0.5, 1]
  • scaleDivergingSqrt(domain, interpolator)

Bold are existing scale constructors in master.

@mbostock mbostock changed the title Scale convenience constructor. Scale convenience constructors. Jan 6, 2019
@mbostock mbostock mentioned this issue Jan 6, 2019
Merged
13 tasks
@mbostock
Copy link
Member Author

mbostock commented Jan 25, 2019

68 70 89 67 62 constructors! 😮 23 existing constructors checked.

@mbostock
Copy link
Member Author

mbostock commented Jan 25, 2019

An additional 22 variants if we want to allow the log base and pow exponent specified in the constructor—but I don’t think it’s worth the added complexity.

  • scaleLog(base) // domain = [1, 10], range = [0, 1]
  • scaleLog(range, base) // domain = [1, 10]
  • scaleLog(domain, range, base)
  • scalePow(exponent) // domain = [0, 1], range = [0, 1]
  • scalePow(range, exponent) // domain = [0, 1]
  • scalePow(domain, range, exponent)
  • scaleSequentialLog(base) // interpolator = identity, domain = [1, 10]
  • scaleSequentialLog(interpolator, base) // domain = [1, 10]
  • scaleSequentialLog(domain, base) // interpolator = identity
  • scaleSequentialLog(domain, interpolator, base)
  • scaleSequentialPow(exponent) // interpolator = identity, domain = [1, 10]
  • scaleSequentialPow(interpolator, exponent) // domain = [0, 1]
  • scaleSequentialPow(domain, exponent) // interpolator = identity
  • scaleSequentialPow(domain, interpolator, exponent)
  • scaleDivergingLog(base) // interpolator = identity, domain = [0.1, 1, 10]
  • scaleDivergingLog(interpolator, base) // domain = [0.1, 1, 10]
  • scaleDivergingLog(domain, base) // interpolator = identity
  • scaleDivergingLog(domain, interpolator, base)
  • scaleDivergingPow(exponent) // interpolator = identity, domain = [0, 0.5, 1]
  • scaleDivergingPow(interpolator, exponent) // domain = [0, 0.5, 1]
  • scaleDivergingPow(domain, exponent) // interpolator = identity
  • scaleDivergingPow(domain, interpolator, exponent)

@mbostock
Copy link
Member Author

An additional 5 variants if we want to specify the domain but not interpolator—which again, I don’t think is worth it.

  • scaleSequentialLog(domain) // interpolator = identity, base = 10
  • scaleSequentialPow(domain) // interpolator = identity, exponent = 1
  • scaleDivergingPow(domain) // interpolator = identity, exponent = 1
  • scaleDivergingSqrt(domain) // interpolator = identity
  • scaleDivergingLog(domain) // interpolator = identity, base = 10

@mbostock
Copy link
Member Author

The top approach has a nice property in that all scales have the same three constructor forms:

  • a default constructor (0 arguments)
  • a range-only constructor (where range = interpolator as appropriate)
  • a domain-and-range constructor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant