Commit ed010499 authored by Hixie's avatar Hixie

Prettier arrows in the stock app.

This returns us to a more stocks1-like arrow style.
Also it uses math rather than transforms to rotate the arrow, since transforms are expensive.
It also removes the save/restore calls, which are _really_ expensive.

Also some minor style fixes.

R=eseidel@chromium.org

Review URL: https://codereview.chromium.org/1203443007.
parent 3616adba
...@@ -35,41 +35,41 @@ class StockArrow extends Component { ...@@ -35,41 +35,41 @@ class StockArrow extends Component {
var arrow = new CustomPaint(callback: (sky.Canvas canvas, Size size) { var arrow = new CustomPaint(callback: (sky.Canvas canvas, Size size) {
Paint paint = new Paint()..color = color; Paint paint = new Paint()..color = color;
paint.strokeWidth = 1.0; paint.strokeWidth = 1.0;
var padding = paint.strokeWidth * 3.0; const double padding = 2.0;
var r = kSize / 2.0 - padding; assert(padding > paint.strokeWidth / 2.0); // make sure the circle remains inside the box
canvas.save(); double r = (kSize - padding) / 2.0; // radius of the circle
canvas.translate(padding, padding); double centerX = padding + r;
double centerY = padding + r;
// The arrow (below) is drawn upwards by default. // Draw the arrow.
double w = 8.0;
double h = 5.0;
double arrowY;
if (percentChange < 0.0) { if (percentChange < 0.0) {
canvas.translate(r, r); h = -h;
canvas.rotate(math.PI); arrowY = centerX + 1.0;
canvas.translate(-r, -r); } else {
arrowY = centerX - 1.0;
} }
Path path = new Path();
// Draw the (equliateral triangle) arrow. path.moveTo(centerX, arrowY - h); // top of the arrow
var dx = math.sqrt(3.0) * r / 2.0; path.lineTo(centerX + w, arrowY + h);
var path = new Path(); path.lineTo(centerX - w, arrowY + h);
path.moveTo(r, 0.0);
path.lineTo(r + dx, r * 1.5);
path.lineTo(r - dx, r * 1.5);
path.lineTo(r, 0.0);
path.close(); path.close();
paint.setStyle(sky.PaintingStyle.fill); paint.setStyle(sky.PaintingStyle.fill);
canvas.drawPath(path, paint); canvas.drawPath(path, paint);
// Draw a circle that circumscribes the arrow. // Draw a circle that circumscribes the arrow.
paint.setStyle(sky.PaintingStyle.stroke); paint.setStyle(sky.PaintingStyle.stroke);
canvas.drawCircle(r, r, r + 2.0, paint); canvas.drawCircle(centerX, centerY, r, paint);
canvas.restore();
}); });
return new Container( return new Container(
child: arrow, child: arrow,
width: kSize, width: kSize,
height: kSize, height: kSize,
margin: const EdgeDims.symmetric(horizontal: 5.0)); margin: const EdgeDims.symmetric(horizontal: 5.0)
);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment