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

Unified Diff: charted/lib/charts/data_transformers/filter_transformer.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 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: charted/lib/charts/data_transformers/filter_transformer.dart
diff --git a/charted/lib/charts/data_transformers/filter_transformer.dart b/charted/lib/charts/data_transformers/filter_transformer.dart
deleted file mode 100644
index 393c453f6fbb85dba29b18ae610b29ad110c5c7a..0000000000000000000000000000000000000000
--- a/charted/lib/charts/data_transformers/filter_transformer.dart
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * 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;
-
-typedef bool FilterFunction(dynamic value);
-
-/**
- * Transforms the ChartData base on the specified FilterDefinitions. Each row
- * of data will be tested by passing the value at target column to the filter
- * function. If filter function returns false, the row will be filtered out.
- * This transformer does not modify the column part of the input ChartData.
- */
-class FilterTransformer extends ChangeNotifier
- implements ChartDataTransform, ChartData {
- final SubscriptionsDisposer _dataSubscriptions = new SubscriptionsDisposer();
- Iterable<ChartColumnSpec> columns;
- ObservableList<Iterable> rows = new ObservableList();
- List<FilterDefinition> filterFunctions;
- ChartData _data;
-
- FilterTransformer(this.filterFunctions);
-
- /**
- * Transforms the input data with the list of [FilterDefinition] specified in
- * the constructor. If the rows and columns are ObservableList in the data,
- * changes in rows and columns in input data will trigger transform to be
- * performed again to update the output rows and columns.
- */
- ChartData transform(ChartData data) {
- _data = data;
- _registerListeners();
- _transform();
- return this;
- }
-
- /** Registers listeners if data.rows or data.columns are Observable. */
- _registerListeners() {
- _dataSubscriptions.dispose();
-
- if(_data is Observable) {
- var observable = (_data as Observable);
- _dataSubscriptions.add(observable.changes.listen((records) {
- _transform();
-
- // NOTE: Currently we're only passing the first change because the chart
- // area just draw with the updated data. When we add partial update
- // to chart area, we'll need to handle this better.
- notifyChange(records.first);
- }));
- }
- }
-
- /**
- * Performs the filter transform with _data. This is called on transform and
- * onChange if the input ChartData is Observable.
- */
- _transform() {
- columns = _data.columns;
- rows.clear();
-
- for (var row in _data.rows) {
- // Add the row if each value in target column passes the filter function.
- if (filterFunctions.every((e) =>
- e.filterFunc(row.elementAt(e.targetColumn)))) {
- rows.add(row);
- }
- }
- }
-}
-
-class FilterDefinition {
- final FilterFunction filterFunc;
- final int targetColumn;
- FilterDefinition(this.targetColumn, this.filterFunc);
-}

Powered by Google App Engine
This is Rietveld 408576698