red-palette 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/palette.rb +1 -1
- data/lib/palette/colors.rb +38 -3
- data/lib/palette/version.rb +1 -1
- data/red-palette.gemspec +1 -1
- data/test/palette_test.rb +28 -6
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1adfe150392dfb94f321411798f406a2dd9e9dcb7183c049f28363a84bf1ed9a
|
4
|
+
data.tar.gz: f123f69082f526c4aa4be8f5e8055956c6a06a4d7aeff8ff15d9af951ba23a66
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69e32980c20d3a9a6d7334145cfb9b168d637bf15ec7ed2e4c2b5725e48e06de1962d7dd6ea08734bd868e31109c03f05bf9257371927e1390fa3c6ddc067790
|
7
|
+
data.tar.gz: 0ef1c3883ce5ea83312489458793ca1a370cb4fa9b2da784d5cdf12f04ddb7f8374a2a0c47a4b092978249a54f45c5339f1b4172bab0bae0b560e768d3a923b8
|
data/lib/palette.rb
CHANGED
data/lib/palette/colors.rb
CHANGED
@@ -79,8 +79,43 @@ class Palette
|
|
79
79
|
pal
|
80
80
|
end
|
81
81
|
|
82
|
-
def self.matplotlib_colors(name, n_colors=6)
|
83
|
-
|
84
|
-
|
82
|
+
def self.matplotlib_colors(name, n_colors=6, as_cmap: false)
|
83
|
+
if name.end_with?("_d")
|
84
|
+
sub_name = name[0..-2]
|
85
|
+
if sub_name.end_with?("_r")
|
86
|
+
reverse = true
|
87
|
+
sub_name = sub_name[0..-2]
|
88
|
+
else
|
89
|
+
reverse = false
|
90
|
+
end
|
91
|
+
colors = Palette.new(sub_name, 2).colors
|
92
|
+
colors << Colors::RGB.parse("#333333")
|
93
|
+
colors.reverse! if reverse
|
94
|
+
cmap = blend_cmap(colors, n_colors, as_cmap: true)
|
95
|
+
else
|
96
|
+
cmap = Colors::ColormapRegistry[name]
|
97
|
+
end
|
98
|
+
|
99
|
+
return cmap if as_cmap
|
100
|
+
|
101
|
+
bins = if MPL_QUAL_PALS.include?(name)
|
102
|
+
Helper.linspace(0r, 1r, MPL_QUAL_PALS[name])[0, n_colors]
|
103
|
+
else
|
104
|
+
Helper.linspace(0r, 1r, Integer(n_colors) + 2)[1...-1]
|
105
|
+
end
|
106
|
+
colors = cmap[bins]
|
107
|
+
return colors
|
108
|
+
end
|
109
|
+
|
110
|
+
def self.blend_colors(colors, n_colors=6, as_cmap: false)
|
111
|
+
name = "blend"
|
112
|
+
cmap = Colors::LinearSegmentedColormap.new_from_list(name, colors)
|
113
|
+
if as_cmap
|
114
|
+
return cmap
|
115
|
+
else
|
116
|
+
bins = Helper.linspace(0r, 1r, Integer(n_colors))
|
117
|
+
colors = cmap[bins]
|
118
|
+
return colors
|
119
|
+
end
|
85
120
|
end
|
86
121
|
end
|
data/lib/palette/version.rb
CHANGED
data/red-palette.gemspec
CHANGED
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.files += Dir.glob("doc/text/*")
|
33
33
|
spec.test_files += Dir.glob("test/**/*")
|
34
34
|
|
35
|
-
spec.add_dependency("red-colors", ">= 0.
|
35
|
+
spec.add_dependency("red-colors", ">= 0.3.0")
|
36
36
|
|
37
37
|
spec.add_development_dependency("bundler")
|
38
38
|
spec.add_development_dependency("rake")
|
data/test/palette_test.rb
CHANGED
@@ -3,7 +3,7 @@ class PaletteTest < Test::Unit::TestCase
|
|
3
3
|
|
4
4
|
sub_test_case(".default") do
|
5
5
|
test("the initial value") do
|
6
|
-
assert_equal(Palette.new("
|
6
|
+
assert_equal(Palette.new("tab10"), Palette.default)
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
@@ -146,18 +146,40 @@ class PaletteTest < Test::Unit::TestCase
|
|
146
146
|
|
147
147
|
sub_test_case(".matplotlib_colors") do
|
148
148
|
test("Set3") do
|
149
|
-
omit("Not implemented yet")
|
150
149
|
palette = Palette.new("Set3")
|
151
150
|
assert_equal("Set3", palette.name)
|
152
151
|
assert_equal(Palette::QUAL_PALETTE_SIZES["Set3"],
|
153
152
|
palette.n_colors)
|
154
|
-
assert_equal(
|
155
|
-
|
156
|
-
|
157
|
-
|
153
|
+
assert_equal([
|
154
|
+
Colors::RGB.new(0.55294117647058827, 0.82745098039215681, 0.7803921568627451),
|
155
|
+
Colors::RGB.new(1.0, 0.92941176470588238, 0.43529411764705883)
|
156
|
+
],
|
157
|
+
[
|
158
|
+
palette.colors[0],
|
159
|
+
palette.colors[-1],
|
160
|
+
])
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
sub_test_case("seaborn's palette") do
|
165
|
+
test("flare") do
|
166
|
+
palette = Palette.new("flare", 256)
|
167
|
+
assert_equal("flare", palette.name)
|
168
|
+
assert_equal(256, palette.n_colors)
|
169
|
+
assert_equal([
|
170
|
+
Colors::RGB.new(0.92907237, 0.68878959, 0.50411509),
|
171
|
+
Colors::RGB.new(0.29408557, 0.13721193, 0.38442775),
|
172
|
+
],
|
173
|
+
[
|
174
|
+
palette.colors[0],
|
175
|
+
palette.colors[-1],
|
176
|
+
])
|
158
177
|
end
|
159
178
|
end
|
160
179
|
|
180
|
+
sub_test_case(".blend_colors") do
|
181
|
+
end
|
182
|
+
|
161
183
|
test("desaturation feature") do
|
162
184
|
desaturated_colors = Palette.new(["#ff0000", "#00ff0099"], desaturate_factor: 0.8).colors
|
163
185
|
assert_near(Colors::HSL.new(0, 0.8r, 0.5r).to_rgb,
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: red-palette
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kenta Murata
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-06-
|
11
|
+
date: 2021-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: red-colors
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.3.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.3.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|