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

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

Issue 2299473002: DevTools: Move BezierEditor from elements/ to ui/ (Closed)
Patch Set: Created 4 years, 3 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
OLDNEW
(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 {number} width
8 * @param {number} height
9 * @param {number} marginTop
10 * @param {number} controlPointRadius
11 * @param {boolean} linearLine
12 */
13 WebInspector.BezierUI = function(width, height, marginTop, controlPointRadius, l inearLine)
14 {
15 this.width = width;
16 this.height = height;
17 this.marginTop = marginTop;
18 this.radius = controlPointRadius;
19 this.linearLine = linearLine;
20 }
21
22 WebInspector.BezierUI.prototype = {
23 /**
24 * @return {number}
25 */
26 curveWidth: function()
27 {
28 return this.width - this.radius * 2;
29 },
30
31 /**
32 * @return {number}
33 */
34 curveHeight: function()
35 {
36 return this.height - this.radius * 2 - this.marginTop * 2;
37 },
38
39 /**
40 * @param {!Element} parentElement
41 * @param {string} className
42 * @param {number} x1
43 * @param {number} y1
44 * @param {number} x2
45 * @param {number} y2
46 */
47 _drawLine: function(parentElement, className, x1, y1, x2, y2)
48 {
49 var line = parentElement.createSVGChild("line", className);
50 line.setAttribute("x1", x1 + this.radius);
51 line.setAttribute("y1", y1 + this.radius + this.marginTop);
52 line.setAttribute("x2", x2 + this.radius);
53 line.setAttribute("y2", y2 + this.radius + this.marginTop);
54 },
55
56 /**
57 * @param {!Element} parentElement
58 * @param {number} startX
59 * @param {number} startY
60 * @param {number} controlX
61 * @param {number} controlY
62 */
63 _drawControlPoints: function(parentElement, startX, startY, controlX, contro lY)
64 {
65 this._drawLine(parentElement, "bezier-control-line", startX, startY, con trolX, controlY);
66 var circle = parentElement.createSVGChild("circle", "bezier-control-circ le");
67 circle.setAttribute("cx", controlX + this.radius);
68 circle.setAttribute("cy", controlY + this.radius + this.marginTop);
69 circle.setAttribute("r", this.radius);
70 },
71
72 /**
73 * @param {?WebInspector.Geometry.CubicBezier} bezier
74 * @param {!Element} svg
75 */
76 drawCurve: function(bezier, svg)
77 {
78 if (!bezier)
79 return;
80 var width = this.curveWidth();
81 var height = this.curveHeight();
82 svg.setAttribute("width", this.width);
83 svg.setAttribute("height", this.height);
84 svg.removeChildren();
85 var group = svg.createSVGChild("g");
86
87 if (this.linearLine)
88 this._drawLine(group, "linear-line", 0, height, width, 0);
89
90 var curve = group.createSVGChild("path", "bezier-path");
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),
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)
95 ];
96 curve.setAttribute("d", "M" + this.radius + "," + (height + this.radius + this.marginTop) + " C" + curvePoints.join(" "));
97
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);
100 }
101 }
102
103 WebInspector.BezierUI.Height = 26;
104
105 /**
106 * @param {!WebInspector.Geometry.CubicBezier} bezier
107 * @param {!Element} path
108 * @param {number} width
109 */
110 WebInspector.BezierUI.drawVelocityChart = function(bezier, path, width)
111 {
112 var height = WebInspector.BezierUI.Height;
113 var pathBuilder = ["M", 0, height];
114 /** @const */ var sampleSize = 1 / 40;
115
116 var prev = bezier.evaluateAt(0);
117 for (var t = sampleSize; t < 1 + sampleSize; t += sampleSize) {
118 var current = bezier.evaluateAt(t);
119 var slope = (current.y - prev.y) / (current.x - prev.x);
120 var weightedX = prev.x * (1 - t) + current.x * t;
121 slope = Math.tanh(slope / 1.5); // Normalise slope
122 pathBuilder = pathBuilder.concat(["L", (weightedX * width).toFixed(2), ( height - slope * height).toFixed(2) ]);
123 prev = current;
124 }
125 pathBuilder = pathBuilder.concat(["L", width.toFixed(2), height, "Z"]);
126 path.setAttribute("d", pathBuilder.join(" "));
127 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698