Commit 123313cb667a25ee6301fdc23e651d4904e9c78e
1 parent
c3008fb2
Exists in
master
and in
2 other branches
Clip the paths of the time series. Some more misc cleanup.
Showing
2 changed files
with
46 additions
and
28 deletions
Show diff stats
web/static/js/swapp.js
... | ... | @@ -251,7 +251,7 @@ |
251 | 251 | }()); |
252 | 252 | out$.TimeSeries = TimeSeries = (function(){ |
253 | 253 | TimeSeries.displayName = 'TimeSeries'; |
254 | - var prototype = TimeSeries.prototype, constructor = TimeSeries; | |
254 | + var RATIO, prototype = TimeSeries.prototype, constructor = TimeSeries; | |
255 | 255 | function TimeSeries(parameter, title, target, data, visible, container, options){ |
256 | 256 | this.parameter = parameter; |
257 | 257 | this.title = title; |
... | ... | @@ -282,7 +282,7 @@ |
282 | 282 | }); |
283 | 283 | }; |
284 | 284 | TimeSeries.prototype.init = function(){ |
285 | - var dx, this$ = this; | |
285 | + var clipId, dx, this$ = this; | |
286 | 286 | console.info("Initializing plot of " + this + "…"); |
287 | 287 | this.margin = { |
288 | 288 | top: 30, |
... | ... | @@ -303,7 +303,11 @@ |
303 | 303 | this.svg.attr("class", this.parameter + " " + this.target.slug); |
304 | 304 | this.plotWrapper = this.svg.append('g'); |
305 | 305 | this.plotWrapper.attr('transform', 'translate(' + this.margin.left + ',' + this.margin.top + ')'); |
306 | - this.path = this.plotWrapper.append('path').datum(this.data).classed('line', true); | |
306 | + clipId = "ts-clip-" + this.parameter + "-" + this.target.slug; | |
307 | + this.clip = this.svg.append("defs").append("svg:clipPath").attr("id", clipId).append("svg:rect").attr("x", 0).attr("y", 0); | |
308 | + this.pathWrapper = this.plotWrapper.append('g'); | |
309 | + this.pathWrapper.attr("clip-path", "url(#" + clipId + ")"); | |
310 | + this.path = this.pathWrapper.append('path').datum(this.data).classed('line', true); | |
307 | 311 | this.brush = this.plotWrapper.append("g").attr("class", "brush"); |
308 | 312 | this.mouseCanvas = this.plotWrapper.append("rect").style("fill", "none"); |
309 | 313 | this.plotWrapper.append('g').classed('x axis', true); |
... | ... | @@ -319,15 +323,18 @@ |
319 | 323 | this.cursorDate = this.focus.append("text").attr("class", "cursor-text cursor-date").attr("dx", dx).attr("dy", "1em"); |
320 | 324 | return this.resize(); |
321 | 325 | }; |
326 | + RATIO = GOLDEN_RATIO * GOLDEN_RATIO * GOLDEN_RATIO * GOLDEN_RATIO; | |
322 | 327 | TimeSeries.prototype.resize = function(){ |
323 | 328 | var width, height; |
324 | - width = jQuery(this.container).width() - this.margin.left - this.margin.right; | |
325 | - height = GOLDEN_RATIO * GOLDEN_RATIO * GOLDEN_RATIO * GOLDEN_RATIO * width; | |
329 | + width = Math.ceil($(this.container).width() - this.margin.left - this.margin.right); | |
330 | + height = Math.ceil(RATIO * width); | |
326 | 331 | this.plotWidth = width; |
327 | 332 | this.plotHeight = height; |
333 | + console.debug("Resizing " + this + ": " + width + " x " + height + "…"); | |
328 | 334 | this.xScale.range([0, width]); |
329 | 335 | this.yScale.range([height, 0]); |
330 | 336 | this.svg.attr('width', width + this.margin.right + this.margin.left).attr('height', height + this.margin.top + this.margin.bottom); |
337 | + this.clip.attr("width", width).attr("height", height); | |
331 | 338 | this.path.attr('d', this.line); |
332 | 339 | this.xAxis.scale(this.xScale); |
333 | 340 | this.yAxis.scale(this.yScale); | ... | ... |
web/static/js/swapp.ls
... | ... | @@ -257,7 +257,16 @@ export class TimeSeries |
257 | 257 | @plotWrapper.attr('transform', |
258 | 258 | 'translate(' + @margin.left + ',' + @margin.top + ')') |
259 | 259 | |
260 | - @path = @plotWrapper.append('path') | |
260 | + clipId = "ts-clip-#{@parameter}-#{@target.slug}" | |
261 | + @clip = @svg.append("defs").append("svg:clipPath") | |
262 | + .attr("id", clipId) | |
263 | + .append("svg:rect") | |
264 | + .attr("x", 0) | |
265 | + .attr("y", 0) | |
266 | + | |
267 | + @pathWrapper = @plotWrapper.append('g') | |
268 | + @pathWrapper.attr("clip-path", "url(\##{clipId})") | |
269 | + @path = @pathWrapper.append('path') | |
261 | 270 | .datum(@data) |
262 | 271 | .classed('line', true) |
263 | 272 | |
... | ... | @@ -267,39 +276,37 @@ export class TimeSeries |
267 | 276 | # deprecated, use brush's 'overlay' child |
268 | 277 | @mouseCanvas = @plotWrapper.append("rect") |
269 | 278 | .style("fill", "none") |
270 | -# .style("pointer-events", "all") | |
271 | 279 | |
272 | 280 | @plotWrapper.append('g').classed('x axis', true) |
273 | 281 | @plotWrapper.append('g').classed('y axis', true) |
274 | 282 | @yAxisText = @plotWrapper.append("text") |
275 | - .attr("transform", "rotate(-90)") | |
276 | - .attr("dy", "1em") | |
277 | - .style("text-anchor", "middle") | |
278 | - .text(@title) | |
283 | + .attr("transform", "rotate(-90)") | |
284 | + .attr("dy", "1em") | |
285 | + .style("text-anchor", "middle") | |
286 | + .text(@title) | |
279 | 287 | @yAxisTextTarget = @plotWrapper.append("text") |
280 | - .attr("transform", "rotate(-90)") | |
281 | - .attr("dy", "1em") | |
282 | - .style("text-anchor", "middle") | |
283 | - .style("font-style", "oblique") | |
284 | - .text(@target.name) | |
288 | + .attr("transform", "rotate(-90)") | |
289 | + .attr("dy", "1em") | |
290 | + .style("text-anchor", "middle") | |
291 | + .style("font-style", "oblique") | |
292 | + .text(@target.name) | |
285 | 293 | |
286 | 294 | @focus = @plotWrapper.append('g').style("display", "none") |
287 | 295 | |
288 | 296 | @cursorCircle = @focus.append("circle") |
289 | - .attr("class", "cursor-circle") | |
290 | - .attr("r", 3) | |
297 | + .attr("class", "cursor-circle") | |
298 | + .attr("r", 3) | |
291 | 299 | |
292 | 300 | dx = 8 |
293 | 301 | @cursorValueShadow = @focus.append("text") |
294 | - .attr("class", "cursor-text cursor-text-shadow") | |
295 | - .attr("dx", dx) | |
296 | - .attr("dy", "-.3em") | |
302 | + .attr("class", "cursor-text cursor-text-shadow") | |
303 | + .attr("dx", dx) | |
304 | + .attr("dy", "-.3em") | |
297 | 305 | |
298 | 306 | @cursorValue = @focus.append("text") |
299 | - .attr("class", "cursor-text cursor-value") | |
300 | - .attr("dx", dx) | |
301 | - .attr("dy", "-.3em") | |
302 | - | |
307 | + .attr("class", "cursor-text cursor-value") | |
308 | + .attr("dx", dx) | |
309 | + .attr("dy", "-.3em") | |
303 | 310 | |
304 | 311 | @cursorDateShadow = @focus.append("text") |
305 | 312 | .attr("class", "cursor-text cursor-text-shadow") |
... | ... | @@ -313,14 +320,15 @@ export class TimeSeries |
313 | 320 | |
314 | 321 | @resize() |
315 | 322 | |
323 | + RATIO = GOLDEN_RATIO * GOLDEN_RATIO * GOLDEN_RATIO * GOLDEN_RATIO | |
316 | 324 | resize: -> |
317 | - width = jQuery(@container).width() - @margin.left - @margin.right | |
318 | - height = GOLDEN_RATIO * GOLDEN_RATIO * GOLDEN_RATIO * GOLDEN_RATIO * width | |
325 | + width = Math.ceil($(@container).width() - @margin.left - @margin.right) | |
326 | + height = Math.ceil(RATIO * width) | |
319 | 327 | |
320 | 328 | @plotWidth = width |
321 | 329 | @plotHeight = height |
322 | 330 | |
323 | - #console.log("Resizing time series #{@title} of #{@target.name}: #{width} x #{height}") | |
331 | + console.debug("Resizing #{@}: #{width} x #{height}…") | |
324 | 332 | |
325 | 333 | @xScale.range([0, width]); |
326 | 334 | @yScale.range([height, 0]); |
... | ... | @@ -328,6 +336,9 @@ export class TimeSeries |
328 | 336 | @svg.attr('width', width + @margin.right + @margin.left) |
329 | 337 | .attr('height', height + @margin.top + @margin.bottom) |
330 | 338 | |
339 | + @clip.attr("width", width) | |
340 | + .attr("height", height) | |
341 | + | |
331 | 342 | @path.attr('d', @line) |
332 | 343 | |
333 | 344 | @xAxis.scale(@xScale) | ... | ... |