diff options
-rw-r--r-- | Gemfile.lock | 2 | ||||
-rw-r--r-- | app/assets/stylesheets/pokeviewer/pokemon.css.scss | 53 | ||||
-rw-r--r-- | app/helpers/pokeviewer/pokemon_helper.rb | 76 | ||||
-rw-r--r-- | app/views/pokeviewer/pokemon/show.html.haml | 1 | ||||
-rw-r--r-- | pokeviewer.gemspec | 1 |
5 files changed, 131 insertions, 2 deletions
diff --git a/Gemfile.lock b/Gemfile.lock index 3936e58..7c43e10 100644 --- a/Gemfile.lock +++ b/Gemfile.lock | |||
@@ -11,6 +11,7 @@ PATH | |||
11 | rails (~> 5.1.4) | 11 | rails (~> 5.1.4) |
12 | sass-rails (~> 5.0) | 12 | sass-rails (~> 5.0) |
13 | sequenced | 13 | sequenced |
14 | victor | ||
14 | 15 | ||
15 | GEM | 16 | GEM |
16 | remote: https://rubygems.org/ | 17 | remote: https://rubygems.org/ |
@@ -150,6 +151,7 @@ GEM | |||
150 | tilt (2.0.8) | 151 | tilt (2.0.8) |
151 | tzinfo (1.2.3) | 152 | tzinfo (1.2.3) |
152 | thread_safe (~> 0.1) | 153 | thread_safe (~> 0.1) |
154 | victor (0.2.1) | ||
153 | websocket-driver (0.6.5) | 155 | websocket-driver (0.6.5) |
154 | websocket-extensions (>= 0.1.0) | 156 | websocket-extensions (>= 0.1.0) |
155 | websocket-extensions (0.1.2) | 157 | websocket-extensions (0.1.2) |
diff --git a/app/assets/stylesheets/pokeviewer/pokemon.css.scss b/app/assets/stylesheets/pokeviewer/pokemon.css.scss index 077aaf7..c9560d4 100644 --- a/app/assets/stylesheets/pokeviewer/pokemon.css.scss +++ b/app/assets/stylesheets/pokeviewer/pokemon.css.scss | |||
@@ -215,11 +215,10 @@ body { | |||
215 | 215 | ||
216 | .pokemon-basics { | 216 | .pokemon-basics { |
217 | margin: .5em; | 217 | margin: .5em; |
218 | min-width: 5em; | ||
218 | } | 219 | } |
219 | 220 | ||
220 | .pokemon-column { | 221 | .pokemon-column { |
221 | display: flex; | ||
222 | flex-direction: column; | ||
223 | border-left: 1px solid #aaa; | 222 | border-left: 1px solid #aaa; |
224 | 223 | ||
225 | &>div + div { | 224 | &>div + div { |
@@ -300,4 +299,54 @@ body { | |||
300 | } | 299 | } |
301 | } | 300 | } |
302 | } | 301 | } |
302 | |||
303 | .pokemon-condition { | ||
304 | background-color: #b9d7f2; | ||
305 | border-left: 1px solid #aaa; | ||
306 | flex: 1 0px; | ||
307 | |||
308 | .pkcv-cool-circle { | ||
309 | fill: #f59a55; | ||
310 | } | ||
311 | |||
312 | .pkcv-beauty-circle { | ||
313 | fill: #8095ff; | ||
314 | } | ||
315 | |||
316 | .pkcv-cute-circle { | ||
317 | fill: #f5a8d3; | ||
318 | } | ||
319 | |||
320 | .pkcv-smart-circle { | ||
321 | fill: #79e15c; | ||
322 | } | ||
323 | |||
324 | .pkcv-tough-circle { | ||
325 | fill: #f7f100; | ||
326 | } | ||
327 | |||
328 | .pkcv-outline { | ||
329 | stroke: gray; | ||
330 | stroke-width: 5; | ||
331 | stroke-linejoin: round; | ||
332 | fill: white; | ||
333 | fill-opacity: 0.3; | ||
334 | } | ||
335 | |||
336 | .pkcv-data { | ||
337 | fill: #4ee100; | ||
338 | } | ||
339 | |||
340 | .pkcv-label, .pkcv-label-outline { | ||
341 | font-family: "Power Green"; | ||
342 | font-size: 50px; | ||
343 | text-anchor: middle; | ||
344 | } | ||
345 | |||
346 | .pkcv-label-outline { | ||
347 | stroke: #f0f8f8; | ||
348 | stroke-width: 6; | ||
349 | stroke-linejoin: butt; | ||
350 | } | ||
351 | } | ||
303 | } | 352 | } |
diff --git a/app/helpers/pokeviewer/pokemon_helper.rb b/app/helpers/pokeviewer/pokemon_helper.rb index 4f3dc3f..de2d815 100644 --- a/app/helpers/pokeviewer/pokemon_helper.rb +++ b/app/helpers/pokeviewer/pokemon_helper.rb | |||
@@ -1,4 +1,80 @@ | |||
1 | require 'victor' | ||
2 | |||
1 | module Pokeviewer | 3 | module Pokeviewer |
2 | module PokemonHelper | 4 | module PokemonHelper |
5 | |||
6 | def condition_diagram(revision) | ||
7 | svg = Victor::SVG.new width: 420, height: 430 | ||
8 | |||
9 | center_x = 200 | ||
10 | center_y = 200 | ||
11 | radius = 160 | ||
12 | |||
13 | angle = -Math::PI / 2.0 | ||
14 | incr = (2 * Math::PI) / 5 | ||
15 | |||
16 | data = [ | ||
17 | [:cool, revision.coolness], | ||
18 | [:beauty, revision.beauty], | ||
19 | [:cute, revision.cuteness], | ||
20 | [:smart, revision.smartness], | ||
21 | [:tough, revision.toughness] | ||
22 | ] | ||
23 | |||
24 | outline = data.map do |c| | ||
25 | x_offset = radius * Math.cos(angle) | ||
26 | y_offset = radius * Math.sin(angle) | ||
27 | |||
28 | svg.circle( | ||
29 | cx: (center_x + x_offset), | ||
30 | cy: (center_y + y_offset), | ||
31 | r: 53, | ||
32 | class: "pkcv-#{c[0]}-circle") | ||
33 | |||
34 | if c[0] == :cool | ||
35 | text_y = center_y + (radius + 20) * Math.sin(angle) | ||
36 | else | ||
37 | text_y = center_y + (radius + 60) * Math.sin(angle) | ||
38 | end | ||
39 | |||
40 | svg.text(c[0].upcase, | ||
41 | x: (center_x + (radius + 60) * Math.cos(angle)), | ||
42 | y: text_y, | ||
43 | class: "pkcv-label-outline") | ||
44 | |||
45 | svg.text(c[0].upcase, | ||
46 | x: (center_x + (radius + 60) * Math.cos(angle)), | ||
47 | y: text_y, | ||
48 | class: "pkcv-label") | ||
49 | |||
50 | angle += incr | ||
51 | |||
52 | [center_x + x_offset, center_y + y_offset] | ||
53 | end | ||
54 | |||
55 | svg.polygon points: outline.map { |point| point * "," } * " ", class: "pkcv-outline" | ||
56 | |||
57 | points = data.map do |c| | ||
58 | datapoint = c[1] | ||
59 | datapoint = 0.01 if datapoint < 1 | ||
60 | datapoint /= 10.0 | ||
61 | datapoint **= (1.0/3.0) | ||
62 | |||
63 | x_offset = (radius - 3) * Math.cos(angle) * datapoint | ||
64 | y_offset = (radius - 3) * Math.sin(angle) * datapoint | ||
65 | |||
66 | angle += incr | ||
67 | |||
68 | [center_x + x_offset, center_y + y_offset] | ||
69 | end | ||
70 | |||
71 | svg.polygon points: points.map { |point| point * "," } * " ", class: "pkcv-data" | ||
72 | |||
73 | tag.svg(svg.to_s.html_safe, | ||
74 | viewBox: "0 -30 410 430", | ||
75 | width: 410, | ||
76 | class: "pokemon-condition") | ||
77 | end | ||
78 | |||
3 | end | 79 | end |
4 | end | 80 | end |
diff --git a/app/views/pokeviewer/pokemon/show.html.haml b/app/views/pokeviewer/pokemon/show.html.haml index 232d6bc..3a04914 100644 --- a/app/views/pokeviewer/pokemon/show.html.haml +++ b/app/views/pokeviewer/pokemon/show.html.haml | |||
@@ -76,3 +76,4 @@ | |||
76 | %span.pokemon-nature<= @pokemon.nature.titlecase | 76 | %span.pokemon-nature<= @pokemon.nature.titlecase |
77 | nature. | 77 | nature. |
78 | %p= @pokemon.display_met | 78 | %p= @pokemon.display_met |
79 | = condition_diagram @pokemon.revisions.last | ||
diff --git a/pokeviewer.gemspec b/pokeviewer.gemspec index b3408ec..b803105 100644 --- a/pokeviewer.gemspec +++ b/pokeviewer.gemspec | |||
@@ -25,6 +25,7 @@ Gem::Specification.new do |s| | |||
25 | s.add_dependency 'normalize-rails' | 25 | s.add_dependency 'normalize-rails' |
26 | s.add_dependency 'coffee-rails', '~> 4.2' | 26 | s.add_dependency 'coffee-rails', '~> 4.2' |
27 | s.add_dependency 'jquery-rails' | 27 | s.add_dependency 'jquery-rails' |
28 | s.add_dependency 'victor' | ||
28 | 29 | ||
29 | s.add_development_dependency "sqlite3" | 30 | s.add_development_dependency "sqlite3" |
30 | end | 31 | end |