Module: AsciidoctorDiagramLayout::Renderer::ColorPalette Private

Defined in:
lib/asciidoctor_diagram_layout/renderer/color_palette.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Utility module for HSL-to-hex conversion and Java-compatible hashing.

Constant Summary collapse

STROKE_COLOR =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

:nodoc:

"#d0d0d0"
GOLDEN_RATIO =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

:nodoc:

0.618033988749895
HUE_RANGE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

:nodoc:

360

Class Method Summary collapse

Class Method Details

.hsl_to_hex(hue, saturation, lightness) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Converts HSL values to a hex color string.

Parameters:

  • hue (Integer)

    hue angle (0..359)

  • saturation (Integer)

    saturation (0..100)

  • lightness (Integer)

    lightness (0..100)

Returns:

  • (String)

    hex color (e.g. “#d4d4d4”)



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/asciidoctor_diagram_layout/renderer/color_palette.rb', line 20

def self.hsl_to_hex(hue, saturation, lightness)
  s = saturation / 100.0
  l = lightness  / 100.0
  c = (1 - (2 * l - 1).abs) * s
  x = c * (1 - ((hue / 60.0) % 2 - 1).abs)
  m = l - c / 2.0
  if hue < 60
    r, g, b = c, x, 0
  elsif hue < 120
    r, g, b = x, c, 0
  elsif hue < 180
    r, g, b = 0, c, x
  elsif hue < 240
    r, g, b = 0, x, c
  elsif hue < 300
    r, g, b = x, 0, c
  else
    r, g, b = c, 0, x
  end
  ri = (r + m) * 255
  gi = (g + m) * 255
  bi = (b + m) * 255
  format("#%02x%02x%02x", ri.round, gi.round, bi.round)
end

.java_hash(str) ⇒ Integer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Java-compatible String#hashCode.

Uses 32-bit signed overflow semantics, identical to the algorithm defined in the Java Language Specification:

s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]

Parameters:

  • str (String)

Returns:

  • (Integer)

    signed 32-bit hash code



53
54
55
56
57
58
59
60
# File 'lib/asciidoctor_diagram_layout/renderer/color_palette.rb', line 53

def self.java_hash(str)
  return 0 if str.nil? || str.empty?
  h = 0
  str.each_char do |c|
    h = (31 * h + c.ord) & 0xffffffff
  end
  h >= 0x80000000 ? h - 0x100000000 : h
end