svg-graph 2.2.1 → 2.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c6eaa56f94856a998ecd2f0befef3a38c5529da886266cd15150cf4e9758168f
4
- data.tar.gz: f9eb26d8c758153505d95d450e57c3fa0dfbfcdd9018d89bb6bcee3b656cebff
3
+ metadata.gz: 9d2a4756bdc712df308bb715f9076bac952fbf64dd8d8b2900d9c424b30026b7
4
+ data.tar.gz: 5c3b12638b3eb65936f32a84e50f222113b2c7c4c0e6f69bbbd9c594c99bd6eb
5
5
  SHA512:
6
- metadata.gz: 5c77c61810a9d855bc469ac4672d9917f0bbb345b5464235c0a06e9d901aa796c8cba67c12e181200ca3865ea2ce9629d8ae39065aec831b77c707fdc46720d4
7
- data.tar.gz: d270039fc1ea0340a515f554c4ff1f6437d0138c62ff09daafb5c1599df819d096ab04ffa23fe8862cac16b4bd6fcc71efea973e001fa97cfd1e5058e7444a82
6
+ metadata.gz: fd35db671d05e9f8c2559508a4ab7bf7bfd7d4582f6433fe4b93c2cd4f182c0692100f806cf3d72704ff4ec74a267ec2b319100df7704972c2ad46530ddc1978
7
+ data.tar.gz: 5216c72900a99522c7f49ac48166f85167bfecaf087c2d2e3891abfeaad44adbe378e1230cc87569d7e99ce9f1f4bd318de708eeff615218c23449c48f345dfd
data/History.txt CHANGED
@@ -2,6 +2,13 @@ TODO / Backlog
2
2
  * refactor various hardcoded constant pixel offsets in Graph class to use named constants or variables
3
3
  * Fix bug in Plot where min/max_x/y_value are not respected, TODO
4
4
 
5
+ === 2.2.3 /
6
+
7
+ === 2.2.2 / 2023-04-30
8
+ * fix line9 color typo in Line.rb [thanks, akostadinov #42]
9
+ * anchor right y labels [thanks, akostadinov #44]
10
+ * start line from first point, not 0 0 [thanks, akostadinov #43]
11
+
5
12
  === 2.2.1 / 2020-12-25
6
13
  * Remove inline styling for data point labels and popups [thanks marnen, PR #23]
7
14
  * fix #29 text background not aligned close to axis due to missing anchors
@@ -908,7 +908,10 @@ module SVG
908
908
  if show_y_labels
909
909
  # x = 0, y = 0 is top left right next to graph area
910
910
  y = y_offset - (label_height * count)
911
- x = -label_width/2.0 + y_label_font_size/2.0
911
+ # instead of calculating the middle anchor position, simply use
912
+ # static offset and anchor end to right-align the labels. See line :936 below.
913
+ #x = -label_width/2.0 + y_label_font_size/2.0
914
+ x = 3
912
915
 
913
916
  if stagger_y_labels and count % 2 == 1
914
917
  x -= stagger
@@ -929,7 +932,8 @@ module SVG
929
932
  end
930
933
  text.text = textStr
931
934
  # note text-anchor is at bottom of textfield
932
- text.attributes["style"] = "text-anchor: middle"
935
+ #text.attributes["style"] = "text-anchor: middle"
936
+ text.attributes["style"] = "text-anchor: end"
933
937
  degrees = rotate_y_labels
934
938
  text.attributes["transform"] = "translate( -#{font_size} 0 ) " +
935
939
  "rotate( #{degrees} #{x} #{y} ) "
@@ -42,7 +42,7 @@ module SVG
42
42
  #
43
43
  # = Examples
44
44
  #
45
- # http://www.germane-software/repositories/public/SVG/test/single.rb
45
+ # https://github.com/lumean/svg-graph2/blob/master/examples/line.rb
46
46
  #
47
47
  # = Notes
48
48
  # Only number of fileds datapoints will be drawn, additional data values
@@ -238,8 +238,9 @@ module SVG
238
238
  })
239
239
  end
240
240
 
241
+ matcher = /^(\S+ \S+) (.*)/.match lpath
241
242
  @graph.add_element("path", {
242
- "d" => "M0 #@graph_height L" + lpath,
243
+ "d" => "M#{matcher[1]} L#{matcher[2]}",
243
244
  "class" => "line#{line}"
244
245
  })
245
246
 
@@ -319,7 +320,7 @@ module SVG
319
320
  }
320
321
  .line9{
321
322
  fill: none;
322
- stroke: #ccc6666;
323
+ stroke: #cc6666;
323
324
  stroke-width: 1px;
324
325
  }
325
326
  .line10{
data/lib/SVG/Graph/Pie.rb CHANGED
@@ -36,7 +36,7 @@ module SVG
36
36
  #
37
37
  # = Examples
38
38
  #
39
- # http://www.germane-software/repositories/public/SVG/test/single.rb
39
+ # https://github.com/lumean/svg-graph2/blob/master/examples/pie.rb
40
40
  #
41
41
  # == See also
42
42
  #
@@ -55,7 +55,7 @@ module SVG
55
55
  #
56
56
  # = Examples
57
57
  #
58
- # http://www.germane-software/repositories/public/SVG/test/plot.rb
58
+ # https://github.com/lumean/svg-graph2/blob/master/examples/plot.rb
59
59
  #
60
60
  # = Notes
61
61
  #
@@ -180,6 +180,9 @@ module SVG
180
180
  "The data provided contained an odd set of "+
181
181
  "data points" unless conf[:data].length % 2 == 0
182
182
 
183
+ # clear the min/max x/y range caches
184
+ clear_cache
185
+
183
186
  # remove nil values
184
187
  conf[:data] = conf[:data].compact
185
188
 
@@ -223,24 +226,37 @@ module SVG
223
226
  X = 0
224
227
  Y = 1
225
228
 
229
+ # procedure to clear all the cached variables used in working out the
230
+ # max and min ranges for the chart
231
+ def clear_cache
232
+ @max_x_cache = @min_x_cache = @max_y_cache = @min_y_cache = nil
233
+ end
234
+
226
235
  def max_x_range
236
+ return @max_x_cache unless @max_x_cache.nil?
237
+
227
238
  # needs to be computed fresh when called, to cover the use-case:
228
239
  # add_data -> burn -> add_data -> burn
229
240
  # when values would be cached, the graph is not updated for second burning
230
241
  max_value = @data.collect{|x| x[:data][X][-1] }.max
231
242
  max_value = max_value > max_x_value ? max_value : max_x_value if max_x_value
232
- return max_value
243
+ @max_x_cache = max_value
244
+ @max_x_cache
233
245
  end
234
246
 
235
247
  def min_x_range
248
+ return @min_x_cache unless @min_x_cache.nil?
249
+
236
250
  # needs to be computed fresh when called, to cover the use-case:
237
251
  # add_data -> burn -> add_data -> burn
238
252
  # when values would be cached, the graph is not updated for second burning
239
253
  min_value = @data.collect{|x| x[:data][X][0] }.min
240
254
  min_value = min_value < min_x_value ? min_value : min_x_value if min_x_value
241
- return min_value
255
+ @min_x_cache = min_value
256
+ @min_x_cache
242
257
  end
243
258
 
259
+ # calculate the min and max x value as well as the scale division used for the x-axis
244
260
  def x_label_range
245
261
  max_value = max_x_range
246
262
  min_value = min_x_range
@@ -253,6 +269,7 @@ module SVG
253
269
  end
254
270
  scale_range = max_value - min_value
255
271
 
272
+ # either use the given step size or by default do 9 divisions.
256
273
  scale_division = scale_x_divisions || (scale_range / 9.0)
257
274
  @x_offset = 0
258
275
 
@@ -265,10 +282,13 @@ module SVG
265
282
  [min_value, max_value, scale_division]
266
283
  end
267
284
 
285
+ # get array of values for the x axis divisions, assuming left-most value starts
286
+ # exactly where the graph starts.
268
287
  def get_x_values
269
288
  min_value, max_value, @x_scale_division = x_label_range
289
+ x_times = ((max_value-min_value)/@x_scale_division).round + 1
270
290
  rv = []
271
- min_value.step( max_value + @x_scale_division , @x_scale_division ) {|v| rv << v}
291
+ x_times.times{|v| rv << (min_value + (v * @x_scale_division))}
272
292
  return rv
273
293
  end
274
294
  alias :get_x_labels :get_x_values
@@ -281,18 +301,24 @@ module SVG
281
301
  end
282
302
 
283
303
  def max_y_range
304
+ return @max_y_cache unless @max_y_cache.nil?
305
+
284
306
  max_value = @data.collect{|x| x[:data][Y].max }.max
285
307
  max_value = max_value > max_y_value ? max_value : max_y_value if max_y_value
286
- return max_value
308
+ @max_y_cache = max_value
309
+ @max_y_cache
287
310
  end
288
311
 
289
312
  def min_y_range
313
+ return @min_y_cache unless @min_y_cache.nil?
314
+
290
315
  # needs to be computed fresh when called, to cover the use-case:
291
316
  # add_data -> burn -> add_data -> burn
292
317
  # when values would be cached, the graph is not updated for second burning
293
318
  min_value = @data.collect{|x| x[:data][Y].min }.min
294
319
  min_value = min_value < min_y_value ? min_value : min_y_value if min_y_value
295
- return min_value
320
+ @min_y_cache = min_value
321
+ @min_y_cache
296
322
  end
297
323
 
298
324
  def y_label_range
@@ -345,6 +371,7 @@ module SVG
345
371
  @graph_height.to_f / (values.length - 1)
346
372
  end
347
373
 
374
+ # calculates the x,y coordinates of a datapoint in the plot area
348
375
  def calc_coords(x, y)
349
376
  coords = {:x => 0, :y => 0}
350
377
  # scale the coordinates, use float division / multiplication
@@ -47,7 +47,7 @@ module SVG
47
47
  #
48
48
  # = Examples
49
49
  #
50
- # http://www.germane-software/repositories/public/SVG/test/schedule.rb
50
+ # https://github.com/lumean/svg-graph2/blob/master/examples/schedule.rb
51
51
  #
52
52
  # = Notes
53
53
  #
@@ -60,7 +60,7 @@ module SVG
60
60
  #
61
61
  # = Examples
62
62
  #
63
- # http://www.germane-software/repositories/public/SVG/test/timeseries.rb
63
+ # https://github.com/lumean/svg-graph2/blob/master/examples/timeseries.rb
64
64
  #
65
65
  # = Notes
66
66
  #
@@ -249,12 +249,12 @@ module SVG
249
249
  step = amount
250
250
  end
251
251
  # only do this if division_units is not year or month. Those are done already above in the cases.
252
- min.step( max, step ) {|v| rv << v} if step
252
+ min.step( max + (step/10), step ) {|v| rv << v} if step
253
253
  @x_scale_division = step if step
254
254
  return rv
255
255
  end
256
256
  end
257
- min.step( max , @x_scale_division ) {|v| rv << v}
257
+ min.step( max + (@x_scale_division/10), @x_scale_division ) {|v| rv << v}
258
258
  return rv
259
259
  end # get_x_values
260
260
 
data/lib/svggraph.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module SVG
2
2
  module Graph
3
- VERSION = '2.2.1'
3
+ VERSION = '2.2.2'
4
4
 
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: svg-graph
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Russell
@@ -9,10 +9,10 @@ authors:
9
9
  - Liehann Loots
10
10
  - Piergiuliano Bossi
11
11
  - Manuel Widmer
12
- autorequire:
12
+ autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2020-12-26 00:00:00.000000000 Z
15
+ date: 2023-04-30 00:00:00.000000000 Z
16
16
  dependencies: []
17
17
  description: "Gem version of SVG:::Graph. SVG:::Graph is a pure Ruby library for generating
18
18
  charts,\nwhich are a type of graph where the values of one axis are not scalar.
@@ -57,7 +57,7 @@ homepage: https://github.com/lumean/svg-graph2
57
57
  licenses:
58
58
  - GPL-2.0
59
59
  metadata: {}
60
- post_install_message:
60
+ post_install_message:
61
61
  rdoc_options: []
62
62
  require_paths:
63
63
  - lib
@@ -72,8 +72,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
72
  - !ruby/object:Gem::Version
73
73
  version: '0'
74
74
  requirements: []
75
- rubygems_version: 3.1.4
76
- signing_key:
75
+ rubygems_version: 3.2.3
76
+ signing_key:
77
77
  specification_version: 4
78
78
  summary: SVG:::Graph is a pure Ruby library for generating charts, which are a type
79
79
  of graph where the values of one axis are not scalar.