charta 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a9634870840f818207264c46799dc53cf3e37bf3f3d119e85dc470405ebcb8d1
4
- data.tar.gz: 6453c04a73201f197c869b37d18a6ff0c262c8545ced384a13ecee48568279e1
3
+ metadata.gz: 96bee13636a087302272ef4bc271ca0200e46aece932f932a2c9ff6b989254a8
4
+ data.tar.gz: 4d139f4c3d628b178862b6879edc2ba92e11f82e96f43d748def1ac063c89562
5
5
  SHA512:
6
- metadata.gz: 658472714de5dbe3a618839ddf36858884b6d28ab520bab2c5140514d0a287931b52aa1278110dc3979a3ed40b2bc0c7cb7e11a9450bff9767ae32180ebe24f8
7
- data.tar.gz: 675ea3982c1d1bb3465f68e272fb995dde17cc61f5af81837346a7431fc79d1fc82dc0661eb2528aab2903808d6e0941d20923fa62142db25eafa95eb32a00f6
6
+ metadata.gz: 04b4a7e56bc7a412114f4f2713725d1304bc4c859911a2079a847b88511d80c5f20057df7a19f79c6b022b107ff9b1328b064084f0ebdf1e5335622afbff7f27
7
+ data.tar.gz: 3f8cec56a64a686abcfd14264df20b593c396fb0296b779b48c2697a630ad9bed6d16de61a86c12995fec6f74e5a1cf4ac1f65655e244a840393ea5448fd00ed
data/charta.gemspec CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_dependency 'rgeo', '~> 2.0'
22
22
  spec.add_dependency 'rgeo-geojson', '~> 2.0'
23
23
  spec.add_dependency 'rgeo-proj4', '~> 2.0'
24
+ spec.add_dependency 'victor', '~> 0.3.3'
24
25
  spec.add_dependency 'zeitwerk', '~> 2.4.0'
25
26
 
26
27
  spec.add_development_dependency 'bundler', '~> 2.0'
@@ -18,7 +18,7 @@ module Charta
18
18
  end
19
19
 
20
20
  def svg_view_box
21
- [x_min, -y_max, width, height]
21
+ [x_min, y_min, width, height]
22
22
  end
23
23
 
24
24
  def to_a
@@ -30,7 +30,7 @@ module Charta
30
30
  if coordinates.is_a?(Charta::Geometry)
31
31
  coordinates
32
32
  elsif coordinates.is_a?(RGeo::Feature::Instance)
33
- new_feature(Charta.generate_ewkt(coordinates))
33
+ Geometry.feature(coordinates)
34
34
  elsif coordinates.to_s =~ /\A[[:space:]]*\z/
35
35
  empty_feature(srs)
36
36
  else
@@ -2,6 +2,7 @@ require 'json'
2
2
  require 'rgeo/geo_json'
3
3
  require 'rgeo/svg' # integrated lib for now
4
4
  require 'active_support/core_ext/module/delegation'
5
+ require 'victor' # for SVG
5
6
 
6
7
  module Charta
7
8
  # Represents a Geometry with SRID
@@ -63,16 +64,36 @@ module Charta
63
64
 
64
65
  alias to_ewkb to_binary
65
66
 
66
- # Pas bien compris le fonctionnement
67
+ # Generate SVG from geometry
68
+ # @param [Hash] options , the options for SVG object.
69
+ # @option options [Hash] :mode could be :stroke or :fill
70
+ # @option options [Hash] :color could be "orange", "red", "blue" or HTML color "#14TF15"
71
+ # @option options [Hash] :fill_opacity could be '0' to '100'
72
+ # @option options [Hash] :stroke_linecap could be 'round', 'square', 'butt'
73
+ # @option options [Hash] :stroke_linejoin default 'round'
74
+ # @option options [Hash] :stroke_width default '5%'
75
+ # @note more informations on https://developer.mozilla.org/fr/docs/Web/SVG/Tutorial/Fills_and_Strokes
76
+ # @return [String] the SVG image
67
77
  def to_svg(options = {})
68
- svg = '<svg xmlns="http://www.w3.org/2000/svg" version="1.1"'
69
- { preserve_aspect_ratio: 'xMidYMid meet',
70
- width: 180, height: 180,
71
- view_box: bounding_box.svg_view_box.join(' ') }.merge(options).each do |attr, value|
72
- svg << " #{Charta.camelcase(attr.to_s, :lower)}=\"#{value}\""
78
+ # set default options if not present
79
+ options[:mode] ||= :stroke
80
+ options[:color] ||= 'black'
81
+ options[:fill_opacity] ||= '100' # 0 to 100
82
+ options[:stroke_linecap] ||= 'butt' # round, square, butt
83
+ options[:stroke_linejoin] ||= 'round' #
84
+ options[:stroke_width] ||= '5%'
85
+
86
+ svg = Victor::SVG.new template: :html
87
+ svg.setup width: 180, height: 180, viewBox: bounding_box.svg_view_box.join(' ')
88
+ # return a stroke SVG with options
89
+ if options[:mode] == :stroke
90
+ svg.path d: to_svg_path, fill: 'none', stroke: options[:color], stroke_linecap: options[:stroke_linecap],
91
+ stroke_linejoin: options[:stroke_linejoin], stroke_width: options[:stroke_width]
92
+ # return a fill SVG with options
93
+ elsif options[:mode] == :fill
94
+ svg.path d: to_svg_path, fill: options[:color], fill_opacity: options[:fill_opacity]
73
95
  end
74
- svg << "><path d=\"#{to_svg_path}\"/></svg>"
75
- svg
96
+ svg.render
76
97
  end
77
98
 
78
99
  # Return the geometry as Scalar Vector Graphics (SVG) path data.
@@ -1,3 +1,3 @@
1
1
  module Charta
2
- VERSION = '0.3.1'.freeze
2
+ VERSION = '0.4.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: charta
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ekylibre developers
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-15 00:00:00.000000000 Z
11
+ date: 2021-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '2.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: victor
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.3.3
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.3.3
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: zeitwerk
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -164,7 +178,7 @@ dependencies:
164
178
  - - '='
165
179
  - !ruby/object:Gem::Version
166
180
  version: 1.3.1
167
- description:
181
+ description:
168
182
  email:
169
183
  - dev@ekylibre.com
170
184
  executables: []
@@ -206,7 +220,7 @@ homepage: https://gitlab.com/ekylibre
206
220
  licenses:
207
221
  - AGPL-3.0-only
208
222
  metadata: {}
209
- post_install_message:
223
+ post_install_message:
210
224
  rdoc_options: []
211
225
  require_paths:
212
226
  - lib
@@ -221,8 +235,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
221
235
  - !ruby/object:Gem::Version
222
236
  version: '0'
223
237
  requirements: []
224
- rubygems_version: 3.0.3
225
- signing_key:
238
+ rubygems_version: 3.2.26
239
+ signing_key:
226
240
  specification_version: 4
227
241
  summary: Simple tool over geos and co
228
242
  test_files: []