Class: Kmeans::Dendrogram

Inherits:
Object
  • Object
show all
Defined in:
lib/kmeans/dendrogram.rb

Instance Method Summary collapse

Constructor Details

#initialize(user_options = {}) ⇒ Dendrogram

Returns a new instance of Dendrogram.



8
9
10
11
12
13
14
15
16
# File 'lib/kmeans/dendrogram.rb', line 8

def initialize(user_options = {})
  @options = {
    :imagefile => 'clusters.png',
    :font_path => '/usr/share/fonts/truetype/vlgothic/VL-Gothic-Regular.ttf',
    :stroke => 'transparent',
    :fill => 'black',
    :pointsize => 10
  }.merge(user_options)
end

Instance Method Details

#drawdendrogram(clust, labels) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/kmeans/dendrogram.rb', line 18

def drawdendrogram(clust, labels)
  h = getheight(clust) * 20
  w = 1200
  depth = getdepth(clust)

  scaling = Float(w-150)/depth

  img = Image.new(w,h)
  draw = Draw.new
  draw.stroke('red')
  draw.stroke_width(1)
  draw.line(0, h/2, 10, h/2)

  drawnode(draw, clust, 10, (h/2), scaling, labels)

  draw.draw(img)
  img.write(@options[:imagefile])
end