red-palette 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +5 -0
- data/lib/palette.rb +1 -2
- data/lib/palette/colors.rb +14 -8
- data/lib/palette/helper.rb +26 -0
- data/lib/palette/version.rb +1 -1
- data/red-palette.gemspec +0 -1
- metadata +3 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a79f4c5d1a76337bf252b00c1aea0f776dd1ee1678a5050d4c37b87e02bde3e
|
4
|
+
data.tar.gz: 9417c77ce946dda675e26c8269d7b054e2864a327758568b1f92dd8b0c52358b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad8687cd9af527240704a8b35c865a048b5b0c1fc4f6683ea8546403646e8378f281811ef5d3c70e25f24c5a5d954b7ea2e9bc429f6d442ad63aa82844383683
|
7
|
+
data.tar.gz: a72e57186ab666533bbfb86ab5fdd589f8450fa4fc730c5e86c4d743f46ec45b84cc741e5960891c591e393db24d605244de0187b0cc511a7ff50b7c32eb2724
|
data/Gemfile
CHANGED
data/lib/palette.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require "colors"
|
2
|
-
require "numo/narray"
|
3
2
|
|
4
3
|
require_relative "palette/constants"
|
5
4
|
require_relative "palette/colors"
|
@@ -40,7 +39,7 @@ class Palette
|
|
40
39
|
# Use all colors in a qualitative palette or 6 of another kind
|
41
40
|
n_colors ||= QUAL_PALETTE_SIZES.fetch(palette, 6)
|
42
41
|
case @name
|
43
|
-
when SEABORN_PALETTES.method(:has_key?)
|
42
|
+
when SEABORN_PALETTES.method(:has_key?).to_proc # NOTE: to_proc needs for Ruby 2.4
|
44
43
|
palette = self.class.seaborn_colors(@name)
|
45
44
|
when "hls", "HLS", "hsl", "HSL"
|
46
45
|
palette = self.class.hsl_colors(n_colors)
|
data/lib/palette/colors.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require_relative "helper"
|
2
|
+
|
1
3
|
class Palette
|
2
4
|
def self.seaborn_colors(name)
|
3
5
|
SEABORN_PALETTES[name].map do |hex_string|
|
@@ -19,10 +21,12 @@ class Palette
|
|
19
21
|
# @return [Array<Colors::HSL>]
|
20
22
|
# The array of colors
|
21
23
|
def self.hsl_colors(n_colors=6, h: 3.6r, s: 0.65r, l: 0.6r)
|
22
|
-
hues =
|
23
|
-
hues.
|
24
|
-
|
25
|
-
|
24
|
+
hues = Helper.linspace(0, 1, n_colors + 1)[0...-1]
|
25
|
+
hues.each_index do |i|
|
26
|
+
hues[i] += (h/360r).to_f
|
27
|
+
hues[i] %= 1
|
28
|
+
hues[i] -= hues[i].to_i
|
29
|
+
end
|
26
30
|
(0...n_colors).map {|i| Colors::HSL.new(hues[i]*360r, s, l) }
|
27
31
|
end
|
28
32
|
|
@@ -40,10 +44,12 @@ class Palette
|
|
40
44
|
# @return [Array<Colors::HSL>]
|
41
45
|
# The array of colors
|
42
46
|
def self.husl_colors(n_colors=6, h: 3.6r, s: 0.9r, l: 0.65r)
|
43
|
-
hues =
|
44
|
-
hues.
|
45
|
-
|
46
|
-
|
47
|
+
hues = Helper.linspace(0, 1, n_colors + 1)[0...-1]
|
48
|
+
hues.each_index do |i|
|
49
|
+
hues[i] += (h/360r).to_f
|
50
|
+
hues[i] %= 1
|
51
|
+
hues[i] *= 359
|
52
|
+
end
|
47
53
|
(0...n_colors).map {|i| Colors::HUSL.new(hues[i], s, l) }
|
48
54
|
end
|
49
55
|
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class Palette
|
2
|
+
module Helper
|
3
|
+
module Fallback
|
4
|
+
module_function def linspace(x1, x2, n=100)
|
5
|
+
d = x2 - x1
|
6
|
+
step = d / (n-1).to_f
|
7
|
+
n.times.map {|i| x1 + i*step }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
begin
|
12
|
+
require 'numo/narray'
|
13
|
+
rescue LoadError
|
14
|
+
end
|
15
|
+
|
16
|
+
if defined?(Numo)
|
17
|
+
module_function def linspace(x1, x2, *rest)
|
18
|
+
Numo::DFloat.linspace(x1, x2, *rest).to_a
|
19
|
+
end
|
20
|
+
else
|
21
|
+
module_function def linspace(x1, x2, *rest)
|
22
|
+
Fallback.linspace(x1, x2, *rest)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/palette/version.rb
CHANGED
data/red-palette.gemspec
CHANGED
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.2.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: 2020-01-
|
11
|
+
date: 2020-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: red-colors
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: numo-narray
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: bundler
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -123,6 +109,7 @@ files:
|
|
123
109
|
- lib/palette.rb
|
124
110
|
- lib/palette/colors.rb
|
125
111
|
- lib/palette/constants.rb
|
112
|
+
- lib/palette/helper.rb
|
126
113
|
- lib/palette/statistics.rb
|
127
114
|
- lib/palette/version.rb
|
128
115
|
- red-palette.gemspec
|