Class: Spoom::Coverage::D3::Timeline::Versions

Inherits:
Spoom::Coverage::D3::Timeline show all
Extended by:
T::Sig
Defined in:
lib/spoom/coverage/d3/timeline.rb

Instance Attribute Summary

Attributes inherited from Base

#id

Instance Method Summary collapse

Methods inherited from Spoom::Coverage::D3::Timeline

#area, header_script, header_style, #line, #points, #script, #x_scale, #x_ticks, #y_scale, #y_ticks

Methods inherited from Base

header_script, header_style, #html, #script

Constructor Details

#initialize(id, snapshots) ⇒ Versions

Returns a new instance of Versions.


232
233
234
235
236
237
238
239
240
241
242
# File 'lib/spoom/coverage/d3/timeline.rb', line 232

def initialize(id, snapshots)
  data = snapshots.map do |snapshot|
    {
      timestamp: snapshot.commit_timestamp,
      commit: snapshot.commit_sha,
      static: snapshot.version_static,
      runtime: snapshot.version_runtime,
    }
  end
  super(id, data, [])
end

Instance Method Details

#plotObject


259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/spoom/coverage/d3/timeline.rb', line 259

def plot
  <<~JS
    #{x_scale}
    #{y_scale(
      min: "d3.min([d3.min(data_#{id}, (d) => parseVersion(d.static)),
                    d3.min(data_#{id}, (d) => parseVersion(d.runtime))]) - 0.01",
      max: "d3.max([d3.max(data_#{id}, (d) => parseVersion(d.static)),
                    d3.max(data_#{id}, (d) => parseVersion(d.runtime))]) + 0.01",
      ticks: 'ticks(8)'
    )}
    #{line(y: 'parseVersion(d.runtime)', color: '#e83e8c', curve: 'curveStepAfter')}
    #{line(y: 'parseVersion(d.static)', color: '#007bff', curve: 'curveStepAfter')}
    #{points(y: 'parseVersion(d.static)')}
    #{x_ticks}
    #{y_ticks(ticks: 'ticks(4)', format: "'v0.' + d.toFixed(2)", padding: 50)}
  JS
end

#tooltipObject


245
246
247
248
249
250
251
252
253
254
255
256
# File 'lib/spoom/coverage/d3/timeline.rb', line 245

def tooltip
  <<~JS
    function tooltip_#{id}(d) {
      moveTooltip(d)
        .html("commit <b>" + d.commit + "</b><br>"
          + d3.timeFormat("%y/%m/%d")(parseDate(d.timestamp)) + "<br><br>"
          + "static: v<b>" + d.static + "</b><br>"
          + "runtime: v<b>" + d.runtime + "</b><br><br>"
          + "versions from<br>Gemfile.lock")
    }
  JS
end