Class: Spoom::Coverage::D3::Timeline::Runtimes

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) ⇒ Runtimes

Returns a new instance of Runtimes.



286
287
288
289
290
291
292
293
294
295
# File 'lib/spoom/coverage/d3/timeline.rb', line 286

def initialize(id, snapshots)
  data = snapshots.map do |snapshot|
    {
      timestamp: snapshot.commit_timestamp,
      commit: snapshot.commit_sha,
      runtime: snapshot.duration.to_f / 1000.0 / 1000.0,
    }
  end
  super(id, data, [])
end

Instance Method Details

#plotObject



311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
# File 'lib/spoom/coverage/d3/timeline.rb', line 311

def plot
  <<~JS
    #{x_scale}
    #{y_scale(
      min: "0",
      max: "d3.max(data_#{id}, (d) => d.runtime)",
      ticks: "ticks(10)",
    )}
    #{area(y: "d.runtime")}
    #{line(y: "d.runtime")}
    #{points(y: "d.runtime")}
    #{x_ticks}
    #{y_ticks(ticks: "ticks(5)", format: 'd.toFixed(2) + "s"', padding: 40)}
      .call(g => g.selectAll(".tick:first-of-type text").remove())
  JS
end

#tooltipObject



298
299
300
301
302
303
304
305
306
307
308
# File 'lib/spoom/coverage/d3/timeline.rb', line 298

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>"
          + "<b>" + d.runtime + "</b>s<br><br>"
          + "(sorbet user + system time)")
    }
  JS
end