Skip to content
This repository has been archived by the owner on Dec 10, 2021. It is now read-only.

feat(color): support better color interpolation for sequential schemes #547

Merged
merged 4 commits into from
May 28, 2020

Conversation

kristw
Copy link
Contributor

@kristw kristw commented May 27, 2020

🏆 Enhancements

  • add modifyRange option to createLinearScale(domain, modifyRange = false). This extends the original behavior that always modify domain if needed.
   * Return a linear scale with a new domain interpolated from the input domain
   * to match the number of elements in the color scheme
   * because D3 continuous scale uses piecewise mapping between domain and range.
   * This is a common use-case when the domain is [min, max]
   * and the palette has more than two colors.
   *
   * @param domain domain of the scale
   * @param modifyRange Set this to true if you don't want to modify the domain and
   * want to interpolate range to have the same number of elements with domain instead.
  • add extent option for .getColors(numColors, extent) to reduce the range of the color scheme, inspired SchemeParams option in vega-lite
   * Get colors from this scheme
   * @param numColors number of colors to return.
   * Will interpolate the current scheme to match the number of colors requested
   * @param extent The extent of the color range to use.
   * For example [0.2, 1] will rescale the color scheme
   * such that color values in the range [0, 0.2) are excluded from the scheme.

@kristw kristw requested a review from a team as a code owner May 27, 2020 20:32
@vercel
Copy link

vercel bot commented May 27, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/superset/superset-ui/5u09mb1lx
✅ Preview: https://superset-ui-git-kristw-scale.superset.now.sh

@codecov
Copy link

codecov bot commented May 27, 2020

Codecov Report

Merging #547 into master will decrease coverage by 0.08%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #547      +/-   ##
==========================================
- Coverage   23.21%   23.12%   -0.09%     
==========================================
  Files         291      291              
  Lines        6790     6820      +30     
  Branches      675      684       +9     
==========================================
+ Hits         1576     1577       +1     
- Misses       5176     5204      +28     
- Partials       38       39       +1     
Impacted Files Coverage Δ
packages/superset-ui-color/src/SequentialScheme.ts 100.00% <100.00%> (ø)
...ns/plugin-chart-word-cloud/src/chart/WordCloud.tsx 0.00% <0.00%> (ø)
...hart-word-cloud/src/legacyPlugin/transformProps.ts 59.09% <0.00%> (+9.09%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cb2bb5e...2786b28. Read the comment docs.

@@ -10,6 +11,11 @@ function range(count: number) {
return values;
}

function rangeZeroToOne(steps: number) {
const denominator = steps - 1;
return range(steps).map(i => i / denominator);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can replace range with [...new Array(steps).keys()]

@kristw
Copy link
Contributor Author

kristw commented May 28, 2020

@ktmud d3.quantize and d3.piecewise are awesome.

@ktmud
Copy link
Contributor

ktmud commented May 28, 2020

d3 API is full of gems like this. 😄 I didn't actually know d3.piecewise when I started reviewing this PR.

@kristw kristw merged commit f7d4648 into master May 28, 2020
@delete-merged-branch delete-merged-branch bot deleted the kristw--scale branch May 28, 2020 23:29
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants