| OLD | NEW |
| 1 // | 1 // |
| 2 // Copyright 2014 Google Inc. All rights reserved. | 2 // Copyright 2014 Google Inc. All rights reserved. |
| 3 // | 3 // |
| 4 // Use of this source code is governed by a BSD-style | 4 // Use of this source code is governed by a BSD-style |
| 5 // license that can be found in the LICENSE file or at | 5 // license that can be found in the LICENSE file or at |
| 6 // https://developers.google.com/open-source/licenses/bsd | 6 // https://developers.google.com/open-source/licenses/bsd |
| 7 // | 7 // |
| 8 | 8 |
| 9 part of charted.svg.shapes; | 9 part of charted.svg.shapes; |
| 10 | 10 |
| 11 /// Draw a rectangle at [x], [y] which is [width] pixels wide and | 11 /// Draw a rectangle at [x], [y] which is [width] pixels wide and |
| 12 /// [height] pixels height. [topLeft], [topRight], [bottomRight] and | 12 /// [height] pixels height. [topLeft], [topRight], [bottomRight] and |
| 13 /// [bottomLeft] are the corner radius at each of the four corners. | 13 /// [bottomLeft] are the corner radius at each of the four corners. |
| 14 String roundedRect(int x, int y, int width, int height, | 14 String roundedRect(int x, int y, int width, int height, int topLeft, |
| 15 int topLeft, int topRight, int bottomRight, int bottomLeft) => | 15 int topRight, int bottomRight, int bottomLeft) => |
| 16 'M${x+topLeft},${y} ' | 16 'M${x+topLeft},${y} ' |
| 17 'L${x+width-topRight},${y} ' | 17 'L${x+width-topRight},${y} ' |
| 18 'Q${x+width},${y} ${x+width},${y+topRight}' | 18 'Q${x+width},${y} ${x+width},${y+topRight}' |
| 19 'L${x+width},${y+height-bottomRight} ' | 19 'L${x+width},${y+height-bottomRight} ' |
| 20 'Q${x+width},${y+height} ${x+width-bottomRight},${y+height}' | 20 'Q${x+width},${y+height} ${x+width-bottomRight},${y+height}' |
| 21 'L${x+bottomLeft},${y+height} ' | 21 'L${x+bottomLeft},${y+height} ' |
| 22 'Q${x},${y+height} ${x},${y+height-bottomLeft}' | 22 'Q${x},${y+height} ${x},${y+height-bottomLeft}' |
| 23 'L${x},${y+topLeft} ' | 23 'L${x},${y+topLeft} ' |
| 24 'Q${x},${y} ${x+topLeft},${y} Z'; | 24 'Q${x},${y} ${x+topLeft},${y} Z'; |
| 25 | 25 |
| 26 /// Draw a rectangle with rounded corners on both corners on the right. | 26 /// Draw a rectangle with rounded corners on both corners on the right. |
| 27 String rightRoundedRect(int x, int y, int width, int height, int radius) { | 27 String rightRoundedRect(int x, int y, int width, int height, int radius) { |
| 28 if (width < radius) radius = width; | 28 if (width < radius) radius = width; |
| 29 if (height < radius * 2) radius = height ~/ 2; | 29 if (height < radius * 2) radius = height ~/ 2; |
| 30 return roundedRect(x, y, width, height, 0, radius, radius, 0); | 30 return roundedRect(x, y, width, height, 0, radius, radius, 0); |
| 31 } | 31 } |
| 32 | 32 |
| 33 /// Draw a rectangle with rounded corners on both corners on the top. | 33 /// Draw a rectangle with rounded corners on both corners on the top. |
| 34 String topRoundedRect(int x, int y, int width, int height, int radius) { | 34 String topRoundedRect(int x, int y, int width, int height, int radius) { |
| 35 if (height < radius) radius = height; | 35 if (height < radius) radius = height; |
| 36 if (width < radius * 2) radius = width ~/ 2; | 36 if (width < radius * 2) radius = width ~/ 2; |
| 37 return roundedRect(x, y, width, height, radius, radius, 0, 0); | 37 return roundedRect(x, y, width, height, radius, radius, 0, 0); |
| 38 } | 38 } |
| 39 | 39 |
| 40 /// Draw a rectangle with rounded corners on both corners on the right. | 40 /// Draw a rectangle with rounded corners on both corners on the right. |
| 41 String leftRoundedRect(int x, int y, int width, int height, int radius) { | 41 String leftRoundedRect(int x, int y, int width, int height, int radius) { |
| 42 if (width < radius) radius = width; | 42 if (width < radius) radius = width; |
| 43 if (height < radius * 2) radius = height ~/ 2; | 43 if (height < radius * 2) radius = height ~/ 2; |
| 44 return roundedRect(x, y, width, height, radius, 0, 0, radius); | 44 return roundedRect(x, y, width, height, radius, 0, 0, radius); |
| 45 } | 45 } |
| 46 | 46 |
| 47 /// Draw a rectangle with rounded corners on both corners on the top. | 47 /// Draw a rectangle with rounded corners on both corners on the top. |
| 48 String bottomRoundedRect(int x, int y, int width, int height, int radius) { | 48 String bottomRoundedRect(int x, int y, int width, int height, int radius) { |
| 49 if (height < radius) radius = height; | 49 if (height < radius) radius = height; |
| 50 if (width < radius * 2) radius = width ~/ 2; | 50 if (width < radius * 2) radius = width ~/ 2; |
| 51 return roundedRect(x, y, width, height, 0, 0, radius, radius); | 51 return roundedRect(x, y, width, height, 0, 0, radius, radius); |
| 52 } | 52 } |
| OLD | NEW |