waxy 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d89aacf98d963b4e37d64245c278dc5c29254827b72b63222fa480d7cd9873ac
4
+ data.tar.gz: 2624d4371c49a06cd5b47c227e8cd3f9ee1882ccd2115c3c14b11fc27937cea3
5
+ SHA512:
6
+ metadata.gz: 7a371d450d4f1bd5cabaa56a62435e5dc39261d80ab62f1c7ce479a3ed1d438ad56127f4eed042572180a2466f4e28ae5e7e83ea6474f97f3f4aba31806f4991
7
+ data.tar.gz: 650b6dfeda31f52b1b34d5fd7c699e4ca0e974b284176d2b0e63268de1a6622600517032a1463e3313413bc0720698ef7b0dcc2610f2eb2248eda3873b1fe965
@@ -0,0 +1,17 @@
1
+ .DS_Store
2
+
3
+ /.bundle/
4
+ /.yardoc
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
14
+
15
+
16
+ index.html
17
+ go.rb
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.1
7
+ before_install: gem install bundler -v 2.0.1
@@ -0,0 +1,9 @@
1
+
2
+ # 0.0.1
3
+
4
+ * Something to work with in other applications, highly experimental
5
+ * Basic hexagon and layout rendering, with ability to customize properties of hexagon slices
6
+ * A servicable rectangular layout
7
+ * Ability to provide HTML links to hex elements
8
+ * Basic specs
9
+ * Various largely untested layout experiments
@@ -0,0 +1,76 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, sex characteristics, gender identity and expression,
9
+ level of experience, education, socio-economic status, nationality, personal
10
+ appearance, race, religion, or sexual identity and orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at mjyoder@illinois.edu. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72
+
73
+ [homepage]: https://www.contributor-covenant.org
74
+
75
+ For answers to common questions about this code of conduct, see
76
+ https://www.contributor-covenant.org/faq
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in waxy.gemspec
4
+ gemspec
@@ -0,0 +1,41 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ waxy (0.1.0)
5
+ tilt (~> 2.0.9)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ awesome_print (1.8.0)
11
+ byebug (11.0.1)
12
+ diff-lcs (1.3)
13
+ rake (12.3.2)
14
+ rspec (3.8.0)
15
+ rspec-core (~> 3.8.0)
16
+ rspec-expectations (~> 3.8.0)
17
+ rspec-mocks (~> 3.8.0)
18
+ rspec-core (3.8.0)
19
+ rspec-support (~> 3.8.0)
20
+ rspec-expectations (3.8.2)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.8.0)
23
+ rspec-mocks (3.8.0)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.8.0)
26
+ rspec-support (3.8.0)
27
+ tilt (2.0.9)
28
+
29
+ PLATFORMS
30
+ ruby
31
+
32
+ DEPENDENCIES
33
+ awesome_print
34
+ bundler (~> 2.0)
35
+ byebug (~> 11)
36
+ rake (~> 12.0)
37
+ rspec (~> 3.8)
38
+ waxy!
39
+
40
+ BUNDLED WITH
41
+ 2.0.1
@@ -0,0 +1,16 @@
1
+ University of Illinois/NCSA Open Source License
2
+
3
+ Copyright (c) 2019 Species File Group
4
+ All rights reserved.
5
+
6
+ Developed by: Species File Group
7
+ INHS
8
+ https://github.com/SpeciesFileGroup/
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal with the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
11
+
12
+ Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimers.
13
+ Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimers in the documentation and/or other materials provided with the distribution.
14
+ Neither the names of <Name of Development Group, Name of Institution>, nor the names of its contributors may be used to endorse or promote products derived from this Software without specific prior written permission.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
@@ -0,0 +1,86 @@
1
+ [![Continuous Integration Status][1]][2]
2
+
3
+ # Waxy
4
+
5
+ Waxy is an experimental visualization tool to generate SVG hexagons and their layouts, it is in Ruby.
6
+
7
+ The library is solely possible thanks to the wonderful Amit Patel sharing his knowledge at [the Red Blob Games blog](https://www.redblobgames.com/), in particular [the hexagon tutorial](https://www.redblobgames.com/grids/hexagons/). Most of the serious code herein is simply an implementation of the metacode therein. All of the misinterpretations and problems are ours, not Amit's!
8
+
9
+ ![random](/examples/img/random.png)
10
+ ![rectangle](/examples/img/rectangle.png)
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'waxy'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install waxy
27
+
28
+ ## Usage
29
+
30
+ _The API will most certainly change if/when the code is deemed more than a playground. Nothing is really optimized._
31
+
32
+ ```Ruby
33
+ require 'waxy'
34
+
35
+ srand
36
+
37
+ layout = Waxy::Geometry::Layout.new(
38
+ Waxy::Geometry::Orientation::LAYOUT_POINTY,
39
+ Waxy::Geometry::Point.new(20,20), # size
40
+ Waxy::Geometry::Point.new(20, 20), # start
41
+ 5.0 # padding
42
+ )
43
+
44
+ meta = []
45
+
46
+ (0..400).each do |i|
47
+ a = Waxy::Meta.new
48
+ a.size = (0..5).collect{ rand(0.0..1.0) }
49
+ a.stroke = 'purple'
50
+ a.link = 'http://127.0.0.1:3000/'
51
+ a.link_title = "RECORD #{i}"
52
+
53
+ meta.push a
54
+ end
55
+
56
+ meta.sort!{ |a,b| a.sum_size <=> b.sum_size }
57
+
58
+ c = Waxy::Render::Svg::Canvas.new(1000, 1000)
59
+ c.body << Waxy::Render::Svg.rectangle(layout, meta, 5)
60
+ puts c.to_svg
61
+ ```
62
+
63
+ then
64
+
65
+ ```Bash
66
+ ruby go.rb > svg.html
67
+ open svg.html
68
+ ```
69
+
70
+ ## Development
71
+
72
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
73
+
74
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
75
+
76
+ ## Contributing
77
+
78
+ Bug reports and pull requests are welcome on GitHub at https://github.com/SpeciesFileGroup/waxy.
79
+
80
+ ## License
81
+
82
+ The gem is available as open source under the terms of the [NCSA](https://opensource.org/licenses/NCSA).
83
+
84
+ [1]: https://secure.travis-ci.org/SpeciesFileGroup/waxy.png?branch=master
85
+ [2]: http://travis-ci.org/SpeciesFileGroup/waxy?branch=master
86
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "waxy"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
Binary file
@@ -0,0 +1,71 @@
1
+ require_relative "waxy/version"
2
+ require_relative "waxy/geometry"
3
+ require_relative "waxy/render"
4
+ require_relative "waxy/meta"
5
+
6
+ module Waxy
7
+ class Error < StandardError; end
8
+
9
+ COLORS = {
10
+ 1 => 'yellow',
11
+ 2 => 'orange',
12
+ 3 => 'red',
13
+ 4 => 'purple',
14
+ 5 => 'blue',
15
+ 6 => 'green'
16
+ }
17
+
18
+ end
19
+
20
+
21
+ # total = 100
22
+
23
+ # def point(center, size, i)
24
+ # angle_deg = 60.0 * i
25
+ # angle_rad = Math::PI / 180 * angle_deg
26
+ # return ((center.x + size) * Math.cos(angle_rad)), ((center.y + size ) * Math.sin(angle_rad))
27
+ # end
28
+
29
+ # def triangle(center, size, i)
30
+ # points = []
31
+ # points.push [0,0]
32
+ # points.push point(center, size, i)
33
+ # points.push point(center, size, (i + 1 == 7 ? 1 : i + 1))
34
+ # points
35
+ # end
36
+
37
+ # def hexagon(sizes)
38
+ # center = Center.new(SIZE, SIZE)
39
+ # triangles = []
40
+ # sizes.each_with_index do |s, i|
41
+ # next if s < 1.0
42
+ # triangles.push triangle(center, s, i.to_f)
43
+ # end
44
+
45
+ # triangles.each_with_index do |t, i|
46
+ # color = COLORS[i + 1]
47
+ # puts "<polygon fill=\"#{color}\" class=\"triangle\" points=\"#{t.collect{|p| p.join(',')}.join(' ')}\"></polygon>"
48
+ # puts "<line x1=\"0\" y1=\"0\" x2=\"#{t[1][0]}\" y2=\"#{t[1][1]}\" stroke=\"white\" width=\"2\" />"
49
+ # puts "<line x1=\"0\" y1=\"0\" x2=\"#{t[2][0]}\" y2=\"#{t[2][1]}\" stroke=\"white\" width=\"2\" />"
50
+ # end
51
+ # end
52
+
53
+ # puts '<svg id="image-fill" xmlns="http://www.w3.org/2000/svg" version="1.1" width="100%" height="1000" xmlns:xlink="http://www.w3.org/1999/xlink">'
54
+
55
+ # i = 0.0
56
+ # j = 0.0
57
+
58
+ # total.times.each do |z|
59
+ # sizes = (1..6).collect{|s| rand(0..SIZE) }
60
+
61
+ # puts "<g transform=\"translate(#{(i * 50.0) + 50.0} , #{(j * 50.0 + 50.0)})\">"
62
+ # hexagon(sizes)
63
+ # puts '</g>'
64
+ # i += 1
65
+ # if i > 9
66
+ # i = 0
67
+ # j = j + 1
68
+ # end
69
+ # end
70
+
71
+ # puts '</svg>'
@@ -0,0 +1,60 @@
1
+ require_relative 'geometry/point'
2
+ require_relative 'geometry/layout'
3
+ require_relative 'geometry/hex'
4
+ require_relative 'geometry/fractional_hex'
5
+ require_relative 'geometry/orientation'
6
+
7
+ module Waxy
8
+
9
+ # This is an implmentation of https://www.redblobgames.com/grids/hexagons/implementation.html.
10
+ # Thank you for that wonderful tutorial.
11
+ module Geometry
12
+
13
+ # TODO(matt) not right to be here
14
+ h = Waxy::Geometry::Hex
15
+
16
+ SIZE = 10.0
17
+
18
+ # https://www.redblobgames.com/grids/hexagons/#neighbors-axial
19
+ # POINTY
20
+ # q, r, s
21
+ HEX_DIRECTIONS_FLAT = [
22
+ h.new( 1, 0, -1),
23
+ h.new( 0, 1, -1),
24
+ h.new( -1, 1, 0),
25
+ h.new(-1, 0, 1),
26
+ h.new(0, -1, 1),
27
+ h.new( 1, -1, 0)
28
+ ]
29
+
30
+ HEX_DIRECTIONS_POINTY = [
31
+ h.new(0, 1, -1),
32
+ h.new(-1, 1, 0),
33
+ h.new(-1, 0, 1),
34
+ h.new(0, -1, 1),
35
+ h.new(1, -1, 0),
36
+ h.new(1, 0, -1)
37
+ ]
38
+
39
+ def self.point(center, size, i)
40
+ angle_deg = 60.0 * i
41
+ angle_rad = Math::PI / 180 * angle_deg
42
+ return ((center.x + size) * Math.cos(angle_rad)), ((center.y + size ) * Math.sin(angle_rad))
43
+ end
44
+
45
+ def self.hexagon(center, size)
46
+ Hex.new(
47
+ outer_coords: (1..6).collect{|i| point(center, size, i)}
48
+ )
49
+ end
50
+
51
+ def self.triangle(center, size, i)
52
+ points = [[0,0]]
53
+ points.push point(center, size, i)
54
+ points.push point(center, size, (i + 1 == 7 ? 1 : i + 1))
55
+ points
56
+ end
57
+ end
58
+ end
59
+
60
+