Skip to content

Commit 4188798

Browse files
authored
update color palettes (#198)
1 parent 922d1b3 commit 4188798

6 files changed

Lines changed: 124 additions & 49 deletions

File tree

doc/syntax/scale/aesthetic/1_color.qmd

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -85,31 +85,32 @@ SCALE color TO ['antiquewhite', 'firebrick']
8585
### Continuous palettes
8686

8787
#### Sequential
88-
Sequential palettes for numeric data. `navia` is the default continuous color palette in ggsql.
88+
Sequential palettes for numeric data. `sequential` is the default continuous color palette in ggsql.
8989

9090
| Name | Gradient | Source | Description |
9191
|------|----------|--------|-------------|
92-
| `navia` | ![](examples/gradient_navia.svg){height=20 .lightbox} | Crameri | **Default.** Blue-green-cream (alias: `sequential`) |
93-
| `batlow` | ![](examples/gradient_batlow.svg){height=20 .lightbox} | Crameri | Blue-green-yellow-red |
92+
| `sequential` | ![](examples/gradient_sequential.svg){height=20 .lightbox} | ggsql | **Default.** Blue-teal-green (derived from navia) |
93+
| `acton` | ![](examples/gradient_acton.svg){height=20 .lightbox} | Crameri | Dark purple-light purple |
94+
| `bamako` | ![](examples/gradient_bamako.svg){height=20 .lightbox} | Crameri | Teal-olive-cream |
95+
| `batlow` | ![](examples/gradient_batlow.svg){height=20 .lightbox} | Crameri | Blue-teal-green-brown-pink |
9496
| `batlowk` | ![](examples/gradient_batlowk.svg){height=20 .lightbox} | Crameri | Dark variant of batlow |
9597
| `batloww` | ![](examples/gradient_batloww.svg){height=20 .lightbox} | Crameri | Light variant of batlow |
96-
| `hawaii` | ![](examples/gradient_hawaii.svg){height=20 .lightbox} | Crameri | Green-yellow-orange-magenta |
97-
| `lajolla` | ![](examples/gradient_lajolla.svg){height=20 .lightbox} | Crameri | Cream-yellow-orange-brown |
98-
| `tokyo` | ![](examples/gradient_tokyo.svg){height=20 .lightbox} | Crameri | White-magenta-dark blue |
99-
| `turku` | ![](examples/gradient_turku.svg){height=20 .lightbox} | Crameri | Cream-green-dark brown |
100-
| `acton` | ![](examples/gradient_acton.svg){height=20 .lightbox} | Crameri | White-purple |
101-
| `bamako` | ![](examples/gradient_bamako.svg){height=20 .lightbox} | Crameri | White-brown-dark brown |
102-
| `bilbao` | ![](examples/gradient_bilbao.svg){height=20 .lightbox} | Crameri | White-orange-dark brown |
103-
| `buda` | ![](examples/gradient_buda.svg){height=20 .lightbox} | Crameri | White-pink-magenta |
104-
| `davos` | ![](examples/gradient_davos.svg){height=20 .lightbox} | Crameri | White-blue |
105-
| `devon` | ![](examples/gradient_devon.svg){height=20 .lightbox} | Crameri | White-blue-dark blue |
106-
| `glasgow` | ![](examples/gradient_glasgow.svg){height=20 .lightbox} | Crameri | Blue-cream-orange |
107-
| `grayc` | ![](examples/gradient_grayc.svg){height=20 .lightbox} | Crameri | White-black grayscale |
108-
| `imola` | ![](examples/gradient_imola.svg){height=20 .lightbox} | Crameri | Blue-cream-green |
109-
| `lapaz` | ![](examples/gradient_lapaz.svg){height=20 .lightbox} | Crameri | White-blue-dark |
110-
| `lipari` | ![](examples/gradient_lipari.svg){height=20 .lightbox} | Crameri | White-orange-dark blue |
111-
| `nuuk` | ![](examples/gradient_nuuk.svg){height=20 .lightbox} | Crameri | White-blue-green |
112-
| `oslo` | ![](examples/gradient_oslo.svg){height=20 .lightbox} | Crameri | White-blue-black |
98+
| `bilbao` | ![](examples/gradient_bilbao.svg){height=20 .lightbox} | Crameri | Brown-tan-white |
99+
| `buda` | ![](examples/gradient_buda.svg){height=20 .lightbox} | Crameri | Magenta-pink-yellow |
100+
| `davos` | ![](examples/gradient_davos.svg){height=20 .lightbox} | Crameri | Dark blue-teal-green-white |
101+
| `devon` | ![](examples/gradient_devon.svg){height=20 .lightbox} | Crameri | Dark purple-blue-white |
102+
| `glasgow` | ![](examples/gradient_glasgow.svg){height=20 .lightbox} | Crameri | Purple-brown-olive-light purple |
103+
| `grayc` | ![](examples/gradient_grayc.svg){height=20 .lightbox} | Crameri | Black-white grayscale |
104+
| `hawaii` | ![](examples/gradient_hawaii.svg){height=20 .lightbox} | Crameri | Magenta-orange-green-cyan |
105+
| `imola` | ![](examples/gradient_imola.svg){height=20 .lightbox} | Crameri | Blue-teal-green-yellow |
106+
| `lajolla` | ![](examples/gradient_lajolla.svg){height=20 .lightbox} | Crameri | Dark brown-orange-yellow-cream |
107+
| `lapaz` | ![](examples/gradient_lapaz.svg){height=20 .lightbox} | Crameri | Dark purple-blue-teal-cream |
108+
| `lipari` | ![](examples/gradient_lipari.svg){height=20 .lightbox} | Crameri | Dark blue-red-orange-cream |
109+
| `navia` | ![](examples/gradient_navia.svg){height=20 .lightbox} | Crameri | Blue-teal-green-cream |
110+
| `nuuk` | ![](examples/gradient_nuuk.svg){height=20 .lightbox} | Crameri | Blue-teal-green-yellow |
111+
| `oslo` | ![](examples/gradient_oslo.svg){height=20 .lightbox} | Crameri | Black-blue-white |
112+
| `tokyo` | ![](examples/gradient_tokyo.svg){height=20 .lightbox} | Crameri | Dark purple-magenta-olive-green |
113+
| `turku` | ![](examples/gradient_turku.svg){height=20 .lightbox} | Crameri | Black-olive-tan-pink |
113114
| `blues` | ![](examples/gradient_blues.svg){height=20 .lightbox} | ColorBrewer | Light to dark blue |
114115
| `greens` | ![](examples/gradient_greens.svg){height=20 .lightbox} | ColorBrewer | Light to dark green |
115116
| `oranges` | ![](examples/gradient_oranges.svg){height=20 .lightbox} | ColorBrewer | Light to dark orange |
@@ -141,15 +142,15 @@ Diverging palettes emphasize a critical midpoint with two contrasting hues on ei
141142
| Name | Gradient | Source | Description |
142143
|------|----------|--------|-------------|
143144
| `vik` | ![](examples/gradient_vik.svg){height=20 .lightbox} | Crameri | Blue-white-red (alias: `diverging`) |
144-
| `berlin` | ![](examples/gradient_berlin.svg){height=20 .lightbox} | Crameri | Blue-white-red (different hues) |
145-
| `roma` | ![](examples/gradient_roma.svg){height=20 .lightbox} | Crameri | Green-cream-orange |
146-
| `bam` | ![](examples/gradient_bam.svg){height=20 .lightbox} | Crameri | Blue-white-red |
147-
| `broc` | ![](examples/gradient_broc.svg){height=20 .lightbox} | Crameri | Brown-white-green |
148-
| `cork` | ![](examples/gradient_cork.svg){height=20 .lightbox} | Crameri | Blue-white-green |
149-
| `lisbon` | ![](examples/gradient_lisbon.svg){height=20 .lightbox} | Crameri | Blue-white-brown |
150-
| `managua` | ![](examples/gradient_managua.svg){height=20 .lightbox} | Crameri | Blue-white-magenta |
151-
| `tofino` | ![](examples/gradient_tofino.svg){height=20 .lightbox} | Crameri | Blue-cream-brown |
152-
| `vanimo` | ![](examples/gradient_vanimo.svg){height=20 .lightbox} | Crameri | Magenta-white-green |
145+
| `berlin` | ![](examples/gradient_berlin.svg){height=20 .lightbox} | Crameri | Light blue-dark-light red |
146+
| `roma` | ![](examples/gradient_roma.svg){height=20 .lightbox} | Crameri | Brown-cream-blue |
147+
| `bam` | ![](examples/gradient_bam.svg){height=20 .lightbox} | Crameri | Purple-white-green |
148+
| `broc` | ![](examples/gradient_broc.svg){height=20 .lightbox} | Crameri | Purple-white-olive |
149+
| `cork` | ![](examples/gradient_cork.svg){height=20 .lightbox} | Crameri | Purple-white-green |
150+
| `lisbon` | ![](examples/gradient_lisbon.svg){height=20 .lightbox} | Crameri | Light purple-dark-light yellow |
151+
| `managua` | ![](examples/gradient_managua.svg){height=20 .lightbox} | Crameri | Yellow-dark-cyan |
152+
| `tofino` | ![](examples/gradient_tofino.svg){height=20 .lightbox} | Crameri | Light purple-dark-light green |
153+
| `vanimo` | ![](examples/gradient_vanimo.svg){height=20 .lightbox} | Crameri | Pink-dark-light green |
153154
| `rdbu` | ![](examples/gradient_rdbu.svg){height=20 .lightbox} | ColorBrewer | Red-Blue |
154155
| `rdylbu` | ![](examples/gradient_rdylbu.svg){height=20 .lightbox} | ColorBrewer | Red-Yellow-Blue |
155156
| `rdylgn` | ![](examples/gradient_rdylgn.svg){height=20 .lightbox} | ColorBrewer | Red-Yellow-Green |
@@ -158,7 +159,7 @@ Diverging palettes emphasize a critical midpoint with two contrasting hues on ei
158159
| `prgn` | ![](examples/gradient_prgn.svg){height=20 .lightbox} | ColorBrewer | Purple-Green |
159160
| `piyg` | ![](examples/gradient_piyg.svg){height=20 .lightbox} | ColorBrewer | Pink-Yellow-Green |
160161
| `rdgy` | ![](examples/gradient_rdgy.svg){height=20 .lightbox} | ColorBrewer | Red-Grey |
161-
| `puor` | ![](examples/gradient_puor.svg){height=20 .lightbox} | ColorBrewer | Purple-Orange |
162+
| `puor` | ![](examples/gradient_puor.svg){height=20 .lightbox} | ColorBrewer | Orange-Purple |
162163

163164
#### Multi-Sequential
164165

@@ -176,11 +177,11 @@ Cyclic palettes wrap around, making them suitable for periodic data like angles,
176177

177178
| Name | Gradient | Source | Description |
178179
|------|----------|--------|-------------|
179-
| `romao` | ![](examples/gradient_romao.svg){height=20 .lightbox} | Crameri | Cyclic green-orange (alias: `cyclic`) |
180-
| `bamo` | ![](examples/gradient_bamo.svg){height=20 .lightbox} | Crameri | Cyclic blue-red |
181-
| `broco` | ![](examples/gradient_broco.svg){height=20 .lightbox} | Crameri | Cyclic brown-green |
182-
| `corko` | ![](examples/gradient_corko.svg){height=20 .lightbox} | Crameri | Cyclic blue-green |
183-
| `viko` | ![](examples/gradient_viko.svg){height=20 .lightbox} | Crameri | Cyclic blue-red |
180+
| `romao` | ![](examples/gradient_romao.svg){height=20 .lightbox} | Crameri | Cyclic purple-orange-teal-blue (alias: `cyclic`) |
181+
| `bamo` | ![](examples/gradient_bamo.svg){height=20 .lightbox} | Crameri | Cyclic purple-pink-cream-olive |
182+
| `broco` | ![](examples/gradient_broco.svg){height=20 .lightbox} | Crameri | Cyclic gray-blue-cream-olive |
183+
| `corko` | ![](examples/gradient_corko.svg){height=20 .lightbox} | Crameri | Cyclic gray-blue-teal-green |
184+
| `viko` | ![](examples/gradient_viko.svg){height=20 .lightbox} | Crameri | Cyclic purple-blue-cream-orange |
184185

185186
### Discrete palettes
186187

@@ -229,7 +230,7 @@ Kelly, K.L. (1965). Twenty-two colors of maximum contrast. *Color Engineering*,
229230

230231
#### For general continuous data
231232

232-
- **`navia`** (default) - Good all-purpose choice, perceptually uniform
233+
- **`sequential`** (default) - Good all-purpose choice, perceptually uniform
233234
- **`viridis`** - Excellent for print, colorblind-safe, perceptually uniform
234235
- **`batlow`** - Wide perceptual range, good for scientific data
235236

Lines changed: 27 additions & 0 deletions
Loading
Lines changed: 7 additions & 7 deletions
Loading

doc/syntax/scale/aesthetic/generate_examples.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
# Continuous palettes referenced in color_cont.qmd
88
CONTINUOUS_PALETTES <- c(
9+
# ggsql default
10+
"sequential",
911
# Crameri Sequential
1012
"navia", "batlow", "batlowk", "batloww", "hawaii", "lajolla", "tokyo",
1113
"turku", "acton", "bamako", "bilbao", "buda", "davos", "devon", "glasgow",

src/parser/builder.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3328,9 +3328,10 @@ mod tests {
33283328

33293329
let literal_node = source.find_node(&root, "(literal_value) @lit").unwrap();
33303330
let parsed = parse_literal_value(&literal_node, &source).unwrap();
3331-
assert!(
3332-
matches!(parsed, AestheticValue::Literal(ParameterValue::String(ref s)) if s == "red")
3333-
);
3331+
assert!(matches!(
3332+
parsed,
3333+
AestheticValue::Literal(ParameterValue::String(ref s)) if s == "red"
3334+
));
33343335

33353336
// Test number literal
33363337
let source2 = make_source("VISUALISE DRAW point MAPPING 42 AS size");

src/plot/scale/palettes.rs

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use crate::plot::ArrayElement;
1010

1111
/// ggsql 10 - default categorical palette
1212
pub const GGSQL10: &[&str] = &[
13-
"#0067A5", "#F3C300", "#008856", "#F38400", "#875692", "#BE0032", "#A1CAF1", "#E68FAC",
14-
"#8DB600", "#654522",
13+
"#0067A5", "#F38400", "#008856", "#F3C300", "#875692", "#A1CAF1", "#BE0032", "#8DB600",
14+
"#654522", "#E68FAC",
1515
];
1616

1717
/// Tableau 10
@@ -1482,6 +1482,37 @@ pub const NAVIA: &[&str] = &[
14821482
"#F4F1CE", "#F6F2D0", "#F7F2D2", "#F8F2D2", "#F8F2D4", "#F9F2D6", "#FAF3D7", "#FCF3D8",
14831483
];
14841484

1485+
/// Sequential palette (204 colors)
1486+
/// Derived from Crameri navia with 20% of lightest colors removed
1487+
pub const SEQUENTIAL: &[&str] = &[
1488+
"#021326", "#041428", "#04152B", "#04172C", "#04182D", "#041930", "#051932", "#051A33",
1489+
"#051B35", "#051D38", "#051E39", "#051F3B", "#05203E", "#05213F", "#052241", "#052444",
1490+
"#052546", "#052647", "#06274A", "#06284C", "#062A4D", "#062B50", "#062C52", "#062D53",
1491+
"#062E55", "#063058", "#063159", "#06325B", "#06335E", "#06345F", "#063561", "#063764",
1492+
"#063966", "#073967", "#073A6A", "#073B6B", "#073E6C", "#083F6E", "#083F71", "#0A4072",
1493+
"#0A4373", "#0B4476", "#0B4578", "#0B4679", "#0C477A", "#0C487D", "#0C4A7E", "#0D4C7F",
1494+
"#0D4C80", "#0E4D81", "#104E84", "#105185", "#115285", "#125286", "#135387", "#135588",
1495+
"#13578A", "#14588B", "#15598C", "#17598C", "#175B8C", "#185D8D", "#195E8D", "#195F8E",
1496+
"#1A5F8E", "#1A6090", "#1B6190", "#1D6390", "#1E6491", "#1E6591", "#1F6691", "#1F6691",
1497+
"#1F6791", "#206891", "#216A91", "#216B91", "#226C91", "#246C91", "#246C91", "#256D90",
1498+
"#266E90", "#266E90", "#267090", "#26718E", "#27718E", "#27728E", "#28728E", "#2A728D",
1499+
"#2A738D", "#2B748D", "#2B748C", "#2C768C", "#2C768C", "#2C778C", "#2C788C", "#2D788C",
1500+
"#2E798B", "#2E798B", "#30798B", "#30798A", "#317A8A", "#317B8A", "#327B88", "#327D88",
1501+
"#337D88", "#337E87", "#337E87", "#347F87", "#347F86", "#357F86", "#357F85", "#378085",
1502+
"#378085", "#388185", "#398385", "#398385", "#398484", "#398484", "#3A8584", "#3B8583",
1503+
"#3B8583", "#3D8581", "#3D8681", "#3E8781", "#3F8780", "#3F8880", "#3F8880", "#3F8A7F",
1504+
"#408A7F", "#418B7F", "#418C7F", "#438C7F", "#448C7E", "#448C7E", "#458D7D", "#468E7D",
1505+
"#468E7D", "#46907B", "#47917B", "#48917A", "#48927A", "#4A9279", "#4B9279", "#4C9379",
1506+
"#4C9479", "#4C9479", "#4D9678", "#4E9778", "#509877", "#509877", "#519976", "#529976",
1507+
"#529A74", "#539A74", "#549B73", "#559D73", "#579E72", "#579F72", "#589F72", "#599F72",
1508+
"#59A071", "#5AA171", "#5BA370", "#5DA470", "#5EA56E", "#5FA56E", "#5FA66D", "#61A76D",
1509+
"#63A96C", "#64AA6C", "#65AB6C", "#66AC6C", "#66AC6B", "#68AD6B", "#6AAE6A", "#6BB06A",
1510+
"#6CB168", "#6DB268", "#70B268", "#71B368", "#72B467", "#73B667", "#76B767", "#78B867",
1511+
"#79B967", "#7ABA67", "#7DBB67", "#7FBD67", "#80BF67", "#83BF67", "#85C068", "#86C168",
1512+
"#88C36A", "#8CC56A", "#8DC56B", "#90C66C", "#92C76C", "#94CA6D", "#98CB6E", "#99CC70",
1513+
"#9BCC72", "#9FCD72", "#A1CE73", "#A4D176",
1514+
];
1515+
14851516
/// Crameri nuuk (256 colors)
14861517
/// Source: Fabio Crameri scientific colour maps
14871518
pub const NUUK: &[&str] = &[
@@ -2020,7 +2051,8 @@ pub fn get_color_palette(name: &str) -> Option<&'static [&'static str]> {
20202051
"lajolla" => Some(LAJOLLA),
20212052
"lapaz" => Some(LAPAZ),
20222053
"lipari" => Some(LIPARI),
2023-
"navia" | "sequential" => Some(NAVIA),
2054+
"navia" => Some(NAVIA),
2055+
"sequential" => Some(SEQUENTIAL),
20242056
"nuuk" => Some(NUUK),
20252057
"oslo" => Some(OSLO),
20262058
"tokyo" => Some(TOKYO),
@@ -2223,6 +2255,18 @@ mod tests {
22232255
assert_eq!(get_color_palette("acton").unwrap().len(), 256);
22242256
}
22252257

2258+
#[test]
2259+
fn test_sequential_palette() {
2260+
// Sequential is derived from navia with 20% lightest colors removed
2261+
assert_eq!(get_color_palette("sequential").unwrap().len(), 204);
2262+
assert_eq!(get_color_palette("navia").unwrap().len(), 256);
2263+
// First colors should match
2264+
assert_eq!(
2265+
get_color_palette("sequential").unwrap()[0],
2266+
get_color_palette("navia").unwrap()[0]
2267+
);
2268+
}
2269+
22262270
#[test]
22272271
fn test_get_shape_palette() {
22282272
// Combined palette (all shapes)

0 commit comments

Comments
 (0)