forked from google/charts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chart_canvas.dart
148 lines (132 loc) · 5.5 KB
/
chart_canvas.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// Copyright 2018 the Charts project authors. Please see the AUTHORS file
// for details.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import 'dart:math' show Point, Rectangle;
import 'canvas_shapes.dart' show CanvasBarStack, CanvasPie;
import '../../common/color.dart' show Color;
import '../../common/text_element.dart' show TextElement;
abstract class ChartCanvas {
/// Set the name of the view doing the rendering for debugging purposes,
/// or null when we believe rendering is complete.
set drawingView(String viewName);
/// Renders a sector of a circle, with an optional hole in the center.
///
/// [center] The x, y coordinates of the circle's center.
/// [radius] The radius of the circle.
/// [innerRadius] Optional radius of a hole in the center of the circle that
/// should not be filled in as part of the sector.
/// [startAngle] The angle at which the arc starts, measured clockwise from
/// the positive x axis and expressed in radians
/// [endAngle] The angle at which the arc ends, measured clockwise from the
/// positive x axis and expressed in radians.
/// [fill] Fill color for the sector.
/// [stroke] Stroke color of the arc and radius lines.
/// [strokeWidthPx] Stroke width of the arc and radius lines.
void drawCircleSector(Point center, double radius, double innerRadius,
double startAngle, double endAngle,
{Color fill, Color stroke, double strokeWidthPx});
/// Renders a simple line.
///
/// [dashPattern] controls the pattern of dashes and gaps in a line. It is a
/// list of lengths of alternating dashes and gaps. The rendering is similar
/// to stroke-dasharray in SVG path elements. An odd number of values in the
/// pattern will be repeated to derive an even number of values. "1,2,3" is
/// equivalent to "1,2,3,1,2,3."
void drawLine(
{List<Point> points,
Rectangle<num> clipBounds,
Color fill,
Color stroke,
bool smoothLine,
bool roundEndCaps,
double strokeWidthPx,
List<int> dashPattern});
/// Renders a pie, with an optional hole in the center.
void drawPie(CanvasPie canvasPie);
/// Renders a simple point.
///
/// [point] The x, y coordinates of the point.
///
/// [radius] The radius of the point.
///
/// [fill] Fill color for the point.
///
/// [stroke] and [strokeWidthPx] configure the color and thickness of the
/// outer edge of the point. Both must be provided together for a line to
/// appear.
void drawPoint(
{Point point,
double radius,
Color fill,
Color stroke,
double strokeWidthPx});
/// Renders a polygon shape described by a set of points.
///
/// [points] describes the vertices of the polygon. The last point will always
/// be connected to the first point to close the shape.
///
/// [fill] configures the color inside the polygon. The shape will be
/// transparent if this is not provided.
///
/// [stroke] and [strokeWidthPx] configure the color and thickness of the
/// edges of the polygon. Both must be provided together for a line to appear.
void drawPolygon(
{List<Point> points,
Rectangle<num> clipBounds,
Color fill,
Color stroke,
double strokeWidthPx,
bool fillGradient,
bool smoothLine});
/// Renders a simple rectangle.
void drawRect(Rectangle<num> bounds,
{Color fill, Color stroke, double strokeWidthPx});
/// Renders a rounded rectangle.
void drawRRect(Rectangle<num> bounds,
{Color fill,
Color stroke,
num radius,
bool roundTopLeft,
bool roundTopRight,
bool roundBottomLeft,
bool roundBottomRight});
/// Renders a stack of bars, rounding the last bar in the stack.
///
/// The first bar of the stack is expected to be the "base" bar. This would
/// be the bottom most bar for a vertically rendered bar.
void drawBarStack(CanvasBarStack canvasBarStack);
void drawText(TextElement textElement, int offsetX, int offsetY,
{double rotation = 0.0});
/// Request the canvas to clip to [clipBounds].
///
/// Applies to all operations until [restClipBounds] is called.
void setClipBounds(Rectangle<int> clipBounds);
/// Restore
void resetClipBounds();
}
Color getAnimatedColor(Color previous, Color target, double animationPercent) {
var r = (((target.r - previous.r) * animationPercent) + previous.r).round();
var g = (((target.g - previous.g) * animationPercent) + previous.g).round();
var b = (((target.b - previous.b) * animationPercent) + previous.b).round();
var a = (((target.a - previous.a) * animationPercent) + previous.a).round();
return new Color(a: a, r: r, g: g, b: b);
}
/// Defines the pattern for a color fill.
///
/// * [forwardHatch] defines a pattern of white lines angled up and to the right
/// on top of a bar filled with the fill color.
/// * [solid] defines a simple bar filled with the fill color. This is the
/// default pattern for bars.
/// * [gradient] defines a simple bar filled with the gradient color
enum FillPatternType { forwardHatch, solid, gradient }