Class: Spoom::Coverage::D3::Timeline
- Extended by:
- T::Helpers
- Defined in:
- lib/spoom/coverage/d3/timeline.rb
Defined Under Namespace
Classes: Calls, RBIs, Runtimes, Sigils, Sigs, Stacked, Versions
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
-
.header_script ⇒ Object
: -> String.
-
.header_style ⇒ Object
: -> String.
Instance Method Summary collapse
-
#area(y:, color: "#ccc", curve: "curveCatmullRom.alpha(1)") ⇒ Object
: (y: String, ?color: String, ?curve: String) -> String.
-
#initialize(id, data, keys) ⇒ Timeline
constructor
: (String id, untyped data, Array keys) -> void.
-
#line(y:, color: "#ccc", curve: "curveCatmullRom.alpha(1)") ⇒ Object
: (y: String, ?color: String, ?curve: String) -> String.
- #plot ⇒ Object
-
#points(y:) ⇒ Object
: (y: String) -> String.
-
#script ⇒ Object
: -> String.
-
#x_scale ⇒ Object
: -> String.
-
#x_ticks ⇒ Object
: -> String.
-
#y_scale(min:, max:, ticks:) ⇒ Object
: (min: String, max: String, ticks: String) -> String.
-
#y_ticks(ticks:, format:, padding:) ⇒ Object
: (ticks: String, format: String, padding: Integer) -> String.
Methods inherited from Base
Constructor Details
Class Method Details
.header_script ⇒ Object
: -> String
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/spoom/coverage/d3/timeline.rb', line 76 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 |
.header_style ⇒ Object
: -> String
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/spoom/coverage/d3/timeline.rb', line 22 def header_style <<~CSS .domain { stroke: transparent; } .grid line { stroke: #ccc; } .axis text { font: 12px Arial, sans-serif; fill: #333; text-anchor: right; pointer-events: none; } .area { fill-opacity: 0.5; } .line { stroke-width: 2; fill: transparent; } .dot { r: 2; fill: #888; } .inverted .grid line { stroke: #777; } .inverted .area { fill-opacity: 0.9; } .inverted .axis text { fill: #fff; } .inverted .axis line { stroke: #fff; } .inverted .dot { fill: #fff; } CSS end |
Instance Method Details
#area(y:, color: "#ccc", curve: "curveCatmullRom.alpha(1)") ⇒ Object
: (y: String, ?color: String, ?curve: String) -> String
185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/spoom/coverage/d3/timeline.rb', line 185 def area(y:, color: "#ccc", curve: "curveCatmullRom.alpha(1)") <<~HTML svg_#{id}.append("path") .datum(data_#{id}.filter((d) => #{y})) .attr("class", "area") .attr("d", d3.area() .defined((d) => #{y}) .x((d) => xScale_#{id}(parseDate(d.timestamp))) .y0(yScale_#{id}(0)) .y1((d) => yScale_#{id}(#{y})) .curve(d3.#{curve})) .attr("fill", "#{color}") HTML end |
#line(y:, color: "#ccc", curve: "curveCatmullRom.alpha(1)") ⇒ Object
: (y: String, ?color: String, ?curve: String) -> String
201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/spoom/coverage/d3/timeline.rb', line 201 def line(y:, color: "#ccc", curve: "curveCatmullRom.alpha(1)") <<~HTML svg_#{id}.append("path") .datum(data_#{id}.filter((d) => #{y})) .attr("class", "line") .attr("d", d3.line() .x((d) => xScale_#{id}(parseDate(d.timestamp))) .y((d) => yScale_#{id}(#{y})) .curve(d3.#{curve})) .attr("stroke", "#{color}") HTML end |
#plot ⇒ Object
124 |
# File 'lib/spoom/coverage/d3/timeline.rb', line 124 def plot; end |
#points(y:) ⇒ Object
: (y: String) -> String
215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/spoom/coverage/d3/timeline.rb', line 215 def points(y:) <<~HTML svg_#{id}.selectAll("circle") .data(data_#{id}) .enter() .append("circle") .attr("class", "dot") .attr("cx", (d) => xScale_#{id}(parseDate(d.timestamp))) .attr("cy", (d, i) => yScale_#{id}(#{y})) .on("mouseover", (d) => tooltip.style("opacity", 1)) .on("mousemove", tooltip_#{id}) .on("mouseleave", (d) => tooltip.style("opacity", 0)); HTML end |
#script ⇒ Object
: -> String
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/spoom/coverage/d3/timeline.rb', line 99 def script <<~HTML #{tooltip} var data_#{id} = #{@data.to_json}; function draw_#{id}() { var width_#{id} = document.getElementById("#{id}").clientWidth; var height_#{id} = 200; d3.select("##{id}").selectAll("*").remove() var svg_#{id} = d3.select("##{id}") .attr("width", width_#{id}) .attr("height", height_#{id}) #{plot} } draw_#{id}(); window.addEventListener("resize", draw_#{id}); HTML end |
#x_scale ⇒ Object
: -> String
127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/spoom/coverage/d3/timeline.rb', line 127 def x_scale <<~HTML var xScale_#{id} = d3.scaleTime() .range([0, width_#{id}]) .domain(d3.extent(data_#{id}, (d) => parseDate(d.timestamp))); svg_#{id}.append("g") .attr("class", "grid") .attr("transform", "translate(0," + height_#{id} + ")") .call(d3.axisBottom(xScale_#{id}) .tickFormat("") .tickSize(-height_#{id})) HTML end |
#x_ticks ⇒ Object
: -> String
143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/spoom/coverage/d3/timeline.rb', line 143 def x_ticks <<~HTML svg_#{id}.append("g") .attr("class", "axis x") .attr("transform", "translate(0," + height_#{id} + ")") .call(d3.axisBottom(xScale_#{id}) .tickFormat(d3.timeFormat("%y/%m/%d")) .tickPadding(-15) .tickSize(-3)); HTML end |
#y_scale(min:, max:, ticks:) ⇒ Object
: (min: String, max: String, ticks: String) -> String
156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/spoom/coverage/d3/timeline.rb', line 156 def y_scale(min:, max:, ticks:) <<~HTML var yScale_#{id} = d3.scaleLinear() .range([height_#{id}, 0]) .domain([#{min}, #{max}]); svg_#{id}.append("g") .attr("class", "grid") .call(d3.axisLeft(yScale_#{id}) .#{ticks} .tickFormat("") .tickSize(-width_#{id})) HTML end |
#y_ticks(ticks:, format:, padding:) ⇒ Object
: (ticks: String, format: String, padding: Integer) -> String
172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/spoom/coverage/d3/timeline.rb', line 172 def y_ticks(ticks:, format:, padding:) <<~HTML svg_#{id}.append("g") .attr("class", "axis y") .call(d3.axisLeft(yScale_#{id}) .#{ticks} .tickSize(-3) .tickFormat((d) => #{format}) .tickPadding(-#{padding})) HTML end |