Skip to content

Commit

Permalink
GitHub Sync (google#9)
Browse files Browse the repository at this point in the history
* Added basic pie chart rendering. Animation and slice labels are not currently supported.

PiperOrigin-RevId: 189268892

* Update gallery formatting.

PiperOrigin-RevId: 189409440
  • Loading branch information
nshahan authored and JackMoseley2001 committed Nov 1, 2021
1 parent 6eeac49 commit ca42618
Show file tree
Hide file tree
Showing 22 changed files with 1,206 additions and 17 deletions.
6 changes: 5 additions & 1 deletion charts_common/lib/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export 'src/chart/common/behavior/zoom/pan_and_zoom_behavior.dart'
export 'src/chart/common/behavior/zoom/pan_behavior.dart' show PanBehavior;
export 'src/chart/common/chart_canvas.dart' show ChartCanvas, FillPatternType;
export 'src/chart/common/base_chart.dart' show BaseChart, LifecycleListener;
export 'src/chart/common/canvas_shapes.dart' show CanvasBarStack, CanvasRect;
export 'src/chart/common/canvas_shapes.dart'
show CanvasBarStack, CanvasPie, CanvasPieSlice, CanvasRect;
export 'src/chart/common/chart_context.dart' show ChartContext;
export 'src/chart/common/series_renderer.dart' show SeriesRenderer;
export 'src/chart/common/series_renderer_config.dart'
Expand Down Expand Up @@ -80,4 +81,7 @@ export 'src/chart/cartesian/cartesian_renderer.dart' show BaseCartesianRenderer;
export 'src/chart/line/line_chart.dart' show LineChart;
export 'src/chart/line/line_renderer.dart' show LineRenderer;
export 'src/chart/line/line_renderer_config.dart' show LineRendererConfig;
export 'src/chart/pie/arc_renderer.dart' show ArcRenderer;
export 'src/chart/pie/arc_renderer_config.dart' show ArcRendererConfig;
export 'src/chart/pie/pie_chart.dart' show PieChart;
export 'src/chart/time_series/time_series_chart.dart' show TimeSeriesChart;
24 changes: 23 additions & 1 deletion charts_common/lib/src/chart/common/canvas_shapes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import 'dart:math' show Rectangle, min, max;
import 'dart:math' show Rectangle, min, max, Point;
import 'chart_canvas.dart' show FillPatternType;
import '../../common/color.dart' show Color;

Expand Down Expand Up @@ -89,3 +89,25 @@ class CanvasBarStack {
this.fullStackRect,
});
}

/// A list of [CanvasPieSlice]s to be painted by [ChartCanvas].
class CanvasPie {
final List<CanvasPieSlice> slices;
Point center;
double radius;
double innerRadius;
final Color stroke;
double strokeWidthPx;

CanvasPie(this.slices, this.center, this.radius, this.innerRadius,
{this.stroke, this.strokeWidthPx = 0.0});
}

/// A circle sector to be painted by [ChartCanvas].
class CanvasPieSlice {
double startAngle;
double endAngle;
Color fill;

CanvasPieSlice(this.startAngle, this.endAngle, {this.fill});
}
22 changes: 21 additions & 1 deletion charts_common/lib/src/chart/common/chart_canvas.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// limitations under the License.

import 'dart:math' show Point, Rectangle;
import 'canvas_shapes.dart' show CanvasBarStack;
import 'canvas_shapes.dart' show CanvasBarStack, CanvasPie;
import '../../common/color.dart' show Color;
import '../../common/text_element.dart' show TextElement;

Expand All @@ -23,6 +23,23 @@ abstract class ChartCanvas {
/// 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
Expand All @@ -38,6 +55,9 @@ abstract class ChartCanvas {
double strokeWidthPx,
List<int> dashPattern});

/// Renders a pie, with an optional hole in the center.
void drawPie(CanvasPie canvasPie);

/// Renders a simple point.
void drawPoint({Point point, Color fill, double radius});

Expand Down
Loading

0 comments on commit ca42618

Please sign in to comment.