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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/perf_ui/PieChart.js

Issue 2664463002: DevTools: Turn pie chart into a donut chart. (Closed)
Patch Set: fix ESLint Created 3 years, 10 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/devtools/front_end/timeline/TimelineUIUtils.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 25 matching lines...) Expand all
36 * @param {number} size 36 * @param {number} size
37 * @param {function(number):string=} formatter 37 * @param {function(number):string=} formatter
38 * @param {boolean=} showTotal 38 * @param {boolean=} showTotal
39 */ 39 */
40 constructor(size, formatter, showTotal) { 40 constructor(size, formatter, showTotal) {
41 this.element = createElement('div'); 41 this.element = createElement('div');
42 this._shadowRoot = UI.createShadowRootWithCoreStyles(this.element, 'perf_ui/ pieChart.css'); 42 this._shadowRoot = UI.createShadowRootWithCoreStyles(this.element, 'perf_ui/ pieChart.css');
43 var root = this._shadowRoot.createChild('div', 'root'); 43 var root = this._shadowRoot.createChild('div', 'root');
44 var svg = this._createSVGChild(root, 'svg'); 44 var svg = this._createSVGChild(root, 'svg');
45 this._group = this._createSVGChild(svg, 'g'); 45 this._group = this._createSVGChild(svg, 'g');
46 var background = this._createSVGChild(this._group, 'circle'); 46 this._innerR = 0.618;
47 background.setAttribute('r', 1.01); 47 var strokeWidth = 1 / size;
48 background.setAttribute('fill', 'hsl(0, 0%, 90%)'); 48 var circle = this._createSVGChild(this._group, 'circle');
49 circle.setAttribute('r', 1);
50 circle.setAttribute('stroke', 'hsl(0, 0%, 80%)');
51 circle.setAttribute('fill', 'transparent');
52 circle.setAttribute('stroke-width', strokeWidth);
53 circle = this._createSVGChild(this._group, 'circle');
54 circle.setAttribute('r', this._innerR);
55 circle.setAttribute('stroke', 'hsl(0, 0%, 80%)');
56 circle.setAttribute('fill', 'transparent');
57 circle.setAttribute('stroke-width', strokeWidth);
49 this._foregroundElement = root.createChild('div', 'pie-chart-foreground'); 58 this._foregroundElement = root.createChild('div', 'pie-chart-foreground');
50 if (showTotal) 59 if (showTotal)
51 this._totalElement = this._foregroundElement.createChild('div', 'pie-chart -total'); 60 this._totalElement = this._foregroundElement.createChild('div', 'pie-chart -total');
52 this._formatter = formatter; 61 this._formatter = formatter;
53 this._slices = []; 62 this._slices = [];
54 this._lastAngle = -Math.PI / 2; 63 this._lastAngle = -Math.PI / 2;
55 this._setSize(size); 64 this._setSize(size);
56 } 65 }
57 66
58 /** 67 /**
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 var sliceAngle = value / this._totalValue * 2 * Math.PI; 99 var sliceAngle = value / this._totalValue * 2 * Math.PI;
91 if (!isFinite(sliceAngle)) 100 if (!isFinite(sliceAngle))
92 return; 101 return;
93 sliceAngle = Math.min(sliceAngle, 2 * Math.PI * 0.9999); 102 sliceAngle = Math.min(sliceAngle, 2 * Math.PI * 0.9999);
94 var path = this._createSVGChild(this._group, 'path'); 103 var path = this._createSVGChild(this._group, 'path');
95 var x1 = Math.cos(this._lastAngle); 104 var x1 = Math.cos(this._lastAngle);
96 var y1 = Math.sin(this._lastAngle); 105 var y1 = Math.sin(this._lastAngle);
97 this._lastAngle += sliceAngle; 106 this._lastAngle += sliceAngle;
98 var x2 = Math.cos(this._lastAngle); 107 var x2 = Math.cos(this._lastAngle);
99 var y2 = Math.sin(this._lastAngle); 108 var y2 = Math.sin(this._lastAngle);
109 var r2 = this._innerR;
110 var x3 = x2 * r2;
111 var y3 = y2 * r2;
112 var x4 = x1 * r2;
113 var y4 = y1 * r2;
100 var largeArc = sliceAngle > Math.PI ? 1 : 0; 114 var largeArc = sliceAngle > Math.PI ? 1 : 0;
101 path.setAttribute('d', 'M0,0 L' + x1 + ',' + y1 + ' A1,1,0,' + largeArc + ', 1,' + x2 + ',' + y2 + ' Z'); 115 path.setAttribute('d',
116 `M${x1},${y1} A1,1,0,${largeArc},1,${x2},${y2} L${x3},${y3} A${r2},${r2} ,0,${largeArc},0,${x4},${y4} Z`);
102 path.setAttribute('fill', color); 117 path.setAttribute('fill', color);
103 this._slices.push(path); 118 this._slices.push(path);
104 } 119 }
105 120
106 /** 121 /**
107 * @param {!Element} parent 122 * @param {!Element} parent
108 * @param {string} childType 123 * @param {string} childType
109 * @return {!Element} 124 * @return {!Element}
110 */ 125 */
111 _createSVGChild(parent, childType) { 126 _createSVGChild(parent, childType) {
112 var child = parent.ownerDocument.createElementNS('http://www.w3.org/2000/svg ', childType); 127 var child = parent.ownerDocument.createElementNS('http://www.w3.org/2000/svg ', childType);
113 parent.appendChild(child); 128 parent.appendChild(child);
114 return child; 129 return child;
115 } 130 }
116 }; 131 };
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/devtools/front_end/timeline/TimelineUIUtils.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698