mirror of
https://github.com/flutter/samples.git
synced 2026-04-29 02:56:02 +00:00
Web charts common update (#111)
This commit is contained in:
@@ -35,7 +35,7 @@ class LayoutConfig {
|
||||
/// Specs that applies to one margin.
|
||||
class MarginSpec {
|
||||
/// [MarginSpec] that has max of 50 percent.
|
||||
static const defaultSpec = const MarginSpec._internal(null, null, null, 50);
|
||||
static const defaultSpec = MarginSpec._internal(null, null, null, 50);
|
||||
|
||||
final int _minPixel;
|
||||
final int _maxPixel;
|
||||
@@ -64,7 +64,7 @@ class MarginSpec {
|
||||
assert(minPixel <= maxPixel);
|
||||
}
|
||||
|
||||
return new MarginSpec._internal(minPixel, maxPixel, null, null);
|
||||
return MarginSpec._internal(minPixel, maxPixel, null, null);
|
||||
}
|
||||
|
||||
/// Create [MarginSpec] with a fixed pixel size [pixels].
|
||||
@@ -74,7 +74,7 @@ class MarginSpec {
|
||||
// Require require or higher setting if set
|
||||
assert(pixels == null || pixels >= 0);
|
||||
|
||||
return new MarginSpec._internal(pixels, pixels, null, null);
|
||||
return MarginSpec._internal(pixels, pixels, null, null);
|
||||
}
|
||||
|
||||
/// Create [MarginSpec] that specifies min/max percentage.
|
||||
@@ -92,7 +92,7 @@ class MarginSpec {
|
||||
assert(minPercent <= maxPercent);
|
||||
}
|
||||
|
||||
return new MarginSpec._internal(null, null, minPercent, maxPercent);
|
||||
return MarginSpec._internal(null, null, minPercent, maxPercent);
|
||||
}
|
||||
|
||||
/// Get the min pixels, given the [totalPixels].
|
||||
|
||||
@@ -53,7 +53,7 @@ class LayoutManagerImpl implements LayoutManager {
|
||||
|
||||
/// Create a new [LayoutManager].
|
||||
LayoutManagerImpl({LayoutConfig config})
|
||||
: this.config = config ?? new LayoutConfig();
|
||||
: this.config = config ?? LayoutConfig();
|
||||
|
||||
/// Add one [LayoutView].
|
||||
void addView(LayoutView view) {
|
||||
@@ -79,9 +79,9 @@ class LayoutManagerImpl implements LayoutManager {
|
||||
@override
|
||||
List<LayoutView> get paintOrderedViews {
|
||||
if (_viewsNeedPaintSort) {
|
||||
_paintOrderedViews = new List<LayoutView>.from(_views);
|
||||
_paintOrderedViews = List<LayoutView>.from(_views);
|
||||
|
||||
_paintOrderedViews.sort((LayoutView v1, LayoutView v2) =>
|
||||
_paintOrderedViews.sort((v1, v2) =>
|
||||
v1.layoutConfig.paintOrder.compareTo(v2.layoutConfig.paintOrder));
|
||||
|
||||
_viewsNeedPaintSort = false;
|
||||
@@ -93,10 +93,9 @@ class LayoutManagerImpl implements LayoutManager {
|
||||
@override
|
||||
List<LayoutView> get positionOrderedViews {
|
||||
if (_viewsNeedPositionSort) {
|
||||
_positionOrderedViews = new List<LayoutView>.from(_views);
|
||||
_positionOrderedViews = List<LayoutView>.from(_views);
|
||||
|
||||
_positionOrderedViews.sort((LayoutView v1, LayoutView v2) => v1
|
||||
.layoutConfig.positionOrder
|
||||
_positionOrderedViews.sort((v1, v2) => v1.layoutConfig.positionOrder
|
||||
.compareTo(v2.layoutConfig.positionOrder));
|
||||
|
||||
_viewsNeedPositionSort = false;
|
||||
@@ -114,8 +113,7 @@ class LayoutManagerImpl implements LayoutManager {
|
||||
Rectangle<int> get drawableLayoutAreaBounds {
|
||||
assert(_drawAreaBoundsOutdated == false);
|
||||
|
||||
final drawableViews =
|
||||
_views.where((LayoutView view) => view.isSeriesRenderer);
|
||||
final drawableViews = _views.where((view) => view.isSeriesRenderer);
|
||||
|
||||
var componentBounds = drawableViews?.first?.componentBounds;
|
||||
|
||||
@@ -126,7 +124,7 @@ class LayoutManagerImpl implements LayoutManager {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
componentBounds = new Rectangle(0, 0, 0, 0);
|
||||
componentBounds = Rectangle(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
return componentBounds;
|
||||
@@ -226,8 +224,8 @@ class LayoutManagerImpl implements LayoutManager {
|
||||
);
|
||||
|
||||
// Bounds for the draw area.
|
||||
_drawAreaBounds = new Rectangle(measurements.leftWidth,
|
||||
measurements.topHeight, drawAreaWidth, drawAreaHeight);
|
||||
_drawAreaBounds = Rectangle(measurements.leftWidth, measurements.topHeight,
|
||||
drawAreaWidth, drawAreaHeight);
|
||||
_drawAreaBoundsOutdated = false;
|
||||
}
|
||||
|
||||
@@ -243,26 +241,26 @@ class LayoutManagerImpl implements LayoutManager {
|
||||
_viewsForPositions(LayoutPosition.Left, LayoutPosition.FullLeft);
|
||||
var drawAreaViews = _viewsForPositions(LayoutPosition.DrawArea);
|
||||
|
||||
final fullBounds = new Rectangle(0, 0, width, height);
|
||||
final fullBounds = Rectangle(0, 0, width, height);
|
||||
|
||||
// Layout the margins.
|
||||
new LeftMarginLayoutStrategy()
|
||||
LeftMarginLayoutStrategy()
|
||||
.layout(leftViews, _measurements.leftSizes, fullBounds, drawAreaBounds);
|
||||
new RightMarginLayoutStrategy().layout(
|
||||
RightMarginLayoutStrategy().layout(
|
||||
rightViews, _measurements.rightSizes, fullBounds, drawAreaBounds);
|
||||
new BottomMarginLayoutStrategy().layout(
|
||||
BottomMarginLayoutStrategy().layout(
|
||||
bottomViews, _measurements.bottomSizes, fullBounds, drawAreaBounds);
|
||||
new TopMarginLayoutStrategy()
|
||||
TopMarginLayoutStrategy()
|
||||
.layout(topViews, _measurements.topSizes, fullBounds, drawAreaBounds);
|
||||
|
||||
// Layout the drawArea.
|
||||
drawAreaViews.forEach(
|
||||
(LayoutView view) => view.layout(_drawAreaBounds, _drawAreaBounds));
|
||||
drawAreaViews
|
||||
.forEach((view) => view.layout(_drawAreaBounds, _drawAreaBounds));
|
||||
}
|
||||
|
||||
Iterable<LayoutView> _viewsForPositions(LayoutPosition p1,
|
||||
[LayoutPosition p2]) {
|
||||
return positionOrderedViews.where((LayoutView view) =>
|
||||
return positionOrderedViews.where((view) =>
|
||||
(view.layoutConfig.position == p1 ||
|
||||
(p2 != null && view.layoutConfig.position == p2)));
|
||||
}
|
||||
@@ -297,14 +295,14 @@ class LayoutManagerImpl implements LayoutManager {
|
||||
? height - bottomHeight - topHeight
|
||||
: height;
|
||||
|
||||
var leftSizes = new LeftMarginLayoutStrategy().measure(leftViews,
|
||||
var leftSizes = LeftMarginLayoutStrategy().measure(leftViews,
|
||||
maxWidth: useMax ? maxLeftWidth : leftWidth,
|
||||
height: adjustedHeight,
|
||||
fullHeight: height);
|
||||
|
||||
leftWidth = max(leftSizes.total, config.leftSpec.getMinPixels(width));
|
||||
|
||||
var rightSizes = new RightMarginLayoutStrategy().measure(rightViews,
|
||||
var rightSizes = RightMarginLayoutStrategy().measure(rightViews,
|
||||
maxWidth: useMax ? maxRightWidth : rightWidth,
|
||||
height: adjustedHeight,
|
||||
fullHeight: height);
|
||||
@@ -312,20 +310,20 @@ class LayoutManagerImpl implements LayoutManager {
|
||||
|
||||
final adjustedWidth = width - leftWidth - rightWidth;
|
||||
|
||||
var bottomSizes = new BottomMarginLayoutStrategy().measure(bottomViews,
|
||||
var bottomSizes = BottomMarginLayoutStrategy().measure(bottomViews,
|
||||
maxHeight: useMax ? maxBottomHeight : bottomHeight,
|
||||
width: adjustedWidth,
|
||||
fullWidth: width);
|
||||
bottomHeight =
|
||||
max(bottomSizes.total, config.bottomSpec.getMinPixels(height));
|
||||
|
||||
var topSizes = new TopMarginLayoutStrategy().measure(topViews,
|
||||
var topSizes = TopMarginLayoutStrategy().measure(topViews,
|
||||
maxHeight: useMax ? maxTopHeight : topHeight,
|
||||
width: adjustedWidth,
|
||||
fullWidth: width);
|
||||
topHeight = max(topSizes.total, config.topSpec.getMinPixels(height));
|
||||
|
||||
return new _MeasuredSizes(
|
||||
return _MeasuredSizes(
|
||||
leftWidth: leftWidth,
|
||||
leftSizes: leftSizes,
|
||||
rightWidth: rightWidth,
|
||||
|
||||
@@ -39,8 +39,8 @@ class SizeList {
|
||||
}
|
||||
|
||||
class _DesiredViewSizes {
|
||||
final preferredSizes = new SizeList();
|
||||
final minimumSizes = new SizeList();
|
||||
final preferredSizes = SizeList();
|
||||
final minimumSizes = SizeList();
|
||||
|
||||
void add(int preferred, int minimum) {
|
||||
preferredSizes.add(preferred);
|
||||
@@ -74,10 +74,10 @@ abstract class VerticalMarginStrategy {
|
||||
{@required int maxWidth,
|
||||
@required int height,
|
||||
@required int fullHeight}) {
|
||||
final measuredWidths = new _DesiredViewSizes();
|
||||
final measuredWidths = _DesiredViewSizes();
|
||||
int remainingWidth = maxWidth;
|
||||
|
||||
views.forEach((LayoutView view) {
|
||||
views.forEach((view) {
|
||||
final params = view.layoutConfig;
|
||||
final viewMargin = params.viewMargin;
|
||||
|
||||
@@ -118,7 +118,7 @@ class LeftMarginLayoutStrategy extends VerticalMarginStrategy {
|
||||
var prevBoundsRight = drawAreaBounds.left;
|
||||
|
||||
int i = 0;
|
||||
views.forEach((LayoutView view) {
|
||||
views.forEach((view) {
|
||||
final params = view.layoutConfig;
|
||||
|
||||
final width = measuredSizes[i];
|
||||
@@ -133,7 +133,7 @@ class LeftMarginLayoutStrategy extends VerticalMarginStrategy {
|
||||
prevBoundsRight = left - params.viewMargin.leftPx;
|
||||
|
||||
// Layout this component.
|
||||
view.layout(new Rectangle(left, top, width, height), drawAreaBounds);
|
||||
view.layout(Rectangle(left, top, width, height), drawAreaBounds);
|
||||
|
||||
i++;
|
||||
});
|
||||
@@ -148,7 +148,7 @@ class RightMarginLayoutStrategy extends VerticalMarginStrategy {
|
||||
var prevBoundsLeft = drawAreaBounds.right;
|
||||
|
||||
int i = 0;
|
||||
views.forEach((LayoutView view) {
|
||||
views.forEach((view) {
|
||||
final params = view.layoutConfig;
|
||||
|
||||
final width = measuredSizes[i];
|
||||
@@ -163,7 +163,7 @@ class RightMarginLayoutStrategy extends VerticalMarginStrategy {
|
||||
prevBoundsLeft = left + width + params.viewMargin.rightPx;
|
||||
|
||||
// Layout this component.
|
||||
view.layout(new Rectangle(left, top, width, height), drawAreaBounds);
|
||||
view.layout(Rectangle(left, top, width, height), drawAreaBounds);
|
||||
|
||||
i++;
|
||||
});
|
||||
@@ -174,10 +174,10 @@ class RightMarginLayoutStrategy extends VerticalMarginStrategy {
|
||||
abstract class HorizontalMarginStrategy {
|
||||
SizeList measure(Iterable<LayoutView> views,
|
||||
{@required int maxHeight, @required int width, @required int fullWidth}) {
|
||||
final measuredHeights = new _DesiredViewSizes();
|
||||
final measuredHeights = _DesiredViewSizes();
|
||||
int remainingHeight = maxHeight;
|
||||
|
||||
views.forEach((LayoutView view) {
|
||||
views.forEach((view) {
|
||||
final params = view.layoutConfig;
|
||||
final viewMargin = params.viewMargin;
|
||||
|
||||
@@ -218,7 +218,7 @@ class TopMarginLayoutStrategy extends HorizontalMarginStrategy {
|
||||
var prevBoundsBottom = drawAreaBounds.top;
|
||||
|
||||
int i = 0;
|
||||
views.forEach((LayoutView view) {
|
||||
views.forEach((view) {
|
||||
final params = view.layoutConfig;
|
||||
|
||||
final height = measuredSizes[i];
|
||||
@@ -234,7 +234,7 @@ class TopMarginLayoutStrategy extends HorizontalMarginStrategy {
|
||||
prevBoundsBottom = top - params.viewMargin.topPx;
|
||||
|
||||
// Layout this component.
|
||||
view.layout(new Rectangle(left, top, width, height), drawAreaBounds);
|
||||
view.layout(Rectangle(left, top, width, height), drawAreaBounds);
|
||||
|
||||
i++;
|
||||
});
|
||||
@@ -249,7 +249,7 @@ class BottomMarginLayoutStrategy extends HorizontalMarginStrategy {
|
||||
var prevBoundsTop = drawAreaBounds.bottom;
|
||||
|
||||
int i = 0;
|
||||
views.forEach((LayoutView view) {
|
||||
views.forEach((view) {
|
||||
final params = view.layoutConfig;
|
||||
|
||||
final height = measuredSizes[i];
|
||||
@@ -265,7 +265,7 @@ class BottomMarginLayoutStrategy extends HorizontalMarginStrategy {
|
||||
prevBoundsTop = top + height + params.viewMargin.bottomPx;
|
||||
|
||||
// Layout this component.
|
||||
view.layout(new Rectangle(left, top, width, height), drawAreaBounds);
|
||||
view.layout(Rectangle(left, top, width, height), drawAreaBounds);
|
||||
|
||||
i++;
|
||||
});
|
||||
|
||||
@@ -80,8 +80,7 @@ class LayoutViewPositionOrder {
|
||||
/// A configuration for margin (empty space) around a layout child view.
|
||||
class ViewMargin {
|
||||
/// A [ViewMargin] with all zero px.
|
||||
static const empty =
|
||||
const ViewMargin(topPx: 0, bottomPx: 0, rightPx: 0, leftPx: 0);
|
||||
static const empty = ViewMargin(topPx: 0, bottomPx: 0, rightPx: 0, leftPx: 0);
|
||||
|
||||
final int topPx;
|
||||
final int bottomPx;
|
||||
@@ -152,7 +151,7 @@ class LayoutViewConfig {
|
||||
/// The measurement is tight to the component, without adding [ComponentBuffer].
|
||||
class ViewMeasuredSizes {
|
||||
/// All zeroes component size.
|
||||
static const zero = const ViewMeasuredSizes(
|
||||
static const zero = ViewMeasuredSizes(
|
||||
preferredWidth: 0, preferredHeight: 0, minWidth: 0, minHeight: 0);
|
||||
|
||||
final int preferredWidth;
|
||||
|
||||
Reference in New Issue
Block a user