OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. All rights reserved. | 2 * Copyright 2014 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style | 4 * Use of this source code is governed by a BSD-style |
5 * license that can be found in the LICENSE file or at | 5 * license that can be found in the LICENSE file or at |
6 * https://developers.google.com/open-source/licenses/bsd | 6 * https://developers.google.com/open-source/licenses/bsd |
7 */ | 7 */ |
8 /* | 8 /* |
9 * TODO(prsd): Document library | 9 * TODO(prsd): Document library |
10 */ | 10 */ |
11 library charted.selection; | 11 library charted.selection; |
12 | 12 |
13 import "dart:html" show Element, Event, document; | 13 import "dart:html" show Element, Event, EventListener, document; |
14 import "dart:math" as math; | 14 import "dart:math" as math; |
15 import "package:charted/core/utils.dart"; | 15 import "package:charted/core/utils.dart"; |
16 import "package:charted/selection/transition.dart"; | 16 import "package:charted/selection/transition.dart"; |
17 | 17 |
18 part "selection_scope.dart"; | 18 part "selection_scope.dart"; |
19 part "src/selection_impl.dart"; | 19 part "src/selection_impl.dart"; |
20 | 20 |
21 /** | 21 /** |
22 * Callback to access key value from a given data object. During the process | 22 * Callback to access key value from a given data object. During the process |
23 * of binding data to Elements, the key values are used to match Elements | 23 * of binding data to Elements, the key values are used to match Elements |
24 * that have previously bound data | 24 * that have previously bound data |
25 */ | 25 */ |
26 typedef SelectionKeyFunction(datum); | 26 typedef SelectionKeyFunction(datum); |
27 | 27 |
28 /** | 28 /** |
29 * Callback for all DOM related operations - The first parameter [datum] is | 29 * Callback for all DOM related operations - The first parameter [datum] is |
30 * the piece of data associated with the node, [ei] is the index of the | 30 * the piece of data associated with the node, [ei] is the index of the |
31 * element in it's group and [c] is the context to which the data is | 31 * element in it's group and [c] is the context to which the data is |
32 * associated to. | 32 * associated to. |
33 */ | 33 */ |
34 typedef E SelectionCallback<E>(datum, int index, Element element); | 34 typedef E SelectionCallback<E>(datum, int index, Element element); |
35 | 35 |
36 /** Callback used to access a value from a datum */ | 36 /** Callback used to access a value from a datum */ |
37 typedef E SelectionValueAccessor<E>(datum, int index); | 37 typedef E SelectionValueAccessor<E>(datum, int index); |
38 | 38 |
39 /** Create a ChartedCallback that always returns [val] */ | 39 /** Create a ChartedCallback that always returns [val] */ |
40 SelectionCallback toCallback(val) => (datum, index, element) => val; | 40 SelectionCallback/*<T>*/ toCallback/*<T>*/(/*=T*/ val) => (datum, index, element
) => val; |
41 | 41 |
42 /** Create a ChartedValueAccessor that always returns [val] */ | 42 /** Create a ChartedValueAccessor that always returns [val] */ |
43 SelectionValueAccessor toValueAccessor(val) => (datum, index) => val; | 43 SelectionValueAccessor toValueAccessor(val) => (datum, index) => val; |
44 | 44 |
45 /** | 45 /** |
46 * [Selection] is a collection of elements - this collection defines | 46 * [Selection] is a collection of elements - this collection defines |
47 * operators that can be applied on all elements of the collection. | 47 * operators that can be applied on all elements of the collection. |
48 * | 48 * |
49 * All operators accept parameters either as a constant value or a callback | 49 * All operators accept parameters either as a constant value or a callback |
50 * function (typically using the named parameters "val" and "fn"). These | 50 * function (typically using the named parameters "val" and "fn"). These |
51 * operators, when invoked with the callback function, the function is | 51 * operators, when invoked with the callback function, the function is |
52 * called once per element and is passed the "data" associated, the "index" | 52 * called once per element and is passed the "data" associated, the "index" |
53 * and the element itself. | 53 * and the element itself. |
54 */ | 54 */ |
55 abstract class Selection { | 55 abstract class Selection { |
56 /** | 56 /** |
57 * Collection of groups - A selection when created by calling [selectAll] | 57 * Collection of groups - A selection when created by calling [selectAll] |
58 * on an existing [Selection], could contain more than one group. | 58 * on an existing [Selection], could contain more than one group. |
59 */ | 59 */ |
60 Iterable<SelectionGroup> groups; | 60 List<SelectionGroup> groups; |
61 | 61 |
62 /** | 62 /** |
63 * Scope of this selection that manages the element, data associations for | 63 * Scope of this selection that manages the element, data associations for |
64 * all elements in this selection (and the sub-selections) | 64 * all elements in this selection (and the sub-selections) |
65 */ | 65 */ |
66 SelectionScope get scope; | 66 SelectionScope get scope; |
67 | 67 |
68 /** Indicates if this selection is empty */ | 68 /** Indicates if this selection is empty */ |
69 bool get isEmpty; | 69 bool get isEmpty; |
70 | 70 |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 * applying instantaneously. | 285 * applying instantaneously. |
286 */ | 286 */ |
287 Transition transition(); | 287 Transition transition(); |
288 } | 288 } |
289 | 289 |
290 /* | 290 /* |
291 * Group of elements in the selection. | 291 * Group of elements in the selection. |
292 * Each selection may contain more than one group of elements. | 292 * Each selection may contain more than one group of elements. |
293 */ | 293 */ |
294 abstract class SelectionGroup { | 294 abstract class SelectionGroup { |
295 Iterable<Element> elements; | 295 List<Element> elements; |
296 Element parent; | 296 Element parent; |
297 } | 297 } |
298 | 298 |
299 /** | 299 /** |
300 * [EnterSelection] is a sub-selection that represents missing elements of a | 300 * [EnterSelection] is a sub-selection that represents missing elements of a |
301 * selection - an element is considered missing when there is data and no | 301 * selection - an element is considered missing when there is data and no |
302 * corresponding element in a selection. | 302 * corresponding element in a selection. |
303 */ | 303 */ |
304 abstract class EnterSelection { | 304 abstract class EnterSelection { |
305 /** | 305 /** |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 * elements which weren't associated with an element in the DOM. | 379 * elements which weren't associated with an element in the DOM. |
380 */ | 380 */ |
381 EnterSelection get enter; | 381 EnterSelection get enter; |
382 | 382 |
383 /** | 383 /** |
384 * A view of the current selection containing elements that don't have data | 384 * A view of the current selection containing elements that don't have data |
385 * associated with them. | 385 * associated with them. |
386 */ | 386 */ |
387 ExitSelection get exit; | 387 ExitSelection get exit; |
388 } | 388 } |
OLD | NEW |