Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: Source/devtools/front_end/elements/BezierUI.js

Issue 1151263007: Devtools: Move animation to separate module (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @constructor 6 * @constructor
7 * @param {number} width 7 * @param {number} width
8 * @param {number} height 8 * @param {number} height
9 * @param {number} marginTop 9 * @param {number} marginTop
10 * @param {number} controlPointRadius 10 * @param {number} controlPointRadius
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 71
72 /** 72 /**
73 * @param {?WebInspector.Geometry.CubicBezier} bezier 73 * @param {?WebInspector.Geometry.CubicBezier} bezier
74 * @param {!Element} svg 74 * @param {!Element} svg
75 */ 75 */
76 drawCurve: function(bezier, svg) 76 drawCurve: function(bezier, svg)
77 { 77 {
78 if (!bezier) 78 if (!bezier)
79 return; 79 return;
80 var width = this.curveWidth(); 80 var width = this.curveWidth();
81 var height = this.curveHeight();; 81 var height = this.curveHeight();
82 svg.setAttribute("width", this.width); 82 svg.setAttribute("width", this.width);
83 svg.setAttribute("height", this.height); 83 svg.setAttribute("height", this.height);
84 svg.removeChildren(); 84 svg.removeChildren();
85 var group = svg.createSVGChild("g"); 85 var group = svg.createSVGChild("g");
86 86
87 if (this.linearLine) 87 if (this.linearLine)
88 this._drawLine(group, "linear-line", 0, height, width, 0); 88 this._drawLine(group, "linear-line", 0, height, width, 0);
89 89
90 var curve = group.createSVGChild("path", "bezier-path"); 90 var curve = group.createSVGChild("path", "bezier-path");
91 var curvePoints = [ 91 var curvePoints = [
92 new WebInspector.Geometry.Point(bezier.controlPoints[0].x * width + this.radius, (1 - bezier.controlPoints[0].y) * height + this.radius + this.margi nTop), 92 new WebInspector.Geometry.Point(bezier.controlPoints[0].x * width + this.radius, (1 - bezier.controlPoints[0].y) * height + this.radius + this.margi nTop),
93 new WebInspector.Geometry.Point(bezier.controlPoints[1].x * width + this.radius, (1 - bezier.controlPoints[1].y) * height + this.radius + this.margi nTop), 93 new WebInspector.Geometry.Point(bezier.controlPoints[1].x * width + this.radius, (1 - bezier.controlPoints[1].y) * height + this.radius + this.margi nTop),
94 new WebInspector.Geometry.Point(width + this.radius, this.marginTop + this.radius) 94 new WebInspector.Geometry.Point(width + this.radius, this.marginTop + this.radius)
95 ]; 95 ];
96 curve.setAttribute("d", "M" + this.radius + "," + (height + this.radius + this.marginTop) + " C" + curvePoints.join(" ")); 96 curve.setAttribute("d", "M" + this.radius + "," + (height + this.radius + this.marginTop) + " C" + curvePoints.join(" "));
97 97
98 this._drawControlPoints(group, 0, height, bezier.controlPoints[0].x * wi dth, (1 - bezier.controlPoints[0].y) * height); 98 this._drawControlPoints(group, 0, height, bezier.controlPoints[0].x * wi dth, (1 - bezier.controlPoints[0].y) * height);
99 this._drawControlPoints(group, width, 0, bezier.controlPoints[1].x * wid th, (1 - bezier.controlPoints[1].y) * height); 99 this._drawControlPoints(group, width, 0, bezier.controlPoints[1].x * wid th, (1 - bezier.controlPoints[1].y) * height);
100 } 100 }
101 } 101 }
102 102
103 WebInspector.BezierUI.Height = 32;
104
103 /** 105 /**
104 * @param {!WebInspector.Geometry.CubicBezier} bezier 106 * @param {!WebInspector.Geometry.CubicBezier} bezier
105 * @param {!Element} path 107 * @param {!Element} path
106 * @param {number} width 108 * @param {number} width
107 */ 109 */
108 WebInspector.BezierUI.drawVelocityChart = function(bezier, path, width) 110 WebInspector.BezierUI.drawVelocityChart = function(bezier, path, width)
109 { 111 {
110 var height = WebInspector.AnimationUI.Options.AnimationHeight; 112 var height = WebInspector.BezierUI.Height;
111 var pathBuilder = ["M", 0, height]; 113 var pathBuilder = ["M", 0, height];
112 const sampleSize = 1 / 40; 114 const sampleSize = 1 / 40;
113 115
114 var prev = bezier.evaluateAt(0); 116 var prev = bezier.evaluateAt(0);
115 for (var t = sampleSize; t < 1 + sampleSize; t += sampleSize) { 117 for (var t = sampleSize; t < 1 + sampleSize; t += sampleSize) {
116 var current = bezier.evaluateAt(t); 118 var current = bezier.evaluateAt(t);
117 var slope = (current.y - prev.y) / (current.x - prev.x); 119 var slope = (current.y - prev.y) / (current.x - prev.x);
118 var weightedX = prev.x * (1 - t) + current.x * t; 120 var weightedX = prev.x * (1 - t) + current.x * t;
119 slope = Math.tanh(slope / 1.5); // Normalise slope 121 slope = Math.tanh(slope / 1.5); // Normalise slope
120 pathBuilder = pathBuilder.concat(["L", (weightedX * width).toFixed(2), ( height - slope * height).toFixed(2) ]); 122 pathBuilder = pathBuilder.concat(["L", (weightedX * width).toFixed(2), ( height - slope * height).toFixed(2) ]);
121 prev = current; 123 prev = current;
122 } 124 }
123 pathBuilder = pathBuilder.concat(["L", width.toFixed(2), height, "Z"]); 125 pathBuilder = pathBuilder.concat(["L", width.toFixed(2), height, "Z"]);
124 path.setAttribute("d", pathBuilder.join(" ")); 126 path.setAttribute("d", pathBuilder.join(" "));
125 } 127 }
OLDNEW
« no previous file with comments | « Source/devtools/front_end/elements/AnimationTimeline.js ('k') | Source/devtools/front_end/elements/animationTimeline.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698