Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
GitHub Sync (#43)
Browse files Browse the repository at this point in the history
* Add TickProviderSpec for customizing a time axis to choose day only
ticks.

PiperOrigin-RevId: 192329050

* Dart 2 type fix for pan and zoom behavior. Pan and zoom behavior was
not working because the desired gesture types were mismatched.

PiperOrigin-RevId: 192344097

* Fix domain axis ticks not updating during panning.

PiperOrigin-RevId: 192453843

* Internal changes.

PiperOrigin-RevId: 192477572

* Dart 2 type fix for pan behavior. Pan behavior was not
working because the desired gesture types were mismatched.

PiperOrigin-RevId: 192785752

* Add Travis and Pub badges to readme

Closes #42

PiperOrigin-RevId: 193047177
  • Loading branch information
cbbraun committed Apr 16, 2018
1 parent 60a1f40 commit 9f11e31
Show file tree
Hide file tree
Showing 19 changed files with 458 additions and 172 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@ Charts is a general charting library, currently enabled for the

*Note*: This is not an official Google product.

[![Travis CI Build Status](https://travis-ci.org/google/charts.svg?branch=master)](https://travis-ci.org/google/charts)

## charts_common

[![charts_common pub package](https://img.shields.io/pub/v/charts_common.svg)](https://pub.dartlang.org/packages/charts_common)

A common library for charting packages.

## charts_flutter

[![charts_flutter pub package](https://img.shields.io/pub/v/charts_flutter.svg)](https://pub.dartlang.org/packages/charts_flutter)

A charting package for [Flutter](https://flutter.io), supporting both Android
and iOS.

Expand Down
12 changes: 9 additions & 3 deletions charts_common/lib/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,16 @@ export 'src/chart/common/behavior/a11y/a11y_explore_behavior.dart'
export 'src/chart/common/behavior/a11y/a11y_node.dart' show A11yNode;
export 'src/chart/common/behavior/a11y/domain_a11y_explore_behavior.dart'
show DomainA11yExploreBehavior, VocalizationCallback;
export 'src/chart/common/behavior/chart_behavior.dart' show ChartBehavior;
export 'src/chart/common/behavior/chart_behavior.dart'
show
BehaviorPosition,
ChartBehavior,
InsideJustification,
OutsideJustification;
export 'src/chart/common/behavior/domain_highlighter.dart'
show DomainHighlighter;
export 'src/chart/common/behavior/legend/legend.dart'
show SeriesLegend, LegendState;
show LegendCellPadding, LegendState, SeriesLegend;
export 'src/chart/common/behavior/legend/legend_entry.dart' show LegendEntry;
export 'src/chart/common/behavior/line_point_highlighter.dart'
show LinePointHighlighter;
Expand All @@ -59,7 +64,8 @@ export 'src/chart/common/series_renderer.dart' show SeriesRenderer, rendererKey;
export 'src/chart/common/series_renderer_config.dart'
show RendererAttributeKey, SeriesRendererConfig;
export 'src/chart/layout/layout_config.dart' show LayoutConfig, MarginSpec;
export 'src/chart/layout/layout_view.dart' show LayoutPosition, ViewMargin;
export 'src/chart/layout/layout_view.dart'
show LayoutPosition, ViewMargin, ViewMeasuredSizes;
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;
Expand Down
22 changes: 16 additions & 6 deletions charts_common/lib/src/chart/cartesian/axis/axis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,14 @@ abstract class Axis<D, E extends Extents, S extends MutableScale<D, E>>
_scale.range = new ScaleOutputExtent(start, end);
}

/// Request update ticks from tick provider and update the painted ticks.
void updateTicks() {
_updateProvidedTicks();
_updateAxisTicks();
}

/// Request ticks from tick provider.
void updateProvidedTicks() {
void _updateProvidedTicks() {
if (lockAxis || updateTickLocationOnly) {
return;
}
Expand All @@ -206,7 +212,11 @@ abstract class Axis<D, E extends Extents, S extends MutableScale<D, E>>
}

/// Updates the ticks that are actually used for drawing.
void updateAxisTicks() {
void _updateAxisTicks() {
if (lockAxis) {
return;
}

final providedTicks = new List.from(_providedTicks ?? []);

for (AxisTicks<D> animatedTick in _axisTicks) {
Expand Down Expand Up @@ -346,15 +356,15 @@ abstract class Axis<D, E extends Extents, S extends MutableScale<D, E>>

ViewMeasuredSizes _measureVerticalAxis(int maxWidth, int maxHeight) {
setOutputRange(maxHeight, 0);
updateProvidedTicks();
_updateProvidedTicks();

return tickDrawStrategy.measureVerticallyDrawnTicks(
_providedTicks, maxWidth, maxHeight);
}

ViewMeasuredSizes _measureHorizontalAxis(int maxWidth, int maxHeight) {
setOutputRange(0, maxWidth);
updateProvidedTicks();
_updateProvidedTicks();

return tickDrawStrategy.measureHorizontallyDrawnTicks(
_providedTicks, maxWidth, maxHeight);
Expand Down Expand Up @@ -383,10 +393,10 @@ abstract class Axis<D, E extends Extents, S extends MutableScale<D, E>>
if (_scale.range != outputRange) {
_scale.range = outputRange;
}
updateProvidedTicks();
_updateProvidedTicks();
// Update animated ticks in layout, because updateTicks are called during
// measure and we don't want to update the animation at that time.
updateAxisTicks();
_updateAxisTicks();
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import '../../../common/chart_context.dart' show ChartContext;
import '../static_tick_provider.dart' show StaticTickProvider;
import '../time/auto_adjusting_date_time_tick_provider.dart'
show AutoAdjustingDateTimeTickProvider;
import '../time/time_range_tick_provider_impl.dart'
show TimeRangeTickProviderImpl;
import '../time/day_time_stepper.dart' show DayTimeStepper;
import '../time/date_time_tick_formatter.dart' show DateTimeTickFormatter;
import '../time/hour_tick_formatter.dart' show HourTickFormatter;
import '../time/time_tick_formatter.dart' show TimeTickFormatter;
Expand Down Expand Up @@ -98,6 +101,26 @@ class AutoDateTimeTickProviderSpec implements DateTimeTickProviderSpec {
int get hashCode => includeTime?.hashCode ?? 0;
}

/// [TickProviderSpec] that sets up time ticks with days increments only.
@immutable
class DayTickProviderSpec implements DateTimeTickProviderSpec {
final List<int> increments;
DayTickProviderSpec({this.increments});

/// Creates a [TickProviderSpec] that dynamically chooses ticks based on the
/// extents of the data, limited to day increments.
///
/// [increments] specify the number of day increments that can be chosen from
/// when searching for the appropriate tick intervals.
@override
AutoAdjustingDateTimeTickProvider createTickProvider(ChartContext context) {
return new AutoAdjustingDateTimeTickProvider.createWith([
new TimeRangeTickProviderImpl(new DayTimeStepper(context.dateTimeFactory,
allowedTickIncrements: increments))
]);
}
}

/// [TickProviderSpec] that allows you to specific the ticks to be used.
@immutable
class StaticDateTimeTickProviderSpec implements DateTimeTickProviderSpec {
Expand Down
6 changes: 3 additions & 3 deletions charts_common/lib/src/chart/cartesian/cartesian_chart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,13 @@ abstract class CartesianChart<T, D> extends BaseChart<T, D> {
@override
void onSkipLayout() {
// Update ticks only when skipping layout.
domainAxis.updateProvidedTicks();
domainAxis.updateTicks();

if (_usePrimaryMeasureAxis) {
_primaryMeasureAxis.updateProvidedTicks();
_primaryMeasureAxis.updateTicks();
}
if (_useSecondaryMeasureAxis) {
_secondaryMeasureAxis.updateProvidedTicks();
_secondaryMeasureAxis.updateTicks();
}

super.onSkipLayout();
Expand Down
35 changes: 35 additions & 0 deletions charts_common/lib/src/chart/common/behavior/chart_behavior.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,38 @@ abstract class ChartBehavior<T, D> {
/// Removes the behavior from a chart.
void removeFrom(BaseChart<T, D> chart);
}

/// Position of a component within the chart layout.
///
/// Outside positions are [top], [bottom], [start], and [end].
///
/// [top] component positioned at the top, with the chart positioned below the
/// component and height reduced by the height of the component.
/// [bottom] component positioned below the chart, and the chart's height is
/// reduced by the height of the component.
/// [start] component is positioned at the left of the chart (or the right if
/// RTL), the chart's width is reduced by the width of the component.
/// [end] component is positioned at the right of the chart (or the left if
/// RTL), the chart's width is reduced by the width of the component.
/// [inside] component is layered on top of the chart.
enum BehaviorPosition {
top,
bottom,
start,
end,
inside,
}

/// Justification for components positioned outside [BehaviorPosition].
enum OutsideJustification {
startDrawArea,
start,
endDrawArea,
end,
}

/// Justification for components positioned [BehaviorPosition.inside].
enum InsideJustification {
topStart,
topEnd,
}
Loading

0 comments on commit 9f11e31

Please sign in to comment.