plasticine 1.2.3 → 1.2.4

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: ec28eb39afbe68a7d8736bb19f20e372e005d0bc22134d07996e3ec45641440e
4
- data.tar.gz: f143b3e121fb0986a4396103a1be0b39ee3d30df173f5c531b11a7e1de92cea3
3
+ metadata.gz: 622f4435b4c85728ba586bd87bb722c134c440d5afe78d628860745ccad9d8dd
4
+ data.tar.gz: 73e6646931aabe61bf7bd2f7c6ea0a5d759b5d50a7ec987976fcc1dc31a2c4bc
5
5
  SHA512:
6
- metadata.gz: f4117b65a69e027ae9950a7afe3430e8de657584f504534d36770e936e9e471359600fcf860597c384956d52db76d79c23ff394116cc4feeb5ade5850340acb2
7
- data.tar.gz: bad51faaaa94cd35e34c2c0cd50d239f613e1e4548c42313d6c02037dab4433e0173a8b5d5245f64e97082a3330498d79a49dc9e686f3556d5670f6accfdccd5
6
+ metadata.gz: 2b7672a93c63e6342253f9d4f6ae7837c95b42e4783367470aed43c4195588fb19348a89333e6cb18823f7d8480515a20d565f597b3a98e38a1c423199f771c0
7
+ data.tar.gz: 83a0d23568412d127554b0b74e395d3ae56b80ddbacdc299df78e039411c4aded93035f4e1159fc24ef702cc18cad0fa4868fb6281ec55165646c90a982c0f5a
@@ -112,13 +112,7 @@ class @PlasticineColumn
112
112
  @xAxis = d3.axisBottom(@xScale)
113
113
  @xAxis.tickSize -@holder.height()
114
114
 
115
- switch @xAxisFormat
116
- when 'date' then @xAxis.tickFormat(d3.timeFormat('%b'))
117
- when 'day' then @xAxis.tickFormat(d3.timeFormat('%e-%m'))
118
- when 'quarter' then @xAxis.tickFormat (d) => PlasticineHelpers.toQuarter(d, @quarterStartMonth)
119
- when 'year' then @xAxis.tickFormat (d) => PlasticineHelpers.toYear(d, @quarterStartMonth)
120
- when 'money' then @xAxis.tickFormat (d) => PlasticineHelpers.toPrice(d)
121
- when 'numeric' then @xAxis.tickFormat (d) => PlasticineHelpers.toNumeric(d)
115
+ PlasticineHelpers.setAxisFormat @xAxis, @xAxisFormat
122
116
 
123
117
 
124
118
  setXScaleRange: () ->
@@ -135,11 +129,7 @@ class @PlasticineColumn
135
129
  @yAxis.tickSize -@holderWidth()
136
130
  @yAxis.ticks @yAxisTickCount
137
131
 
138
- switch @yAxisFormat
139
- when 'date' then @yAxis.tickFormat(d3.timeFormat('%b'))
140
- when 'day' then @yAxis.tickFormat(d3.timeFormat('%e-%m'))
141
- when 'money' then @yAxis.tickFormat (d) => PlasticineHelpers.toPrice(d)
142
- when 'numeric' then @yAxis.tickFormat (d) => PlasticineHelpers.toNumeric(d)
132
+ PlasticineHelpers.setAxisFormat @yAxis, @yAxisFormat
143
133
 
144
134
 
145
135
  showTooltip: (bar, data) ->
@@ -3,8 +3,7 @@
3
3
 
4
4
  PlasticineHelpers.parseValue = (value, format) ->
5
5
  switch format
6
- when 'date' then new Date(value)
7
- when 'day' then new Date(value)
6
+ when 'date', 'day', 'daytext' then new Date(value)
8
7
  else value
9
8
 
10
9
  PlasticineHelpers.setLocale = () ->
@@ -34,6 +33,20 @@ PlasticineHelpers.formatNumericString = (str) ->
34
33
  else str
35
34
 
36
35
 
36
+ PlasticineHelpers.setAxisFormat = (axis, format) ->
37
+ switch format
38
+ when 'date' then axis.tickFormat(d3.timeFormat('%b'))
39
+ when 'day' then axis.tickFormat(d3.timeFormat('%e-%m'))
40
+ when 'daytext' then axis.tickFormat(d3.timeFormat('%e %b'))
41
+ when 'hours' then axis.tickFormat (d) => @toHours(d)
42
+ when 'money' then axis.tickFormat (d) => @toPrice(d)
43
+ when 'numeric' then axis.tickFormat (d) => @toNumeric(d)
44
+ when 'quarter' then axis.tickFormat (d) => @toQuarter(d, @quarterStartMonth)
45
+ when 'year' then axis.tickFormat (d) => @toYear(d, @quarterStartMonth)
46
+
47
+
48
+ PlasticineHelpers.toHours = (value) -> @formatNumericString(value) + 'h'
49
+
37
50
  PlasticineHelpers.toNumeric = (value) -> @formatNumericString(value)
38
51
 
39
52
  PlasticineHelpers.toPrice = (amount) ->
@@ -43,7 +56,7 @@ PlasticineHelpers.toPrice = (amount) ->
43
56
  price = String(amount)[0..-3]
44
57
  price = "0" if price is ""
45
58
 
46
- price = @formatNumericString(value)
59
+ price = @formatNumericString(amount)
47
60
 
48
61
  # TODO : Show decimals
49
62
  # price += ',' + String(amount).slice(-2)
@@ -1,14 +1,13 @@
1
1
  class @PlasticineLine
2
2
  constructor: (@holder) ->
3
3
  @holder = $('.plasticine-line')
4
+ @holder.on('resize', (e) => @resizeX())
4
5
 
5
6
  PlasticineHelpers.setLocale()
6
- #@drawTooltip()
7
7
 
8
8
  @xScale = d3.scaleBand()
9
9
  @setXScaleRange()
10
-
11
- @yScale = d3.scaleLinear().range([@holder.height(),50])
10
+ @yScale = d3.scaleLinear().range([@holder.height(), @holder.data('lines-top-padding')])
12
11
 
13
12
  @setXAxis()
14
13
  @setYAxis()
@@ -52,13 +51,13 @@ class @PlasticineLine
52
51
  stack = d3.stack().keys(stackedKeys)
53
52
  series = stack(stackedDataset);
54
53
 
55
- @chartPath = d3.area().curve(d3.curveCardinal)
54
+ @chartPath = d3.area().curve(d3.curveMonotoneX)
56
55
  .x( (d,i) => @xScale(stackedDataset[i].x) )
57
56
  .y0( (d) => @yScale(d[0]) )
58
57
  .y1( (d) => @yScale(d[1]) )
59
58
  else
60
59
  series = data['lines']
61
- @chartPath = d3.line().curve(d3.curveCardinal)
60
+ @chartPath = d3.line().curve(d3.curveMonotoneX)
62
61
  .x( (d) => @xScale(d.x))
63
62
  .y( (d) => @yScale(d.y))
64
63
 
@@ -71,6 +70,8 @@ class @PlasticineLine
71
70
 
72
71
 
73
72
  refreshLines: () ->
73
+ self = this
74
+
74
75
  $('g.element').remove()
75
76
 
76
77
  element = @lines.enter().append('g').attr('class', "element")
@@ -84,6 +85,7 @@ class @PlasticineLine
84
85
  @legend.append('li').html('<span></span>' + line.label)
85
86
 
86
87
 
88
+
87
89
  drawXAxis: () ->
88
90
  height = @holder.height()
89
91
  @svg.append('g').attr('class', 'x axis')
@@ -126,13 +128,11 @@ class @PlasticineLine
126
128
  @xAxis = d3.axisBottom(@xScale)
127
129
  @xAxis.tickSize -@holder.height()
128
130
 
129
- switch @xAxisFormat
130
- when 'date' then @xAxis.tickFormat(d3.timeFormat('%b'))
131
- when 'day' then @xAxis.tickFormat(d3.timeFormat('%e-%m'))
132
- when 'quarter' then @xAxis.tickFormat (d) => PlasticineHelpers.toQuarter(d, @quarterStartMonth)
133
- when 'year' then @xAxis.tickFormat (d) => PlasticineHelpers.toYear(d, @quarterStartMonth)
134
- when 'money' then @xAxis.tickFormat (d) => PlasticineHelpers.toPrice(d)
135
- when 'numeric' then @xAxis.tickFormat (d) => PlasticineHelpers.toNumeric(d)
131
+ setXAxis: () ->
132
+ @xAxis = d3.axisBottom(@xScale)
133
+ @xAxis.tickSize -@holder.height()
134
+
135
+ PlasticineHelpers.setAxisFormat @xAxis, @xAxisFormat
136
136
 
137
137
 
138
138
  setXScaleRange: () ->
@@ -149,8 +149,4 @@ class @PlasticineLine
149
149
  @yAxis.tickSize -@holderWidth()
150
150
  @yAxis.ticks @yAxisTickCount
151
151
 
152
- switch @yAxisFormat
153
- when 'date' then @yAxis.tickFormat(d3.timeFormat('%b'))
154
- when 'day' then @yAxis.tickFormat(d3.timeFormat('%e-%m'))
155
- when 'money' then @yAxis.tickFormat (d) => PlasticineHelpers.toPrice(d)
156
- when 'numeric' then @yAxis.tickFormat (d) => PlasticineHelpers.toNumeric(d)
152
+ PlasticineHelpers.setAxisFormat @yAxis, @yAxisFormat
@@ -4,7 +4,7 @@ class Plasticine::Builder::Line < Plasticine::Builder::Base
4
4
  def initialize(id, options={})
5
5
  super
6
6
 
7
- @visual.merge! lines: [], nature: 'line', axis_x_format: :string, axis_y_format: :number, axis_y_tick_count: 10, chart_layout: 'line', order: nil, quarter_start_month: 1
7
+ @visual.merge! lines: [], nature: 'line', axis_x_format: :string, axis_y_format: :number, axis_y_tick_count: 10, chart_layout: 'line', max_y_ratio: 1, order: nil, quarter_start_month: 1
8
8
  @lines = {}
9
9
  end
10
10
 
@@ -25,6 +25,10 @@ class Plasticine::Builder::Line < Plasticine::Builder::Base
25
25
  @visual[:chart_layout] = clayout
26
26
  end
27
27
 
28
+ def max_y_ratio=(max_y_ratio)
29
+ @visual[:max_y_ratio] = max_y_ratio
30
+ end
31
+
28
32
  def quarter_start_month=(month)
29
33
  @visual[:quarter_start_month] = month
30
34
  end
@@ -69,8 +73,12 @@ class Plasticine::Builder::Line < Plasticine::Builder::Base
69
73
  end
70
74
  end
71
75
 
72
- @visual[:max_y_stack] = stacks.max_by{|k,v| v}[1] # Return the highest stacked value for a specific X
73
- @visual[:max_y] = max_y
76
+ if max_y == 0
77
+ @visual[:max_y_stack] = 0
78
+ @visual[:max_y] = 0
79
+ else
80
+ @visual[:max_y_stack] = stacks.max_by{|k,v| v}[1] # Return the highest stacked value for a specific X
81
+ @visual[:max_y] = max_y * @visual[:max_y_ratio]
82
+ end
74
83
  end
75
-
76
84
  end
@@ -41,11 +41,12 @@ module Plasticine::Helpers
41
41
  end
42
42
 
43
43
  def line(options={})
44
- options.reverse_merge! lines_left_padding: 20, lines_right_padding: 20, lines_margin: 1, y_spacing_ratio: 1.10
44
+ options.reverse_merge! lines_left_padding: 20, lines_right_padding: 20, lines_top_padding: 50, lines_margin: 1, y_spacing_ratio: 1.10
45
45
 
46
46
  options[:data] = {
47
47
  lines_left_padding: options.delete(:lines_left_padding),
48
48
  lines_right_padding: options.delete(:lines_right_padding),
49
+ lines_top_padding: options.delete(:lines_top_padding),
49
50
  lines_margin: options.delete(:lines_margin),
50
51
  y_spacing_ratio: options.delete(:y_spacing_ratio)
51
52
  }
@@ -3,7 +3,7 @@ Gem::Specification.new do |gem|
3
3
  gem.description = "Data visualization toolkit for Rails App using D3.js"
4
4
  gem.summary = "Data visualization toolkit for Rails App using D3.js"
5
5
  gem.homepage = "https://github.com/alchimikweb/plasticine"
6
- gem.version = "1.2.3"
6
+ gem.version = "1.2.4"
7
7
  gem.licenses = ["MIT"]
8
8
 
9
9
  gem.authors = ["Sebastien Rosa"]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plasticine
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastien Rosa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-26 00:00:00.000000000 Z
11
+ date: 2019-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails