Coder Social home page Coder Social logo

Comments (3)

sfairgrieve avatar sfairgrieve commented on May 14, 2024

Sylvain,

Good question. You can pass an interpolate option in the
L.CustomColorFunction constructor like so:

var fillColorSeq = new L.CustomColorFunction(range[0], range[1],
L.ColorBrewer.Sequential.PuBuGn['9'], {
    interpolate: false
});

This will ensure that only the 9 or 4 or desired number of color classes
are used rather than interpolating between colors.

As far as the legend goes, it looks like that's a bug or at least an
oversight. The legend will always use a gradient, even if it doesn't make
sense (as in this case). I will push a fix in the next few days that makes
this configurable. Thanks for pointing this out.

Thanks,

Scott

Sent from my iPhone

On Mar 21, 2014, at 6:52 PM, sylvaincaillot [email protected]
wrote:

Good morning,
First of all congratulations for this amazing plugin.

I am developing a map with a chloropeth layer similar to you countystats
example.
I would like to give the user the posiibility to choose its color
palette(sequential/diverging) and the number of data classes as in the
Colorbrewer website.
Using this webpage and this site (
http://www.cse.unsw.edu.au/~mike/myrlibrary.old/RColorBrewer/html/ColorBrewer.html),
i have been writing the following code for sequential and diverging colors:

var fillColorSeq = new L.CustomColorFunction(range[0], range[1],
L.ColorBrewer.Sequential.PuBuGn['9']);
var fillColorDiv= new L.CustomColorFunction(range[0], range[1],
L.ColorBrewer.Diverging.PRGn['11']);

I works OK but when i reduce the number of color classes
(eg.:L.ColorBrewer.Diverging.PRGn['4']);), i would expect to have 4 colors
only in my map and legend but, i still continue to have more colors than
data classes with perhaps a clearer tint.

Am i doing something wrong?
Should i use the slice attribute? I didn't find much information on it.

At least, is it possible to define automatically the number of segments of
the legend based on the number of data classes chosen for the
customeColorFunction without using the numSegments option of the legend and
the gradient effect?
I would like to get something similar to the Colorbrewer site.

Thanks in advance for your reply.

Sylvain

Reply to this email directly or view it on
GitHubhttps://github.com//issues/25
.

from leaflet-dvf.

sfairgrieve avatar sfairgrieve commented on May 14, 2024

Just pushed an update which should make this work. In the DataLayer legendOptions section, just include an option called gradient with a value of false in addition to setting interpolate to false in the L.CustomColorFunction. I updated the county stats example to illustrate this.

from leaflet-dvf.

sylvaincaillot avatar sylvaincaillot commented on May 14, 2024

It works beautifully. Thanks for your prompt answer.
Is there a way to reset LegendOptions where the numSegments has changed for example. I tried to look for something similar to setDisplayOptions for legendOptions but didn't find anything.

Sylvain

from leaflet-dvf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.