Class: GithubPolyglot::SVG
- Inherits:
-
Object
- Object
- GithubPolyglot::SVG
- Includes:
- LanguageStats
- Defined in:
- lib/github_polyglot/svg.rb,
lib/github_polyglot/svg/language_stats.rb
Overview
Generates SVG for language stats
Defined Under Namespace
Modules: LanguageStats
Constant Summary collapse
- WIDTH =
Width of the SVG image
300- BAR_HEIGHT =
Height of the language bar
8- BAR_PADDING =
Padding underneath the language bar
8- RADII =
Radii of rounded elements
5- OTHER_LANGUAGES =
The name of the entry for remaining languages.
:Other- DEFAULT_COLOR =
The default color to use if a language doesn’t have a color
'#EDEDED'- CSS =
The CSS text that gets applied to the SVG.
File.read(File.('svg.css', __dir__))
Constants included from LanguageStats
LanguageStats::LANGUAGE_NAME_CLASS, LanguageStats::LANGUAGE_PERCENTAGE_CLASS, LanguageStats::STATS_COLUMNS, LanguageStats::STAT_ROW_HEIGHT, LanguageStats::TOP_LANGUAGES
Instance Method Summary collapse
-
#generate ⇒ Object
Creates an SVG string.
-
#height ⇒ Object
Gets the height of the SVG.
-
#initialize(languages) ⇒ SVG
constructor
A new instance of SVG.
-
#radii ⇒ Object
Gets the radii of rounded elements.
-
#radius ⇒ Object
Alias for radii.
-
#width ⇒ Object
Gets the width of the SVG.
Constructor Details
#initialize(languages) ⇒ SVG
Returns a new instance of SVG.
34 35 36 |
# File 'lib/github_polyglot/svg.rb', line 34 def initialize(languages) @languages = languages end |
Instance Method Details
#generate ⇒ Object
Creates an SVG string
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/github_polyglot/svg.rb', line 39 def generate mask_id = 'mask' builder = Nokogiri::XML::Builder.new do |xml| xml.svg(xmlns: 'http://www.w3.org/2000/svg', width: width, height: height, viewBox: view_box) do xml.style(type: 'text/css') { xml.cdata(CSS) } body(xml, mask_id) end end builder.to_xml end |
#height ⇒ Object
Gets the height of the SVG
57 58 59 |
# File 'lib/github_polyglot/svg.rb', line 57 def height BAR_HEIGHT + BAR_PADDING + stats_height end |
#radii ⇒ Object
Gets the radii of rounded elements
62 63 64 |
# File 'lib/github_polyglot/svg.rb', line 62 def radii RADII end |
#radius ⇒ Object
Alias for radii
67 68 69 |
# File 'lib/github_polyglot/svg.rb', line 67 def radius RADII end |
#width ⇒ Object
Gets the width of the SVG
52 53 54 |
# File 'lib/github_polyglot/svg.rb', line 52 def width WIDTH end |