OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 /** |
| 6 * @constructor |
| 7 * @param {!WebInspector.AnimationModel.AnimationGroup} model |
| 8 */ |
| 9 WebInspector.AnimationGroupPreviewUI = function(model) |
| 10 { |
| 11 this._model = model; |
| 12 this.element = createElementWithClass("div", "animation-buffer-preview"); |
| 13 this._svg = this.element.createSVGChild("svg"); |
| 14 this._svg.setAttribute("width", "100%"); |
| 15 this._svg.setAttribute("preserveAspectRatio", "none"); |
| 16 this._svg.setAttribute("height", "100%"); |
| 17 this._svg.setAttribute("viewBox", "0 0 100 27"); |
| 18 this._svg.setAttribute("shape-rendering", "crispEdges"); |
| 19 this._render(); |
| 20 } |
| 21 |
| 22 WebInspector.AnimationGroupPreviewUI.prototype = { |
| 23 /** |
| 24 * @return {number} |
| 25 */ |
| 26 _groupDuration: function() |
| 27 { |
| 28 var duration = 0; |
| 29 for (var anim of this._model.animations()) { |
| 30 var animDuration = anim.source().delay() + anim.source().duration(); |
| 31 if (animDuration > duration) |
| 32 duration = animDuration; |
| 33 } |
| 34 return duration; |
| 35 }, |
| 36 |
| 37 _render: function() |
| 38 { |
| 39 this._svg.removeChildren(); |
| 40 const numberOfAnimations = Math.min(this._model.animations().length, 10)
; |
| 41 var timeToPixelRatio = 100 / Math.max(this._groupDuration(), 300); |
| 42 for (var i = 0; i < numberOfAnimations; i++) { |
| 43 var effect = this._model.animations()[i].source(); |
| 44 var line = this._svg.createSVGChild("line"); |
| 45 line.setAttribute("x1", effect.delay() * timeToPixelRatio); |
| 46 line.setAttribute("x2", (effect.delay() + effect.duration()) * timeT
oPixelRatio); |
| 47 var y = Math.floor(27 / numberOfAnimations * i) + 1; |
| 48 line.setAttribute("y1", y); |
| 49 line.setAttribute("y2", y); |
| 50 line.style.stroke = WebInspector.AnimationUI.Color(this._model.anima
tions()[i]); |
| 51 } |
| 52 } |
| 53 } |
OLD | NEW |