| 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 part of charted.selection; | 9 part of charted.selection; |
| 10 | 10 |
| 11 /** SelectionScope represents a scope for all the data and DOM operations. */ | 11 /** SelectionScope represents a scope for all the data and DOM operations. */ |
| 12 class SelectionScope { | 12 class SelectionScope { |
| 13 Expando _associations = new Expando(); | 13 Expando _associations = new Expando(); |
| 14 Expando<Map<String, Pair<Function, bool>>> _listeners = new Expando(); | 14 Expando<Map<String, Pair<Function, bool>>> _listeners = new Expando(); |
| 15 Element _root; | 15 Element _root; |
| 16 | 16 |
| 17 /** Creates a new selection scope with document as the root. */ | 17 /** Creates a new selection scope with document as the root. */ |
| 18 SelectionScope() { | 18 SelectionScope() { |
| 19 _root = document.documentElement; | 19 _root = document.documentElement; |
| 20 } | 20 } |
| 21 | 21 |
| 22 /** | 22 /** |
| 23 * Creates a new selection scope with the first element matching | 23 * Creates a new selection scope with the first element matching |
| 24 * [selector] as the root. | 24 * [selector] as the root. |
| 25 */ | 25 */ |
| 26 SelectionScope.selector(String selector) { | 26 SelectionScope.selector(String selector) { |
| 27 if (selector == null || selector.isEmpty ){ | 27 if (selector == null || selector.isEmpty) { |
| 28 throw new ArgumentError('Selector cannot be empty'); | 28 throw new ArgumentError('Selector cannot be empty'); |
| 29 } | 29 } |
| 30 _root = document.querySelector(selector); | 30 _root = document.querySelector(selector); |
| 31 } | 31 } |
| 32 | 32 |
| 33 /** | 33 /** |
| 34 * Creates a new selection scope with the passed [element] as [root]. | 34 * Creates a new selection scope with the passed [element] as [root]. |
| 35 * Charted assumes that the element is already part of the DOM. | 35 * Charted assumes that the element is already part of the DOM. |
| 36 */ | 36 */ |
| 37 SelectionScope.element(Element element) { | 37 SelectionScope.element(Element element) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 67 */ | 67 */ |
| 68 Selection select(String selector) => | 68 Selection select(String selector) => |
| 69 new _SelectionImpl.single(selector: selector, scope: this); | 69 new _SelectionImpl.single(selector: selector, scope: this); |
| 70 | 70 |
| 71 /** | 71 /** |
| 72 * Creates a new [Selection] containing all elements matching [selector]. | 72 * Creates a new [Selection] containing all elements matching [selector]. |
| 73 * If no element matches, the resulting selection will not have any | 73 * If no element matches, the resulting selection will not have any |
| 74 * elements in it. | 74 * elements in it. |
| 75 */ | 75 */ |
| 76 Selection selectAll(String selector) => | 76 Selection selectAll(String selector) => |
| 77 new _SelectionImpl.all(selector:selector, scope:this); | 77 new _SelectionImpl.all(selector: selector, scope: this); |
| 78 | 78 |
| 79 /** | 79 /** |
| 80 * Creates a new [Selection] containing [elements]. Assumes that | 80 * Creates a new [Selection] containing [elements]. Assumes that |
| 81 * all the given elements are descendants of [root] in DOM. | 81 * all the given elements are descendants of [root] in DOM. |
| 82 */ | 82 */ |
| 83 Selection selectElements(List<Element> elements) => | 83 Selection selectElements(List<Element> elements) => |
| 84 new _SelectionImpl.elements(elements, this); | 84 new _SelectionImpl.elements(elements, this); |
| 85 | 85 |
| 86 /** | 86 /** |
| 87 * Appends a new element to [root] and creates a selection containing | 87 * Appends a new element to [root] and creates a selection containing |
| 88 * the newly added element. | 88 * the newly added element. |
| 89 */ | 89 */ |
| 90 Selection append(String tag) { | 90 Selection append(String tag) { |
| 91 var element = Namespace.createChildElement(tag, _root); | 91 var element = Namespace.createChildElement(tag, _root); |
| 92 root.children.add(element); | 92 root.children.add(element); |
| 93 | 93 |
| 94 return selectElements([element]); | 94 return selectElements([element]); |
| 95 } | 95 } |
| 96 } | 96 } |
| OLD | NEW |