@@ -484,7 +484,7 @@ d3 = function() {
484484 var d3_selectionPrototype = d3 . selection . prototype = [ ] ;
485485 d3_selectionPrototype . select = function ( selector ) {
486486 var subgroups = [ ] , subgroup , subnode , group , node ;
487- if ( typeof selector !== "function" ) selector = d3_selection_selector ( selector ) ;
487+ selector = d3_selection_selector ( selector ) ;
488488 for ( var j = - 1 , m = this . length ; ++ j < m ; ) {
489489 subgroups . push ( subgroup = [ ] ) ;
490490 subgroup . parentNode = ( group = this [ j ] ) . parentNode ;
@@ -500,13 +500,13 @@ d3 = function() {
500500 return d3_selection ( subgroups ) ;
501501 } ;
502502 function d3_selection_selector ( selector ) {
503- return function ( ) {
503+ return typeof selector === "function" ? selector : function ( ) {
504504 return d3_select ( selector , this ) ;
505505 } ;
506506 }
507507 d3_selectionPrototype . selectAll = function ( selector ) {
508508 var subgroups = [ ] , subgroup , node ;
509- if ( typeof selector !== "function" ) selector = d3_selection_selectorAll ( selector ) ;
509+ selector = d3_selection_selectorAll ( selector ) ;
510510 for ( var j = - 1 , m = this . length ; ++ j < m ; ) {
511511 for ( var group = this [ j ] , i = - 1 , n = group . length ; ++ i < n ; ) {
512512 if ( node = group [ i ] ) {
@@ -518,7 +518,7 @@ d3 = function() {
518518 return d3_selection ( subgroups ) ;
519519 } ;
520520 function d3_selection_selectorAll ( selector ) {
521- return function ( ) {
521+ return typeof selector === "function" ? selector : function ( ) {
522522 return d3_selectAll ( selector , this ) ;
523523 } ;
524524 }
@@ -696,25 +696,24 @@ d3 = function() {
696696 } ) : this . node ( ) . innerHTML ;
697697 } ;
698698 d3_selectionPrototype . append = function ( name ) {
699- name = d3 . ns . qualify ( name ) ;
700- function append ( ) {
701- return this . appendChild ( d3_document . createElementNS ( this . namespaceURI , name ) ) ;
702- }
703- function appendNS ( ) {
704- return this . appendChild ( d3_document . createElementNS ( name . space , name . local ) ) ;
705- }
706- return this . select ( name . local ? appendNS : append ) ;
699+ name = d3_selection_creator ( name ) ;
700+ return this . select ( function ( ) {
701+ return this . appendChild ( name . apply ( this , arguments ) ) ;
702+ } ) ;
707703 } ;
704+ function d3_selection_creator ( name ) {
705+ return typeof name === "function" ? name : ( name = d3 . ns . qualify ( name ) ) . local ? function ( ) {
706+ return d3_document . createElementNS ( name . space , name . local ) ;
707+ } : function ( ) {
708+ return d3_document . createElementNS ( this . namespaceURI , name ) ;
709+ } ;
710+ }
708711 d3_selectionPrototype . insert = function ( name , before ) {
709- name = d3 . ns . qualify ( name ) ;
710- if ( typeof before !== "function" ) before = d3_selection_selector ( before ) ;
711- function insert ( d , i ) {
712- return this . insertBefore ( d3_document . createElementNS ( this . namespaceURI , name ) , before . call ( this , d , i ) ) ;
713- }
714- function insertNS ( d , i ) {
715- return this . insertBefore ( d3_document . createElementNS ( name . space , name . local ) , before . call ( this , d , i ) ) ;
716- }
717- return this . select ( name . local ? insertNS : insert ) ;
712+ name = d3_selection_creator ( name ) ;
713+ before = d3_selection_selector ( before ) ;
714+ return this . select ( function ( ) {
715+ return this . insertBefore ( name . apply ( this , arguments ) , before . apply ( this , arguments ) ) ;
716+ } ) ;
718717 } ;
719718 d3_selectionPrototype . remove = function ( ) {
720719 return this . each ( function ( ) {
@@ -7444,7 +7443,7 @@ d3 = function() {
74447443 d3 . transition . prototype = d3_transitionPrototype ;
74457444 d3_transitionPrototype . select = function ( selector ) {
74467445 var id = this . id , subgroups = [ ] , subgroup , subnode , node ;
7447- if ( typeof selector !== "function" ) selector = d3_selection_selector ( selector ) ;
7446+ selector = d3_selection_selector ( selector ) ;
74487447 for ( var j = - 1 , m = this . length ; ++ j < m ; ) {
74497448 subgroups . push ( subgroup = [ ] ) ;
74507449 for ( var group = this [ j ] , i = - 1 , n = group . length ; ++ i < n ; ) {
@@ -7461,7 +7460,7 @@ d3 = function() {
74617460 } ;
74627461 d3_transitionPrototype . selectAll = function ( selector ) {
74637462 var id = this . id , subgroups = [ ] , subgroup , subnodes , node , subnode , transition ;
7464- if ( typeof selector !== "function" ) selector = d3_selection_selectorAll ( selector ) ;
7463+ selector = d3_selection_selectorAll ( selector ) ;
74657464 for ( var j = - 1 , m = this . length ; ++ j < m ; ) {
74667465 for ( var group = this [ j ] , i = - 1 , n = group . length ; ++ i < n ; ) {
74677466 if ( node = group [ i ] ) {
0 commit comments