Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat($d3-ext) Select by string or d3.selection.
- Loading branch information
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* @fileOverview | ||
* Utility functions related to d3 selections. | ||
*/ | ||
define( | ||
function() { | ||
'use strict'; | ||
|
||
return { | ||
|
||
/** | ||
* Same as d3.select but allows a d3.selection as input too. | ||
* @param {d3.selection|string} selection | ||
*/ | ||
select: function(selection) { | ||
return (selection instanceof d3.selection) ? | ||
selection : | ||
d3.select(selection); | ||
} | ||
|
||
}; | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
define([ | ||
'd3-ext/util' | ||
], | ||
function(selection) { | ||
'use strict'; | ||
|
||
describe('d3-ext.selection', function() { | ||
|
||
beforeEach(function() { | ||
}); | ||
|
||
it('selects with a text selector', function() { | ||
var fixture = jasmine.htmlFixture(), | ||
sel = selection.select('#html-fixture'); | ||
expect(sel.node()).toBe(fixture.node()); | ||
}); | ||
|
||
it('selects with a d3 selection', function() { | ||
var fixture = jasmine.htmlFixture(), | ||
sel = selection.select(d3.select('#html-fixture')); | ||
expect(sel.node()).toBe(fixture.node()); | ||
}); | ||
|
||
it('selects with an DOM node', function() { | ||
var fixture = jasmine.htmlFixture(), | ||
sel = selection.select(fixture.node()); | ||
expect(sel.node()).toBe(fixture.node()); | ||
}); | ||
|
||
}); | ||
|
||
}); |