I didn’t find a tool to edit the colors on a map, so I created a small JavaScript library to help doing it: Color scale chooser. The source code is here.
Using it is easy:
- Create an SVG (or a group in an SVG) to append the color scale chooser
- Create an instance of the color scale chooser
- There are many options to pass. In this case, an initial color scale is passed
- Call the color scale chooser instance from the SVG (or an element in the SVG)
This will draw a scale like the one in the example below. Clicking on the colors will open an edit dialog, where the color and scale value can be changed. Also, by clicking on the cross sign over each color, the interval is removed. More intervals can be added with the upper rectangle.
There are some options to pass to the instance:
- .squareWidth(width) sets the width of each square in pixels. The default is 80
- .squareHeight(height) sets the height of each square in pixels. The default is 40
- .scaleValues(obj) sets the initial color scale. The array must be in the format shown in the example
- Each element must be an object with the value and the color keys
- .title(title) adds a title with the text above the scale. The default is null, so no title is added
- .addText(add text) changes the text of the add button. By default is add
- .on(“change”, function) adds a function to trigger when a change on the scale occurs
- The triggered event is change, but more events could be added
Example
For more complicated (and useful) examples, check the color scale isobands and the color scale interpolation examples.
The important part of the example is the function in the on part of the instance. Generates a canvas with the gradient as explained in the color scales section.