lib/spoom/coverage/d3/timeline.rb in spoom-1.1.11 vs lib/spoom/coverage/d3/timeline.rb in spoom-1.1.12

- old
+ new

@@ -16,83 +16,87 @@ def initialize(id, data, keys) super(id, data) @keys = keys end - sig { returns(String) } - def self.header_style - <<~CSS - .domain { - stroke: transparent; - } + class << self + extend T::Sig - .grid line { - stroke: #ccc; - } + sig { returns(String) } + def header_style + <<~CSS + .domain { + stroke: transparent; + } - .axis text { - font: 12px Arial, sans-serif; - fill: #333; - text-anchor: right; - pointer-events: none; - } + .grid line { + stroke: #ccc; + } - .area { - fill-opacity: 0.5; - } + .axis text { + font: 12px Arial, sans-serif; + fill: #333; + text-anchor: right; + pointer-events: none; + } - .line { - stroke-width: 2; - fill: transparent; - } + .area { + fill-opacity: 0.5; + } - .dot { - r: 2; - fill: #888; - } + .line { + stroke-width: 2; + fill: transparent; + } - .inverted .grid line { - stroke: #777; - } + .dot { + r: 2; + fill: #888; + } - .inverted .area { - fill-opacity: 0.9; - } + .inverted .grid line { + stroke: #777; + } - .inverted .axis text { - fill: #fff; - } + .inverted .area { + fill-opacity: 0.9; + } - .inverted .axis line { - stroke: #fff; - } + .inverted .axis text { + fill: #fff; + } - .inverted .dot { - fill: #fff; - } - CSS - end + .inverted .axis line { + stroke: #fff; + } - sig { returns(String) } - def self.header_script - <<~JS - var parseVersion = function(version) { - if (!version) { - return null; + .inverted .dot { + fill: #fff; } - return parseFloat(version.replaceAll("0.", "")); - } + CSS + end - function tooltipTimeline(d, kind) { - moveTooltip(d) - .html("commit <b>" + d.data.commit + "</b><br>" - + d3.timeFormat("%y/%m/%d")(parseDate(d.data.timestamp)) + "<br><br>" - + "<b>typed: " + d.key + "</b><br><br>" - + "<b>" + (d.data.values[d.key] ? d.data.values[d.key] : 0) + "</b> " + kind +"<br>" - + "<b>" + toPercent(d.data.values[d.key] ? d.data.values[d.key] : 0, d.data.total) + "%") - } - JS + sig { returns(String) } + def header_script + <<~JS + var parseVersion = function(version) { + if (!version) { + return null; + } + return parseFloat(version.replaceAll("0.", "")); + } + + function tooltipTimeline(d, kind) { + moveTooltip(d) + .html("commit <b>" + d.data.commit + "</b><br>" + + d3.timeFormat("%y/%m/%d")(parseDate(d.data.timestamp)) + "<br><br>" + + "<b>typed: " + d.key + "</b><br><br>" + + "<b>" + (d.data.values[d.key] ? d.data.values[d.key] : 0) + "</b> " + kind +"<br>" + + "<b>" + toPercent(d.data.values[d.key] ? d.data.values[d.key] : 0, d.data.total) + "%") + } + JS + end end sig { override.returns(String) } def script <<~HTML @@ -262,17 +266,17 @@ #{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)' + 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)')} + #{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)} + #{y_ticks(ticks: "ticks(4)", format: "'v0.' + d.toFixed(2)", padding: 50)} JS end end class Runtimes < Timeline @@ -306,19 +310,19 @@ sig { override.returns(String) } def plot <<~JS #{x_scale} #{y_scale( - min: '0', + min: "0", max: "d3.max(data_#{id}, (d) => d.runtime)", - ticks: 'ticks(10)' + ticks: "ticks(10)" )} - #{area(y: 'd.runtime')} - #{line(y: 'd.runtime')} - #{points(y: 'd.runtime')} + #{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)} + #{y_ticks(ticks: "ticks(5)", format: 'd.toFixed(2) + "s"', padding: 40)} .call(g => g.selectAll(".tick:first-of-type text").remove()) JS end end @@ -371,19 +375,19 @@ sig { override.returns(String) } def plot <<~JS #{x_scale} - #{y_scale(min: '0', max: '100', ticks: 'tickValues([0, 25, 50, 75, 100])')} - #{line(y: 'd.data.timestamp')} + #{y_scale(min: "0", max: "100", ticks: "tickValues([0, 25, 50, 75, 100])")} + #{line(y: "d.data.timestamp")} #{x_ticks} - #{y_ticks(ticks: 'tickValues([25, 50, 75])', format: "d + '%'", padding: 30)} + #{y_ticks(ticks: "tickValues([25, 50, 75])", format: "d + '%'", padding: 30)} JS end sig { override.params(y: String, color: String, curve: String).returns(String) } - def line(y:, color: 'strictnessColor(d.key)', curve: 'curveCatmullRom.alpha(1)') + def line(y:, color: "strictnessColor(d.key)", curve: "curveCatmullRom.alpha(1)") <<~JS var area_#{id} = d3.area() .x((d) => xScale_#{id}(parseDate(#{y}))) .y0((d) => yScale_#{id}(d[0])) .y1((d) => yScale_#{id}(d[1])) @@ -444,11 +448,11 @@ class Calls < Stacked extend T::Sig sig { params(id: String, snapshots: T::Array[Snapshot]).void } def initialize(id, snapshots) - keys = ['false', 'true'] + keys = ["false", "true"] data = snapshots.map do |snapshot| { timestamp: snapshot.commit_timestamp, commit: snapshot.commit_sha, total: snapshot.calls_typed + snapshot.calls_untyped, @@ -471,11 +475,11 @@ class Sigs < Stacked extend T::Sig sig { params(id: String, snapshots: T::Array[Snapshot]).void } def initialize(id, snapshots) - keys = ['false', 'true'] + keys = ["false", "true"] data = snapshots.map do |snapshot| { timestamp: snapshot.commit_timestamp, commit: snapshot.commit_sha, total: snapshot.methods_with_sig + snapshot.methods_without_sig, @@ -498,11 +502,11 @@ class RBIs < Stacked extend T::Sig sig { params(id: String, snapshots: T::Array[Snapshot]).void } def initialize(id, snapshots) - keys = ['rbis', 'files'] + keys = ["rbis", "files"] data = snapshots.map do |snapshot| { timestamp: snapshot.commit_timestamp, commit: snapshot.commit_sha, total: snapshot.files, @@ -565,11 +569,11 @@ window.addEventListener("resize", draw_#{id}); JS end sig { override.params(y: String, color: String, curve: String).returns(String) } - def line(y:, color: 'strictnessColor(d.key)', curve: 'curveCatmullRom.alpha(1)') + def line(y:, color: "strictnessColor(d.key)", curve: "curveCatmullRom.alpha(1)") <<~JS var area_#{id} = d3.area() .x((d) => xScale_#{id}(parseDate(#{y}))) .y0((d) => yScale_#{id}(d[0])) .y1((d) => yScale_#{id}(d[1])) @@ -608,13 +612,13 @@ sig { override.returns(String) } def plot <<~JS #{x_scale} - #{y_scale(min: '0', max: "d3.max(data_#{id}, (d) => d.total + 10)", ticks: 'tickValues([0, 25, 50, 75, 100])')} - #{line(y: 'd.data.timestamp', color: "d.key == 'rbis' ? '#8673ff' : '#007bff'")} + #{y_scale(min: "0", max: "d3.max(data_#{id}, (d) => d.total + 10)", ticks: "tickValues([0, 25, 50, 75, 100])")} + #{line(y: "d.data.timestamp", color: "d.key == 'rbis' ? '#8673ff' : '#007bff'")} #{x_ticks} - #{y_ticks(ticks: 'tickValues([25, 50, 75])', format: 'd', padding: 20)} + #{y_ticks(ticks: "tickValues([25, 50, 75])", format: "d", padding: 20)} JS end end end end