| Index: packages/charted/lib/charts/data_transformers/aggregation_transformer.dart
|
| diff --git a/packages/charted/lib/charts/data_transformers/aggregation_transformer.dart b/packages/charted/lib/charts/data_transformers/aggregation_transformer.dart
|
| index 37db0b1a670f7eef3ebd0576a8c72c0a514db71b..7cd80285fa91d9180106606aecaf286c834fba78 100644
|
| --- a/packages/charted/lib/charts/data_transformers/aggregation_transformer.dart
|
| +++ b/packages/charted/lib/charts/data_transformers/aggregation_transformer.dart
|
| @@ -1,28 +1,25 @@
|
| -/*
|
| - * Copyright 2014 Google Inc. All rights reserved.
|
| - *
|
| - * Use of this source code is governed by a BSD-style
|
| - * license that can be found in the LICENSE file or at
|
| - * https://developers.google.com/open-source/licenses/bsd
|
| - */
|
| +//
|
| +// Copyright 2014 Google Inc. All rights reserved.
|
| +//
|
| +// Use of this source code is governed by a BSD-style
|
| +// license that can be found in the LICENSE file or at
|
| +// https://developers.google.com/open-source/licenses/bsd
|
| +//
|
|
|
| part of charted.charts;
|
|
|
| -/**
|
| - * Transforms the ChartData base on the specified dimension columns and facts
|
| - * columns indices. The values in the facts columns will be aggregated by the
|
| - * tree hierarchy generated by the dimension columns. Expand and Collapse
|
| - * methods may be called to display different levels of aggregation.
|
| - *
|
| - * The output ChartData produced by transform() will contain only columns in the
|
| - * original ChartData that were specified in dimensions or facts column indices.
|
| - * The output column will be re-ordered first by the indices specified in the
|
| - * dimension column indices then by the facts column indices. The data in the
|
| - * cells of each row will also follow this rule.
|
| - */
|
| +/// Transforms the ChartData based on the specified dimension columns and facts
|
| +/// columns indices. The values in the facts columns will be aggregated by the
|
| +/// tree hierarchy generated by the dimension columns. Expand and Collapse
|
| +/// methods may be called to display different levels of aggregation.
|
| +///
|
| +/// The output ChartData produced by transform() will contain only columns in the
|
| +/// original ChartData that were specified in dimensions or facts column indices.
|
| +/// The output column will be re-ordered first by the indices specified in the
|
| +/// dimension column indices then by the facts column indices. The data in the
|
| +/// cells of each row will also follow this rule.
|
| class AggregationTransformer extends ChangeNotifier
|
| implements ChartDataTransform, ChartData {
|
| -
|
| static const String AGGREGATION_TYPE_SUM = 'sum';
|
| static const String AGGREGATION_TYPE_MIN = 'min';
|
| static const String AGGREGATION_TYPE_MAX = 'max';
|
| @@ -40,16 +37,13 @@ class AggregationTransformer extends ChangeNotifier
|
| FieldAccessor _indexFieldAccessor = (List row, int index) => row[index];
|
| ChartData _data;
|
|
|
| - AggregationTransformer(this._dimensionColumnIndices,
|
| - this._factsColumnIndices,
|
| + AggregationTransformer(this._dimensionColumnIndices, this._factsColumnIndices,
|
| [String aggregationType = AGGREGATION_TYPE_SUM]) {
|
| _aggregationType = aggregationType;
|
| }
|
|
|
| - /**
|
| - * Transforms the ChartData base on the specified dimension columns and facts
|
| - * columns, aggregation type and currently expanded dimensions.
|
| - */
|
| + /// Transforms the ChartData base on the specified dimension columns and facts
|
| + /// columns, aggregation type and currently expanded dimensions.
|
| ChartData transform(ChartData data) {
|
| assert(data.columns.length > max(_dimensionColumnIndices));
|
| assert(data.columns.length > max(_factsColumnIndices));
|
| @@ -59,11 +53,11 @@ class AggregationTransformer extends ChangeNotifier
|
| return this;
|
| }
|
|
|
| - /** Registers listeners if data.rows or data.columns are Observable. */
|
| + /// Registers listeners if data.rows or data.columns are Observable.
|
| _registerListeners() {
|
| _dataSubscriptions.dispose();
|
|
|
| - if(_data is Observable) {
|
| + if (_data is Observable) {
|
| var observable = (_data as Observable);
|
| _dataSubscriptions.add(observable.changes.listen((records) {
|
| _transform();
|
| @@ -76,13 +70,12 @@ class AggregationTransformer extends ChangeNotifier
|
| }
|
| }
|
|
|
| - /**
|
| - * Performs the filter transform with _data. This is called on transform and
|
| - * onChange if the input ChartData is Observable.
|
| - */
|
| + /// Performs the filter transform with _data. This is called on transform and
|
| + /// onChange if the input ChartData is Observable.
|
| _transform() {
|
| - _model = new AggregationModel(_data.rows, _dimensionColumnIndices,
|
| - _factsColumnIndices, aggregationTypes: [_aggregationType],
|
| + _model = new AggregationModel(
|
| + _data.rows, _dimensionColumnIndices, _factsColumnIndices,
|
| + aggregationTypes: [_aggregationType],
|
| dimensionAccessor: _indexFieldAccessor,
|
| factsAccessor: _indexFieldAccessor);
|
| _model.compute();
|
| @@ -105,17 +98,15 @@ class AggregationTransformer extends ChangeNotifier
|
| rows.addAll(transformedRows);
|
|
|
| // Process columns.
|
| - columns = new List<ChartColumnSpec>.generate(_selectedColumns.length, (index) =>
|
| - _data.columns.elementAt(_selectedColumns[index]));
|
| + columns = new List<ChartColumnSpec>.generate(_selectedColumns.length,
|
| + (index) => _data.columns.elementAt(_selectedColumns[index]));
|
| }
|
|
|
| - /**
|
| - * Fills the aggregatedRows List with data base on the set of expanded values
|
| - * recursively. Currently when a dimension is expanded, rows are
|
| - * generated for its children but not for itself. If we want to change the
|
| - * logic to include itself, just move the expand check around the else clause
|
| - * and always write a row of data whether it's expanded or not.
|
| - */
|
| + /// Fills the aggregatedRows List with data base on the set of expanded values
|
| + /// recursively. Currently when a dimension is expanded, rows are
|
| + /// generated for its children but not for itself. If we want to change the
|
| + /// logic to include itself, just move the expand check around the else clause
|
| + /// and always write a row of data whether it's expanded or not.
|
| _generateAggregatedRow(List<Iterable> aggregatedRows, List dimensionValues) {
|
| var entity = _model.facts(dimensionValues);
|
| var dimensionLevel = dimensionValues.length - 1;
|
| @@ -125,7 +116,6 @@ class AggregationTransformer extends ChangeNotifier
|
| if (!_isExpanded(dimensionValues) ||
|
| dimensionValues.length == _dimensionColumnIndices.length) {
|
| aggregatedRows.add(new List.generate(_selectedColumns.length, (index) {
|
| -
|
| // Dimension column.
|
| if (index < _dimensionColumnIndices.length) {
|
| if (index < dimensionLevel) {
|
| @@ -152,10 +142,8 @@ class AggregationTransformer extends ChangeNotifier
|
| }
|
| }
|
|
|
| - /**
|
| - * Expands a specific dimension and optionally expands all of its parent
|
| - * dimensions.
|
| - */
|
| + /// Expands a specific dimension and optionally expands all of its parent
|
| + /// dimensions.
|
| void expand(List dimension, [bool expandParent = true]) {
|
| _expandAllDimension = false;
|
| _expandedSet.add(dimension);
|
| @@ -168,10 +156,8 @@ class AggregationTransformer extends ChangeNotifier
|
| }
|
| }
|
|
|
| - /**
|
| - * Collapses a specific dimension and optionally collapse all of its
|
| - * Children dimensions.
|
| - */
|
| + /// Collapses a specific dimension and optionally collapse all of its
|
| + /// Children dimensions.
|
| void collapse(List dimension, [bool collapseChildren = true]) {
|
| _expandAllDimension = false;
|
| if (collapseChildren) {
|
| @@ -189,7 +175,7 @@ class AggregationTransformer extends ChangeNotifier
|
| }
|
| }
|
|
|
| - /** Expands all dimensions. */
|
| + /// Expands all dimensions.
|
| void expandAll() {
|
| if (_model != null) {
|
| for (var value in _model.valuesForDimension(_dimensionColumnIndices[0])) {
|
| @@ -209,13 +195,13 @@ class AggregationTransformer extends ChangeNotifier
|
| }
|
| }
|
|
|
| - /** Collapses all dimensions. */
|
| + /// Collapses all dimensions.
|
| void collapseAll() {
|
| _expandAllDimension = false;
|
| _expandedSet.clear();
|
| }
|
|
|
| - /** Tests if specific dimension is expanded. */
|
| + /// Tests if specific dimension is expanded.
|
| bool _isExpanded(List dimension) {
|
| Function eq = const ListEquality().equals;
|
| return _expandedSet.any((e) => eq(e, dimension));
|
|
|