Skip to content

Commit

Permalink
better sort colormaps
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanhhughes committed Aug 5, 2024
1 parent ed867ac commit 3639b5f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
36 changes: 18 additions & 18 deletions include/spark_dsg/colormaps.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ Color gray(float value);
*/
Color quality(float value);

/**
* @brief Generate a color based on a ironbow value.
* @param value The temperature value [0,1], where 0 is dark and 1 is light.
*/
Color ironbow(float value);

/**
* @brief Generate a color based on a rainbow value.
* @param value The rainbow value [0,1], where 0 is red, 0.5 is green, and 1 is
* blue.
*/
Color rainbow(float value);

/**
* @brief Generate a color based on a spectrum of colors.
* @param value The spectrum value [0,1], where 0 is the first color and 1 is the
Expand All @@ -79,19 +92,6 @@ Color hls(float value,
const std::array<float, 3>& start,
const std::array<float, 3>& end);

/**
* @brief Generate a color based on a ironbow value.
* @param value The temperature value [0,1], where 0 is dark and 1 is light.
*/
Color ironbow(float value);

/**
* @brief Generate a color based on a rainbow value.
* @param value The rainbow value [0,1], where 0 is red, 0.5 is green, and 1 is
* blue.
*/
Color rainbow(float value);

/**
* @brief Generate a color from a general divergent colormap
* @param value A value in [0, 1]. 0 results in one color, 1 in the other, and 0.5 in a
Expand Down Expand Up @@ -119,17 +119,17 @@ Color rainbowId(size_t id, size_t ids_per_revolution = 16);
*/
Color colorbrewerId(size_t id);

/**
* @brief Get the underlying color palette for the distinct150 colormap
*/
const std::vector<Color>& colorbrewerPalette();

/**
* @brief Pick a color from a custom palette from distinctipy with 150 colors
* @param id The id to pick from the sequence
*/
Color distinct150Id(size_t id);

/**
* @brief Get the underlying color palette for the distinct150 colormap
*/
const std::vector<Color>& colorbrewerPalette();

/**
* @brief Get the underlying color palette for the distinct150 colormap
*/
Expand Down
16 changes: 8 additions & 8 deletions src/colormaps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ Color quality(float value) {
return color;
}

Color ironbow(float value) { return spectrum(value, ironbow_palette); }

Color rainbow(float value) {
return Color::fromHLS(std::clamp(value, 0.0f, 1.0f), 0.5f, 1.0f);
}

Color spectrum(float value, const std::vector<Color>& colors) {
if (colors.empty()) {
return Color::black();
Expand Down Expand Up @@ -141,12 +147,6 @@ Color hls(float value,
return Color::fromHLS(w * h1 + w_inv * h2, w * l1 + w_inv * l2, w * s1 + w_inv * s2);
}

Color ironbow(float value) { return spectrum(value, ironbow_palette); }

Color rainbow(float value) {
return Color::fromHLS(std::clamp(value, 0.0f, 1.0f), 0.5f, 1.0f);
}

Color divergent(float value,
float hue_low,
float hue_high,
Expand All @@ -169,13 +169,13 @@ Color colorbrewerId(size_t id) {
return cmap.at(id % cmap.size());
}

const std::vector<Color>& colorbrewerPalette() { return colorbrewer_palette; }

Color distinct150Id(size_t id) {
const auto& cmap = custom_150_palette;
return cmap.at(id % cmap.size());
}

const std::vector<Color>& colorbrewerPalette() { return colorbrewer_palette; }

const std::vector<Color>& distinct150Palette() { return custom_150_palette; }

} // namespace spark_dsg::colormaps

0 comments on commit 3639b5f

Please sign in to comment.