Class: Ea::Sources::Qea::Xref::LegendDefinition

Inherits:
Struct
  • Object
show all
Defined in:
lib/ea/sources/qea/xref/legend_definition.rb

Overview

Legend definition record. Produced when the Description contains @PROP= blocks with @TYPE=LEGEND_*. EA encodes legend entries as color/style rules keyed by name.

Example source:

@PROP=@NAME=GMLに定義されたクラス@ENDNAME;
    @TYPE=LEGEND_OBJECTSTYLE@ENDTYPE;
    @VALU=#Back_Ground_Color#=13434828;#Pen_Color#=0;
          #Pen_Size#=1;#Legend_Type#=LEGEND_OBJECTSTYLE;
          @ENDVALU;@PRMT=0@ENDPRMT;@ENDPROP;

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#colorsObject

Returns the value of attribute colors

Returns:

  • (Object)

    the current value of colors



17
18
19
# File 'lib/ea/sources/qea/xref/legend_definition.rb', line 17

def colors
  @colors
end

#legend_typeObject

Returns the value of attribute legend_type

Returns:

  • (Object)

    the current value of legend_type



17
18
19
# File 'lib/ea/sources/qea/xref/legend_definition.rb', line 17

def legend_type
  @legend_type
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



17
18
19
# File 'lib/ea/sources/qea/xref/legend_definition.rb', line 17

def name
  @name
end

#parameterObject

Returns the value of attribute parameter

Returns:

  • (Object)

    the current value of parameter



17
18
19
# File 'lib/ea/sources/qea/xref/legend_definition.rb', line 17

def parameter
  @parameter
end

Instance Method Details

#hex_color(key) ⇒ String?

EA encodes colors as signed 32-bit integers (VB-style). Convert to #RRGGBB hex string for SVG consumption.

Parameters:

  • key (Symbol)

    color key, e.g. :back_ground_color

Returns:

  • (String, nil)

    hex color (#RRGGBB) or nil



23
24
25
26
27
28
29
30
# File 'lib/ea/sources/qea/xref/legend_definition.rb', line 23

def hex_color(key)
  value = colors&.dig(key)
  return nil if value.nil?

  int = value.to_i
  int = (int + 2**32) % 2**32 if int.negative?
  format("#%06X", int & 0xFFFFFF)
end