Merge remote-tracking branch 'upstream/pull/4431'

This commit is contained in:
Tom Hughes 2023-12-28 18:18:23 +00:00
commit a2a16dbd7a
38 changed files with 189 additions and 115 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 155 B

View file

@ -1,3 +0,0 @@
<svg xmlns='http://www.w3.org/2000/svg' width='50' height='3'>
<line x1='-2' x2='52' y1='1.5' y2='1.5' stroke='#bd6d6e' stroke-width='1.5' stroke-dasharray='6 2' />
</svg>

Before

Width:  |  Height:  |  Size: 172 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 232 B

View file

@ -1,3 +0,0 @@
<svg xmlns='http://www.w3.org/2000/svg' width='50' height='4'>
<rect x='-.5' y='.5' width='51' height='3' fill='#e2e3e2' stroke='#9a9a9a' />
</svg>

Before

Width:  |  Height:  |  Size: 148 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 205 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 96 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 103 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 203 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 147 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 211 B

View file

@ -1,4 +0,0 @@
<svg xmlns='http://www.w3.org/2000/svg' width='30' height='5' stroke='black'>
<line y1='0.5' y2='0.5' x2='30' />
<line y1='4.5' y2='4.5' x2='30' />
</svg>

Before

Width:  |  Height:  |  Size: 155 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 162 B

View file

@ -1,3 +0,0 @@
<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10'>
<rect x='.5' y='.5' width='9' height='9' fill='#b9a99c' stroke='#a99a8d' />
</svg>

Before

Width:  |  Height:  |  Size: 147 B

View file

@ -1,3 +0,0 @@
<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10'>
<rect x='.5' y='.5' width='9' height='9' fill='#c4b6ab' stroke='#a99a8d' />
</svg>

Before

Width:  |  Height:  |  Size: 147 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 203 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 92 B

View file

@ -1,3 +0,0 @@
<svg xmlns='http://www.w3.org/2000/svg' width='26' height='10'>
<rect x='.5' y='.5' width='25' height='9' fill='#ddecec' stroke='#9cf' stroke-dasharray='4 2' />
</svg>

Before

Width:  |  Height:  |  Size: 168 B

View file

@ -1,3 +0,0 @@
<svg xmlns='http://www.w3.org/2000/svg' width='26' height='10'>
<rect x='.5' y='.5' width='25' height='9' fill='#ddecec' stroke='#9cf' />
</svg>

Before

Width:  |  Height:  |  Size: 145 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 150 B

View file

@ -1,4 +0,0 @@
<svg xmlns='http://www.w3.org/2000/svg' width='52' height='3'>
<rect width='100%' height='100%' fill='#707070' />
<line x2='100%' y1='50%' y2='50%' stroke='white' stroke-dasharray='8' stroke-dashoffset='2' />
</svg>

Before

Width:  |  Height:  |  Size: 216 B

View file

@ -1,4 +0,0 @@
<svg xmlns='http://www.w3.org/2000/svg' width='52' height='4'>
<rect width='100%' height='100%' fill='#707070' />
<line x2='100%' y1='50%' y2='50%' stroke='white' stroke-dasharray='8' stroke-dashoffset='2' stroke-width='2' />
</svg>

Before

Width:  |  Height:  |  Size: 233 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 147 B

View file

@ -1,3 +0,0 @@
<svg xmlns='http://www.w3.org/2000/svg' width='52' height='3'>
<line x2='100%' y1='50%' y2='50%' stroke='#6e6e6e' stroke-width='1.5' />
</svg>

Before

Width:  |  Height:  |  Size: 143 B

View file

@ -1,4 +0,0 @@
<svg xmlns='http://www.w3.org/2000/svg' width='30' height='5' stroke='grey' stroke-dasharray='4 2' stroke-dashoffset='-1'>
<line y1='0.5' y2='0.5' x2='30' />
<line y1='4.5' y2='4.5' x2='30' />
</svg>

Before

Width:  |  Height:  |  Size: 200 B

View file

@ -1,3 +0,0 @@
<svg xmlns='http://www.w3.org/2000/svg' width='52' height='4'>
<rect x='-.5' y='.5' width='53' height='3' fill='#dddddd' stroke='#a1968b' />
</svg>

Before

Width:  |  Height:  |  Size: 148 B

View file

@ -1,3 +0,0 @@
<svg xmlns='http://www.w3.org/2000/svg' width='52' height='8'>
<rect x='-.5' y='.5' width='53' height='7' fill='#dddddd' stroke='#a1968b' />
</svg>

Before

Width:  |  Height:  |  Size: 148 B

View file

@ -1,3 +0,0 @@
<svg xmlns='http://www.w3.org/2000/svg' width='52' height='13'>
<rect x='-.5' y='.5' width='53' height='12' fill='#dddddd' stroke='#a1968b' />
</svg>

Before

Width:  |  Height:  |  Size: 150 B

View file

@ -1,3 +0,0 @@
<svg xmlns='http://www.w3.org/2000/svg' width='52' height='17'>
<rect x='-.5' y='.5' width='53' height='16' fill='#dddddd' stroke='#a1968b' />
</svg>

Before

Width:  |  Height:  |  Size: 150 B

View file

@ -1,3 +0,0 @@
<svg xmlns='http://www.w3.org/2000/svg' width='52' height='8'>
<rect x='-.5' y='.5' width='53' height='7' fill='#dddddd' stroke='#6d6d6d' />
</svg>

Before

Width:  |  Height:  |  Size: 148 B

View file

@ -1,4 +0,0 @@
<svg xmlns='http://www.w3.org/2000/svg' width='52' height='13'>
<rect x='-.5' y='.5' width='53' height='12' fill='#dddddd' stroke='#6d6d6d' />
<line x1='-4' x2='60' y1='6.5' y2='6.5' stroke='#ffffff' stroke-dasharray='12' />
</svg>

Before

Width:  |  Height:  |  Size: 232 B

View file

@ -1,4 +0,0 @@
<svg xmlns='http://www.w3.org/2000/svg' width='52' height='17'>
<rect x='-1' y='1' width='54' height='15' fill='#dddddd' stroke='#6d6d6d' stroke-width='2' />
<line x1='-4' x2='60' y1='8.5' y2='8.5' stroke='#ffffff' stroke-dasharray='12' />
</svg>

Before

Width:  |  Height:  |  Size: 247 B

View file

@ -1,3 +0,0 @@
<svg xmlns='http://www.w3.org/2000/svg' width='52' height='4'>
<rect x='-.5' y='.5' width='53' height='3' fill='#dddddd' stroke='#6d6d6d' />
</svg>

Before

Width:  |  Height:  |  Size: 148 B

View file

@ -1,4 +0,0 @@
<svg xmlns='http://www.w3.org/2000/svg' width='52' height='3'>
<rect width='100%' height='100%' fill='#868686' />
<line x2='100%' y1='50%' y2='50%' stroke='#eeeeee' stroke-dasharray='10 10' stroke-dashoffset='9' />
</svg>

Before

Width:  |  Height:  |  Size: 222 B

View file

@ -1,4 +0,0 @@
<svg xmlns='http://www.w3.org/2000/svg' width='52' height='4'>
<rect width='100%' height='100%' fill='#868686' />
<line x2='100%' y1='50%' y2='50%' stroke='#eeeeee' stroke-dasharray='10 10' stroke-dashoffset='9' stroke-width='2' />
</svg>

Before

Width:  |  Height:  |  Size: 239 B

View file

@ -1,7 +1,37 @@
module SvgHelper
def solid_svg_tag(width, height, fill, **options)
tag.svg :width => width, :height => height, **options do
tag.rect :width => "100%", :height => "100%", :fill => fill
def key_svg_tag(**options)
border_width = options["border"] ? (options["border-width"] || 1) : 0
rect_attrs = {
:width => "100%",
:height => "100%",
:fill => options["fill"] || "none"
}
if border_width.positive?
rect_attrs[:x] = rect_attrs[:y] = format("%g", 0.5 * border_width)
rect_attrs[:width] = options["width"] - border_width
rect_attrs[:height] = options["height"] - border_width
end
svg_attrs = options.slice("width", "height", "opacity", :class)
tag.svg(**svg_attrs) do
horizontal = "H#{options['width']}"
concat tag.rect(**rect_attrs, **stroke_attrs(options, "border")) if options["fill"] || options["border"]
if options["line"]
y_middle = format("%g", 0.5 * options["height"])
concat tag.path(:d => "M0,#{y_middle} #{horizontal}", **stroke_attrs(options, "line"))
end
if options["casing"]
casing_width = options["casing-width"] || 1
y_top = format("%g", 0.5 * casing_width)
y_bottom = format("%g", options["height"] - (0.5 * casing_width))
concat tag.path(:d => "M0,#{y_top} #{horizontal} M0,#{y_bottom} #{horizontal}", **stroke_attrs(options, "casing"))
end
end
end
private
def stroke_attrs(attrs, prefix)
attrs.select { |key| key.start_with?(prefix) }.transform_keys { |key| key.delete_prefix(prefix).prepend("stroke") }
end
end

View file

@ -4,10 +4,10 @@
<% layer_data.each do |entry| %>
<%= tag.tr :class => "mapkey-table-entry", :data => { :layer => layer_name, :zoom_min => entry["min_zoom"], :zoom_max => entry["max_zoom"] } do %>
<td>
<% if entry["width"] && entry["height"] && entry["fill"] %>
<%= solid_svg_tag entry["width"], entry["height"], entry["fill"], :class => "d-block mx-auto" %>
<% else %>
<% if entry["image"] %>
<%= image_tag "key/#{layer_name}/#{entry['image']}", :class => "d-block mx-auto" %>
<% else %>
<%= key_svg_tag :class => "d-block mx-auto", **entry %>
<% end %>
</td>
<td>

View file

@ -1,24 +1,24 @@
mapnik:
# transportation: roads.mss
- { min_zoom: 6, name: motorway, image: motorway.png }
- { min_zoom: 6, name: motorway, width: 52, height: 5, fill: "#e892a2", casing: "#dc2a67" }
- { min_zoom: 6, name: main_road, image: mainroad.png }
- { min_zoom: 8, name: main_road, image: mainroad8.png }
- { min_zoom: 12, name: main_road, image: mainroad12.png }
- { min_zoom: 13, name: track, image: track.png }
- { min_zoom: 13, name: bridleway, image: bridleway.png }
- { min_zoom: 13, name: cycleway, image: cycleway.png }
- { min_zoom: 13, name: footway, image: footway.png }
- { min_zoom: 13, name: track, width: 52, height: 3, opacity: .8, line: "#996600", line-width: 1.5, line-dasharray: "6 5" }
- { min_zoom: 13, name: bridleway, width: 52, height: 3, line: green, line-width: 1.25, line-dasharray: "4 2" }
- { min_zoom: 13, name: cycleway, width: 52, height: 1, line: blue, line-dasharray: "3 3.5" }
- { min_zoom: 13, name: footway, width: 52, height: 3, line: salmon, line-width: 1.3, line-dasharray: "3 3.5" }
- { min_zoom: 8, name: rail, width: 52, height: 1, fill: "#787878" }
- { min_zoom: 12, name: rail, image: rail12.svg }
- { min_zoom: 18, name: rail, image: rail18.svg }
- { min_zoom: 12, name: rail, width: 52, height: 3, fill: "#707070", line: white, line-dasharray: 8, line-dashoffset: 2 }
- { min_zoom: 18, name: rail, width: 52, height: 4, fill: "#707070", line: white, line-dasharray: 8, line-dashoffset: 2, line-width: 2 }
- { min_zoom: 12, name: subway, width: 52, height: 2, fill: "#999" }
- { min_zoom: 8, name: light_rail, width: 52, height: 1, fill: "#ccc" }
- { min_zoom: 10, name: light_rail, width: 52, height: 1, fill: "#aaa" }
- { min_zoom: 13, name: light_rail, width: 52, height: 2, fill: "#666" }
- { min_zoom: 12, name: tram_only, width: 52, height: 1, fill: "#6e6e6eaa" }
- { min_zoom: 14, name: tram_only, width: 52, height: 1, fill: "#6e6e6e" }
- { min_zoom: 15, name: tram_only, image: tram15.svg }
- { min_zoom: 17, name: tram_only, width: 52, height: 2, fill: "#6e6e6e" }
- { min_zoom: 12, name: tram_only, width: 52, height: 1, line: "#6e6e6e", line-width: 0.75 }
- { min_zoom: 14, name: tram_only, width: 52, height: 3, line: "#6e6e6e", line-width: 1 }
- { min_zoom: 15, name: tram_only, width: 52, height: 3, line: "#6e6e6e", line-width: 1.5 }
- { min_zoom: 17, name: tram_only, width: 52, height: 2, line: "#6e6e6e", line-width: 2 }
- { min_zoom: 12, name: [cable_car, chair_lift], image: cable.png }
- { min_zoom: 11, name: [runway_only, taxiway], image: runway11.svg }
- { min_zoom: 12, name: [runway_only, taxiway], image: runway12.svg }
@ -30,8 +30,8 @@ mapnik:
# landcover z5: landcover.mss, water.mss
- { name: [lake_only, reservoir], width: 26, height: 10, fill: "#aad3df" }
- { name: intermittent_water, image: intermittent_water.svg }
- { min_zoom: 5, name: glacier, image: glacier5.svg }
- { min_zoom: 10, name: glacier, image: glacier10.svg }
- { min_zoom: 5, name: glacier, width: 26, height: 10, fill: "#ddecec", border: "#9cf" }
- { min_zoom: 10, name: glacier, width: 26, height: 10, fill: "#ddecec", border: "#9cf", border-dasharray: "4 2" }
- { min_zoom: 10, name: reef, image: reef.png }
- { min_zoom: 10, name: wetland, image: wetland.png }
- { min_zoom: 5, name: [forest_only, wood], width: 26, height: 10, fill: "#bddab1" }
@ -74,40 +74,42 @@ mapnik:
- { min_zoom: 13, name: [school_only, university, hospital], image: school.svg }
# buildings: buildings.mss
- { min_zoom: 14, name: building, width: 10, height: 10, fill: "#ab9793" }
- { min_zoom: 15, name: building, image: building15.svg }
- { min_zoom: 16, name: building, image: building16.svg }
- { min_zoom: 15, name: building, width: 10, height: 10, fill: "#b9a99c", border: "#a99a8d" }
- { min_zoom: 16, name: building, width: 10, height: 10, fill: "#c4b6ab", border: "#a99a8d" }
# stations: stations.mss
- { min_zoom: 12, name: station, width: 4, height: 4, fill: "#7981b0" }
- { min_zoom: 13, name: station, width: 6, height: 6, fill: "#7981b0" }
- { min_zoom: 15, name: station, width: 9, height: 9, fill: "#7981b0" }
# other
- { min_zoom: 11, name: [summit_only, peak], image: summit.svg } # amenity-points.mss
- { min_zoom: 13, name: tunnel, image: tunnel.svg } # roads.mss
- { min_zoom: 13, name: bridge, image: bridge.svg } # roads.mss
- { min_zoom: 13, name: tunnel, width: 50, height: 5, casing: grey, casing-dasharray: "4 2", casing-dashoffset: 1 } # roads.mss
- { min_zoom: 13, name: bridge, width: 50, height: 5, casing: black } # roads.mss
- { min_zoom: 15, name: private, image: private.png }
- { min_zoom: 15, name: destination, image: destination.png }
- { min_zoom: 12, name: construction, image: construction.png }
cyclemap:
- { min_zoom: 5, name: motorway, width: 50, height: 3, fill: "#9a9ab1" }
- { min_zoom: 12, name: motorway, image: motorway12.png }
- { min_zoom: 12, name: motorway, width: 50, height: 5, fill: "#bdbece", casing: "#8d95a7" }
- { min_zoom: 6, name: trunk, width: 50, height: 2, fill: "#c8d8c8" }
- { min_zoom: 12, name: trunk, image: trunk12.png }
- { min_zoom: 12, name: trunk, width: 50, height: 5, fill: "#c8d8c8", casing: "#abb5a4" }
- { min_zoom: 8, name: primary, width: 50, height: 2, fill: "#d8c8c8" }
- { min_zoom: 12, name: primary, image: primary12.png }
- { min_zoom: 12, name: primary, width: 50, height: 4, fill: "#f0e3e3", casing: "#d4b6b7" }
- { min_zoom: 10, name: secondary, width: 50, height: 1, fill: "#dadacc" }
- { min_zoom: 12, name: secondary, image: secondary12.png }
- { min_zoom: 15, name: pedestrian, image: pedestrian.svg }
- { min_zoom: 13, name: track, image: track.png }
- { min_zoom: 8, name: cycleway, image: cycleway.png }
- { min_zoom: 12, name: secondary, width: 50, height: 4, fill: "#ededc8", casing: "#c8b48a" }
- { min_zoom: 15, name: pedestrian, width: 50, height: 4, fill: "#e2e3e2", casing: "#9a9a9a" }
- { min_zoom: 13, name: track, width: 50, height: 3, fill: white, casing: "#999", casing-dasharray: "5 3", casing-dashoffset: 1 }
- { min_zoom: 15, name: track, width: 50, height: 4, fill: white, casing: "#999", casing-dasharray: "5 3", casing-dashoffset: 1 }
- { min_zoom: 17, name: track, width: 50, height: 5, fill: white, casing: "#999", casing-dasharray: "5 3", casing-dashoffset: 1 }
- { min_zoom: 8, name: cycleway, width: 50, height: 3, line: "#0100fe", line-width: 1.5, line-dasharray: "6 2" }
- { min_zoom: 5, name: cycleway_national, width: 50, height: 2, fill: "#fe0000" }
- { min_zoom: 13, name: cycleway_national, width: 50, height: 4, fill: "#ffb3b3" }
- { min_zoom: 7, name: cycleway_regional, width: 50, height: 2, fill: "#b638fb" }
- { min_zoom: 13, name: cycleway_regional, width: 50, height: 4, fill: "#ddb5d9" }
- { min_zoom: 8, name: cycleway_local, width: 50, height: 2, fill: "#0100fe" }
- { min_zoom: 13, name: cycleway_local, width: 50, height: 4, fill: "#b2b2ff" }
- { min_zoom: 13, name: footway, image: footway.svg }
- { min_zoom: 7, name: rail, image: rail.png }
- { min_zoom: 14, name: rail, image: rail14.png }
- { min_zoom: 13, name: footway, width: 50, height: 3, line: "#bd6d6e", line-width: 1.5, line-dasharray: "6 2" }
- { min_zoom: 7, name: rail, width: 50, height: 3, line: "#999999", line-width: 1.5 }
- { min_zoom: 14, name: rail, width: 50, height: 4, fill: "#999999", line: white, line-dasharray: 4, line-width: 2 }
- { min_zoom: 1, name: [lake_only, reservoir], width: 26, height: 10, fill: "#addeff" }
- { min_zoom: 9, name: [forest_only, wood], width: 26, height: 10, fill: "#b3d6a4" }
- { min_zoom: 10, name: meadow, width: 26, height: 10, fill: "#c0de9c" }
@ -119,8 +121,8 @@ cyclemap:
opnvkarte:
- { min_zoom: 6, name: rail, width: 52, height: 1, fill: "#868686" }
- { min_zoom: 8, name: rail, width: 52, height: 2, fill: "#868686" }
- { min_zoom: 11, name: rail, image: rail11.svg }
- { min_zoom: 15, name: rail, image: rail15.svg }
- { min_zoom: 11, name: rail, width: 52, height: 3, fill: "#868686", line: "#eeeeee", line-dasharray: 10, line-dashoffset: 9 }
- { min_zoom: 15, name: rail, width: 52, height: 4, fill: "#868686", line: "#eeeeee", line-dasharray: 10, line-dashoffset: 9, line-width: 2 }
- { min_zoom: 17, name: rail, image: rail17.svg }
- { min_zoom: 6, name: train, width: 52, height: 2, fill: "#ffc366" }
- { min_zoom: 10, name: train, width: 52, height: 3, fill: "#ffc366" }
@ -154,15 +156,15 @@ opnvkarte:
- { min_zoom: 15, name: bus_stop, image: bus_stop15.svg }
- { min_zoom: 13, name: stop, image: stop13.svg }
- { min_zoom: 15, name: stop, image: stop15.svg }
- { min_zoom: 8, name: motorway, image: motorway8.svg }
- { min_zoom: 13, name: motorway, image: motorway13.svg }
- { min_zoom: 15, name: motorway, image: motorway15.svg }
- { min_zoom: 17, name: motorway, image: motorway17.svg }
- { min_zoom: 8, name: main_road, width: 52, height: 1, fill: "#5c6d6d88" }
- { min_zoom: 11, name: main_road, image: main_road11.svg }
- { min_zoom: 13, name: main_road, image: main_road13.svg }
- { min_zoom: 15, name: main_road, image: main_road15.svg }
- { min_zoom: 17, name: main_road, image: main_road17.svg }
- { min_zoom: 8, name: motorway, width: 52, height: 4, fill: "#dddddd", casing: "#6d6d6d" }
- { min_zoom: 13, name: motorway, width: 52, height: 8, fill: "#dddddd", casing: "#6d6d6d" }
- { min_zoom: 15, name: motorway, width: 52, height: 13, fill: "#dddddd", casing: "#6d6d6d", line: "#ffffff", line-dasharray: 12, line-dashoffset: 4 }
- { min_zoom: 17, name: motorway, width: 52, height: 17, fill: "#dddddd", casing: "#6d6d6d", line: "#ffffff", line-dasharray: 12, line-dashoffset: 4, casing-width: 2 }
- { min_zoom: 8, name: main_road, width: 52, height: 1, fill: "#5c6d6d88" }
- { min_zoom: 11, name: main_road, width: 52, height: 4, fill: "#dddddd", casing: "#a1968b" }
- { min_zoom: 13, name: main_road, width: 52, height: 8, fill: "#dddddd", casing: "#a1968b" }
- { min_zoom: 15, name: main_road, width: 52, height: 13, fill: "#dddddd", casing: "#a1968b" }
- { min_zoom: 17, name: main_road, width: 52, height: 17, fill: "#dddddd", casing: "#a1968b" }
# landcover
- { min_zoom: 0, name: [lake_only, reservoir], width: 26, height: 10, fill: "#a1cbea" }
- { min_zoom: 8, name: [lake_only, reservoir], width: 26, height: 10, fill: "#bfd3ef" }

View file

@ -0,0 +1,113 @@
require "test_helper"
class SvgHelperTest < ActionView::TestCase
def test_key_fill
svg = key_svg_tag("width" => 60, "height" => 40, "fill" => "green")
expected = <<~HTML.gsub(/\n\s*/, "")
<svg width="60" height="40">
<rect width="100%" height="100%" fill="green" />
</svg>
HTML
assert_dom_equal expected, svg
end
def test_key_border
svg = key_svg_tag("width" => 60, "height" => 40, "border" => "red")
expected = <<~HTML.gsub(/\n\s*/, "")
<svg width="60" height="40">
<rect x="0.5" y="0.5" width="59" height="39" fill="none" stroke="red" />
</svg>
HTML
assert_dom_equal expected, svg
end
def test_key_border_width
svg = key_svg_tag("width" => 60, "height" => 40, "border" => "red", "border-width" => 3)
expected = <<~HTML.gsub(/\n\s*/, "")
<svg width="60" height="40">
<rect x="1.5" y="1.5" width="57" height="37" fill="none" stroke="red" stroke-width="3" />
</svg>
HTML
assert_dom_equal expected, svg
end
def test_key_border_with_integer_coords
svg = key_svg_tag("width" => 60, "height" => 40, "border" => "red", "border-width" => 2)
expected = <<~HTML.gsub(/\n\s*/, "")
<svg width="60" height="40">
<rect x="1" y="1" width="58" height="38" fill="none" stroke="red" stroke-width="2" />
</svg>
HTML
assert_dom_equal expected, svg
end
def test_key_border_fractional_width
svg = key_svg_tag("width" => 60, "height" => 40, "border" => "red", "border-width" => 1.5)
expected = <<~HTML.gsub(/\n\s*/, "")
<svg width="60" height="40">
<rect x="0.75" y="0.75" width="58.5" height="38.5" fill="none" stroke="red" stroke-width="1.5" />
</svg>
HTML
assert_dom_equal expected, svg
end
def test_key_line
svg = key_svg_tag("width" => 80, "height" => 15, "line" => "blue")
expected = <<~HTML.gsub(/\n\s*/, "")
<svg width="80" height="15">
<path d="M0,7.5 H80" stroke="blue" />
</svg>
HTML
assert_dom_equal expected, svg
end
def test_key_line_width
svg = key_svg_tag("width" => 80, "height" => 15, "line" => "blue", "line-width" => 3)
expected = <<~HTML.gsub(/\n\s*/, "")
<svg width="80" height="15">
<path d="M0,7.5 H80" stroke="blue" stroke-width="3" />
</svg>
HTML
assert_dom_equal expected, svg
end
def test_key_line_with_integer_coords
svg = key_svg_tag("width" => 80, "height" => 20, "line" => "blue")
expected = <<~HTML.gsub(/\n\s*/, "")
<svg width="80" height="20">
<path d="M0,10 H80" stroke="blue" />
</svg>
HTML
assert_dom_equal expected, svg
end
def test_key_casing
svg = key_svg_tag("width" => 80, "height" => 20, "casing" => "yellow")
expected = <<~HTML.gsub(/\n\s*/, "")
<svg width="80" height="20">
<path d="M0,0.5 H80 M0,19.5 H80" stroke="yellow" />
</svg>
HTML
assert_dom_equal expected, svg
end
def test_key_casing_width
svg = key_svg_tag("width" => 80, "height" => 20, "casing" => "yellow", "casing-width" => 5)
expected = <<~HTML.gsub(/\n\s*/, "")
<svg width="80" height="20">
<path d="M0,2.5 H80 M0,17.5 H80" stroke="yellow" stroke-width="5" />
</svg>
HTML
assert_dom_equal expected, svg
end
def test_key_casing_with_integer_coords
svg = key_svg_tag("width" => 80, "height" => 20, "casing" => "yellow", "casing-width" => 2)
expected = <<~HTML.gsub(/\n\s*/, "")
<svg width="80" height="20">
<path d="M0,1 H80 M0,19 H80" stroke="yellow" stroke-width="2" />
</svg>
HTML
assert_dom_equal expected, svg
end
end