1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
require 'victor'
module Pokeviewer
module PokemonHelper
def condition_diagram(revision)
svg = Victor::SVG.new width: 420, height: 430
center_x = 200
center_y = 200
radius = 160
angle = -Math::PI / 2.0
incr = (2 * Math::PI) / 5
data = [
[:cool, revision.coolness],
[:beauty, revision.beauty],
[:cute, revision.cuteness],
[:smart, revision.smartness],
[:tough, revision.toughness]
]
outline = data.map do |c|
x_offset = radius * Math.cos(angle)
y_offset = radius * Math.sin(angle)
svg.circle(
cx: (center_x + x_offset),
cy: (center_y + y_offset),
r: 53,
class: "pkcv-#{c[0]}-circle")
if c[0] == :cool
text_y = center_y + (radius + 20) * Math.sin(angle)
else
text_y = center_y + (radius + 60) * Math.sin(angle)
end
svg.text(c[0].upcase,
x: (center_x + (radius + 60) * Math.cos(angle)),
y: text_y,
class: "pkcv-label-outline")
svg.text(c[0].upcase,
x: (center_x + (radius + 60) * Math.cos(angle)),
y: text_y,
class: "pkcv-label")
angle += incr
[center_x + x_offset, center_y + y_offset]
end
svg.polygon(
points: outline.map { |point| point * "," } * " ",
class: "pkcv-outline")
points = data.map do |c|
svg.line(
x1: center_x,
y1: center_y,
x2: center_x + radius * Math.cos(angle),
y2: center_y + radius * Math.sin(angle),
class: "pkcv-line")
datapoint = c[1]
datapoint = 0.01 if datapoint < 1
datapoint /= 10.0
datapoint **= (1.0/3.0)
x_offset = (radius - 3) * Math.cos(angle) * datapoint
y_offset = (radius - 3) * Math.sin(angle) * datapoint
angle += incr
[center_x + x_offset, center_y + y_offset]
end
svg.polygon(
points: points.map { |point| point * "," } * " ",
class: "pkcv-data")
tag.svg(svg.to_s.html_safe,
viewBox: "-80 -30 570 430",
width: 300,
class: "pokemon-condition")
end
end
end
|