Class: Spoom::Coverage::D3::Timeline
- Inherits:
-
Base
- Object
- Base
- Spoom::Coverage::D3::Timeline
show all
- Extended by:
- T::Helpers, T::Sig
- Defined in:
- lib/spoom/coverage/d3/timeline.rb
Defined Under Namespace
Classes: Calls, Runtimes, Sigils, Sigs, Stacked, Versions
Instance Attribute Summary
Attributes inherited from Base
#id
Class Method Summary
collapse
Instance Method Summary
collapse
-
#area(y:, color: "#ccc", curve: "curveCatmullRom.alpha(1)") ⇒ Object
-
#initialize(id, data, keys) ⇒ Timeline
constructor
A new instance of Timeline.
-
#line(y:, color: "#ccc", curve: "curveCatmullRom.alpha(1)") ⇒ Object
-
#plot ⇒ Object
-
#points(y:) ⇒ Object
-
#script ⇒ Object
-
#x_scale ⇒ Object
-
#x_ticks ⇒ Object
-
#y_scale(min:, max:, ticks:) ⇒ Object
-
#y_ticks(ticks:, format:, padding:) ⇒ Object
Methods inherited from Base
#html, #tooltip
Constructor Details
#initialize(id, data, keys) ⇒ Timeline
16
17
18
19
|
# File 'lib/spoom/coverage/d3/timeline.rb', line 16
def initialize(id, data, keys)
super(id, data)
@keys = keys
end
|
Class Method Details
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/spoom/coverage/d3/timeline.rb', line 54
def self.
" var parseVersion = function(version) {\n if (!version) {\n return null;\n }\n return parseFloat(version.replaceAll(\"0.\", \"\"));\n }\n\n function tooltipTimeline(d, kind) {\n moveTooltip(d)\n .html(\"commit <b>\" + d.data.commit + \"</b><br>\"\n + d3.timeFormat(\"%y/%m/%d\")(parseDate(d.data.timestamp)) + \"<br><br>\"\n + \"<b>typed: \" + d.key + \"</b><br><br>\"\n + \"<b>\" + (d.data.values[d.key] ? d.data.values[d.key] : 0) + \"</b> \" + kind +\"<br>\"\n + \"<b>\" + toPercent(d.data.values[d.key] ? d.data.values[d.key] : 0, d.data.total) + \"%\")\n }\n JS\nend\n"
|
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
|
# File 'lib/spoom/coverage/d3/timeline.rb', line 22
def self.
" .domain {\n stroke: transparent;\n }\n\n .grid line {\n stroke: #ccc;\n }\n\n .axis text {\n font: 12px Arial, sans-serif;\n fill: #333;\n text-anchor: right;\n pointer-events: none;\n }\n\n .inverted .grid line {\n stroke: #777;\n }\n\n .inverted .axis text {\n fill: #fff;\n }\n\n .inverted .axis line {\n stroke: #fff;\n }\n CSS\nend\n"
|
Instance Method Details
#area(y:, color: "#ccc", curve: "curveCatmullRom.alpha(1)") ⇒ Object
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
# File 'lib/spoom/coverage/d3/timeline.rb', line 161
def area(y:, color: "#ccc", curve: "curveCatmullRom.alpha(1)")
" svg_\#{id}.append(\"path\")\n .datum(data_\#{id}.filter((d) => \#{y}))\n .attr(\"class\", \"area\")\n .attr(\"d\", d3.area()\n .defined((d) => \#{y})\n .x((d) => xScale_\#{id}(parseDate(d.timestamp)))\n .y0(yScale_\#{id}(0))\n .y1((d) => yScale_\#{id}(\#{y}))\n .curve(d3.\#{curve}))\n .attr(\"fill\", \"\#{color}\")\n .attr(\"fill-opacity\", 0.5)\n HTML\nend\n"
|
#line(y:, color: "#ccc", curve: "curveCatmullRom.alpha(1)") ⇒ Object
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
# File 'lib/spoom/coverage/d3/timeline.rb', line 178
def line(y:, color: "#ccc", curve: "curveCatmullRom.alpha(1)")
" svg_\#{id}.append(\"path\")\n .datum(data_\#{id}.filter((d) => \#{y}))\n .attr(\"class\", \"line\")\n .attr(\"d\", d3.line()\n .x((d) => xScale_\#{id}(parseDate(d.timestamp)))\n .y((d) => yScale_\#{id}(\#{y}))\n .curve(d3.\#{curve}))\n .attr(\"stroke\", \"\#{color}\")\n .attr(\"stroke-width\", 3)\n .attr(\"fill\", \"transparent\")\n HTML\nend\n"
|
#plot ⇒ Object
100
|
# File 'lib/spoom/coverage/d3/timeline.rb', line 100
def plot; end
|
#points(y:) ⇒ Object
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
# File 'lib/spoom/coverage/d3/timeline.rb', line 194
def points(y:)
" svg_\#{id}.selectAll(\"circle\")\n .data(data_\#{id})\n .enter()\n .append(\"circle\")\n .attr(\"class\", \"dot\")\n .attr(\"r\", 3)\n .attr(\"cx\", (d) => xScale_\#{id}(parseDate(d.timestamp)))\n .attr(\"cy\", (d, i) => yScale_\#{id}(\#{y}))\n .attr(\"fill\", \"#aaa\")\n .on(\"mouseover\", (d) => tooltip.style(\"opacity\", 1))\n .on(\"mousemove\", tooltip_\#{id})\n .on(\"mouseleave\", (d) => tooltip.style(\"opacity\", 0));\n HTML\nend\n"
|
#script ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/spoom/coverage/d3/timeline.rb', line 75
def script
" \#{tooltip}\n\n var data_\#{id} = \#{@data.to_json};\n\n function draw_\#{id}() {\n var width_\#{id} = document.getElementById(\"\#{id}\").clientWidth;\n var height_\#{id} = 200;\n\n d3.select(\"#\#{id}\").selectAll(\"*\").remove()\n\n var svg_\#{id} = d3.select(\"#\#{id}\")\n .attr(\"width\", width_\#{id})\n .attr(\"height\", height_\#{id})\n\n \#{plot}\n }\n\n draw_\#{id}();\n window.addEventListener(\"resize\", draw_\#{id});\n HTML\nend\n"
|
#x_scale ⇒ Object
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
# File 'lib/spoom/coverage/d3/timeline.rb', line 103
def x_scale
" var xScale_\#{id} = d3.scaleTime()\n .range([0, width_\#{id}])\n .domain(d3.extent(data_\#{id}, (d) => parseDate(d.timestamp)));\n\n svg_\#{id}.append(\"g\")\n .attr(\"class\", \"grid\")\n .attr(\"transform\", \"translate(0,\" + height_\#{id} + \")\")\n .call(d3.axisBottom(xScale_\#{id})\n .tickFormat(\"\")\n .tickSize(-height_\#{id}))\n HTML\nend\n"
|
#x_ticks ⇒ Object
119
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/spoom/coverage/d3/timeline.rb', line 119
def x_ticks
" svg_\#{id}.append(\"g\")\n .attr(\"class\", \"axis x\")\n .attr(\"transform\", \"translate(0,\" + height_\#{id} + \")\")\n .call(d3.axisBottom(xScale_\#{id})\n .tickFormat(d3.timeFormat(\"%y/%m/%d\"))\n .tickPadding(-15)\n .tickSize(-3));\n HTML\nend\n"
|
#y_scale(min:, max:, ticks:) ⇒ Object
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
# File 'lib/spoom/coverage/d3/timeline.rb', line 132
def y_scale(min:, max:, ticks:)
" var yScale_\#{id} = d3.scaleLinear()\n .range([height_\#{id}, 0])\n .domain([\#{min}, \#{max}]);\n\n svg_\#{id}.append(\"g\")\n .attr(\"class\", \"grid\")\n .call(d3.axisLeft(yScale_\#{id})\n .\#{ticks}\n .tickFormat(\"\")\n .tickSize(-width_\#{id}))\n HTML\nend\n"
|
#y_ticks(ticks:, format:, padding:) ⇒ Object
148
149
150
151
152
153
154
155
156
157
158
|
# File 'lib/spoom/coverage/d3/timeline.rb', line 148
def y_ticks(ticks:, format:, padding:)
" svg_\#{id}.append(\"g\")\n .attr(\"class\", \"axis y\")\n .call(d3.axisLeft(yScale_\#{id})\n .\#{ticks}\n .tickSize(-3)\n .tickFormat((d) => \#{format})\n .tickPadding(-\#{padding}))\n HTML\nend\n"
|