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

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

Issue 2213693002: Updated charted DEP to 0.4.X (Closed) Base URL: https://github.com/dart-lang/observatory_pub_packages.git@master
Patch Set: Created 4 years, 4 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 345d537d28bd8bec46a980ff09b6ae2e147edc75..4a684b3f97b7a8dbb5d140730b7b364857538dfb 100644
--- a/packages/charted/lib/charts/src/chart_axis_impl.dart
+++ b/packages/charted/lib/charts/src/chart_axis_impl.dart
@@ -83,17 +83,16 @@ class DefaultChartAxisImpl {
: new MutableRect.size(layout.height, _theme.horizontalAxisHeight);
// Handle auto re-sizing of horizontal axis.
+ var ticks = (_config != null && !isNullOrEmpty(_config.tickValues))
+ ? _config.tickValues
+ : scale.ticks,
+ formatter = _columnSpec.formatter == null
+ ? scale.createTickFormatter()
+ : _columnSpec.formatter,
+ textMetrics = new TextMetrics(fontStyle: _theme.ticksFont),
+ formattedTicks = ticks.map((x) => formatter(x)).toList(),
+ shortenedTicks = formattedTicks;
if (_isVertical) {
- var ticks = (_config != null && !isNullOrEmpty(_config.tickValues))
- ? _config.tickValues
- : scale.ticks,
- formatter = _columnSpec.formatter == null
- ? scale.createTickFormatter()
- : _columnSpec.formatter,
- textMetrics = new TextMetrics(fontStyle: _theme.ticksFont),
- formattedTicks = ticks.map((x) => formatter(x)).toList(),
- shortenedTicks = formattedTicks;
-
var width = textMetrics.getLongestTextWidth(formattedTicks).ceil();
if (width > _theme.verticalAxisWidth) {
width = _theme.verticalAxisWidth;
@@ -105,8 +104,20 @@ class DefaultChartAxisImpl {
size.width =
width + _theme.axisTickPadding + math.max(_theme.axisTickSize, 0);
}
+
_axisTicksPlacement =
new PrecomputedAxisTicks(ticks, formattedTicks, shortenedTicks);
+ } else {
+ // Precompute if extra room is needed for rotated label.
+ var width = layout.width -
+ _area.layout.axes[ORIENTATION_LEFT].width -
+ _area.layout.axes[ORIENTATION_RIGHT].width;
+ var allowedWidth = width ~/ ticks.length,
+ maxLabelWidth = textMetrics.getLongestTextWidth(formattedTicks);
+ if (!RotateHorizontalAxisTicks.needsLabelRotation(
+ allowedWidth, maxLabelWidth)) {
+ size.height = textMetrics.fontSize * 2;
+ }
}
}
@@ -151,7 +162,9 @@ class DefaultChartAxisImpl {
Scale get scale =>
(_config != null && _config.scale != null) ? _config.scale : _scale;
- set scale(Scale value) => _scale = value;
+ set scale(Scale value) {
+ _scale = value;
+ }
}
class PrecomputedAxisTicks implements SvgAxisTicks {
@@ -171,11 +184,14 @@ class RotateHorizontalAxisTicks implements SvgAxisTicks {
int rotation = 0;
Iterable ticks;
- Iterable formattedTicks;
+ Iterable<String> formattedTicks;
Iterable shortenedTicks;
RotateHorizontalAxisTicks(this.rect, this.ticksFont, this.tickLineLength);
+ static bool needsLabelRotation(num allowedWidth, num maxLabelWidth) =>
+ 0.90 * allowedWidth < maxLabelWidth;
+
void init(SvgAxis axis) {
assert(axis.orientation == ORIENTATION_BOTTOM ||
axis.orientation == ORIENTATION_TOP);
@@ -190,7 +206,7 @@ class RotateHorizontalAxisTicks implements SvgAxisTicks {
maxLabelWidth = textMetrics.getLongestTextWidth(formattedTicks);
// Check if we need rotation
- if (0.90 * allowedWidth < maxLabelWidth) {
+ if (needsLabelRotation(allowedWidth, maxLabelWidth)) {
var rectHeight =
tickLineLength > 0 ? rect.height - tickLineLength : rect.height;
rotation = 45;
« 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