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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 72542b2d2b866247433dcdd20f7dcd233e7c5cc8c55b16c13079f370a9092d3a
4
- data.tar.gz: 9cf3c3427e80a3a25b33f6a880f009c5a039f30d2b573a7cfd50d322eec3c260
3
+ metadata.gz: 7a79f4c5d1a76337bf252b00c1aea0f776dd1ee1678a5050d4c37b87e02bde3e
4
+ data.tar.gz: 9417c77ce946dda675e26c8269d7b054e2864a327758568b1f92dd8b0c52358b
5
5
  SHA512:
6
- metadata.gz: 3914868d96a9f88a85c7e22bcde72596db87998a45f3e44bacda5c1ff635046302709711719b53ab912b87dd2569ba8e5b20b32f9a5b5960ac68697fbf56eee5
7
- data.tar.gz: 60c4a27bdce6bb0bf5e1455ddbdbc1437857e8fb7ed799a6e62e8c2cc486579ac51bb38f32235c50fc49e853d64fa6ab245bde1a9aea6d8bd6fc54d3b1523e7e
6
+ metadata.gz: ad8687cd9af527240704a8b35c865a048b5b0c1fc4f6683ea8546403646e8378f281811ef5d3c70e25f24c5a5d954b7ea2e9bc429f6d442ad63aa82844383683
7
+ data.tar.gz: a72e57186ab666533bbfb86ab5fdd589f8450fa4fc730c5e86c4d743f46ec45b84cc741e5960891c591e393db24d605244de0187b0cc511a7ff50b7c32eb2724
data/Gemfile CHANGED
@@ -1,3 +1,8 @@
1
1
  source "https://rubygems.org/"
2
2
 
3
3
  gemspec
4
+
5
+ group :c_ext do
6
+ gem 'numo-narray'
7
+ gem 'enumerable-statistics'
8
+ end
@@ -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)
@@ -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 = Numo::DFloat.linspace(0, 1, n_colors + 1)[0...-1]
23
- hues.inplace + (h/360r).to_f
24
- hues.inplace % 1
25
- hues.inplace - Numo::Int32.cast(hues)
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 = Numo::DFloat.linspace(0, 1, n_colors + 1)[0...-1]
44
- hues.inplace + (h/360r).to_f
45
- hues.inplace % 1
46
- hues.inplace * 359
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
@@ -1,3 +1,3 @@
1
1
  class Palette
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -33,7 +33,6 @@ Gem::Specification.new do |spec|
33
33
  spec.test_files += Dir.glob("test/**/*")
34
34
 
35
35
  spec.add_dependency("red-colors")
36
- spec.add_dependency("numo-narray")
37
36
 
38
37
  spec.add_development_dependency("bundler")
39
38
  spec.add_development_dependency("rake")
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.1.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-18 00:00:00.000000000 Z
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