Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(547)

Unified Diff: packages/charted/lib/charts/src/chart_axis_impl.dart

Issue 2989763002: Update charted to 0.4.8 and roll (Closed)
Patch Set: Removed Cutch from list of reviewers Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: packages/charted/lib/charts/src/chart_axis_impl.dart
diff --git a/packages/charted/lib/charts/src/chart_axis_impl.dart b/packages/charted/lib/charts/src/chart_axis_impl.dart
index 4a684b3f97b7a8dbb5d140730b7b364857538dfb..caf48eb4daf6762f7decc58fac3344b5b1f325c8 100644
--- a/packages/charted/lib/charts/src/chart_axis_impl.dart
+++ b/packages/charted/lib/charts/src/chart_axis_impl.dart
@@ -9,8 +9,10 @@
part of charted.charts;
class DefaultChartAxisImpl {
+ static const int _AXIS_TITLE_HEIGHT = 20;
+
CartesianArea _area;
- ChartAxisConfig _config;
+ ChartAxisConfig config;
ChartAxisTheme _theme;
SvgAxisTicks _axisTicksPlacement;
@@ -22,10 +24,11 @@ class DefaultChartAxisImpl {
String _orientation;
Scale _scale;
SelectionScope _scope;
+ String _title;
MutableRect size;
- DefaultChartAxisImpl.withAxisConfig(this._area, this._config);
+ DefaultChartAxisImpl.withAxisConfig(this._area, this.config);
DefaultChartAxisImpl(this._area);
void initAxisDomain(int column, bool isDimension, Iterable domain) {
@@ -44,10 +47,13 @@ class DefaultChartAxisImpl {
: _area.theme.getMeasureAxisTheme(scale);
// Sets the domain if not using a custom scale.
- if (_config == null || (_config != null && _config.scale == null)) {
+ if (config == null || (config != null && config.scale == null)) {
scale.domain = domain;
- scale.nice = !_isDimension;
+ scale.nice = !_isDimension &&
+ !(config?.forcedTicksCount != null && config.forcedTicksCount > 0);
}
+
+ _title = config?.title;
}
void initAxisScale(Iterable range) {
@@ -63,10 +69,20 @@ class DefaultChartAxisImpl {
if (_area.config.isLeftAxisPrimary) {
range = range.toList().reversed;
}
- (scale as OrdinalScale)
- .rangeRoundBands(range, innerPadding, outerPadding);
+ if (usingBands) {
+ (scale as OrdinalScale)
+ .rangeRoundBands(range, innerPadding, outerPadding);
+ } else {
+ (scale as OrdinalScale).rangePoints(range, outerPadding);
+ }
} else {
- scale.range = range;
+ if (_title != null) {
+ var modifiedRange = range.take(range.length - 1).toList();
+ modifiedRange.add(range.last + _AXIS_TITLE_HEIGHT);
+ scale.range = modifiedRange;
+ } else {
+ scale.range = range;
+ }
scale.ticksCount = _theme.axisTickCount;
}
}
@@ -82,10 +98,15 @@ class DefaultChartAxisImpl {
? new MutableRect.size(_theme.verticalAxisWidth, layout.width)
: new MutableRect.size(layout.height, _theme.horizontalAxisHeight);
+ if (config?.forcedTicksCount != null && config.forcedTicksCount > 0) {
+ scale.forcedTicksCount = config.forcedTicksCount;
+ }
+
// Handle auto re-sizing of horizontal axis.
- var ticks = (_config != null && !isNullOrEmpty(_config.tickValues))
- ? _config.tickValues
+ var ticks = (config != null && !isNullOrEmpty(config.tickValues))
+ ? config.tickValues
: scale.ticks,
+
formatter = _columnSpec.formatter == null
? scale.createTickFormatter()
: _columnSpec.formatter,
@@ -131,8 +152,8 @@ class DefaultChartAxisImpl {
innerTickSize = _theme.axisTickSize <= ChartAxisTheme.FILL_RENDER_AREA
? 0 - (_isVertical ? renderAreaRect.width : renderAreaRect.height)
: _theme.axisTickSize,
- tickValues = _config != null && !isNullOrEmpty(_config.tickValues)
- ? _config.tickValues
+ tickValues = config != null && !isNullOrEmpty(config.tickValues)
+ ? config.tickValues
: null;
element.attributes['transform'] = 'translate(${rect.x}, ${rect.y})';
@@ -141,8 +162,21 @@ class DefaultChartAxisImpl {
_axisTicksPlacement = new RotateHorizontalAxisTicks(
rect, _theme.ticksFont, _theme.axisTickSize + _theme.axisTickPadding);
}
-
initAxisScale(range);
+
+ if (_title != null) {
+ var label = element.querySelector('.chart-axis-label');
+ if (label != null) {
+ label.text = _title;
+ } else {
+ var title = Namespace.createChildElement('text', element);
+ title.attributes['text-anchor'] = 'middle';
+ title.text = _title;
+ title.classes.add('chart-axis-label');
+ element.append(title);
+ }
+ }
+
var axis = new SvgAxis(
orientation: _orientation,
innerTickSize: innerTickSize,
@@ -160,11 +194,12 @@ class DefaultChartAxisImpl {
// Scale passed through configuration takes precedence
Scale get scale =>
- (_config != null && _config.scale != null) ? _config.scale : _scale;
+ (config != null && config.scale != null) ? config.scale : _scale;
set scale(Scale value) {
_scale = value;
}
+
}
class PrecomputedAxisTicks implements SvgAxisTicks {
« no previous file with comments | « packages/charted/lib/charts/src/cartesian_area_impl.dart ('k') | packages/charted/lib/charts/src/chart_config_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698