@@ -6,11 +6,11 @@ import 'd3-transition';
66
77import { Margin } from './Margin' ;
88
9- export const D3Chart = Base => class extends Margin ( InitSize ( Base ) ) {
10- constructor ( ) {
11- super ( ... arguments ) ;
9+ class D3ChartImpl {
10+ constructor ( that ) {
11+ this . that = that ;
1212
13- this . svg = select ( this . el )
13+ this . svg = select ( this . that . el )
1414 . append ( 'svg' )
1515 . attr ( 'xmlns' , 'http://www.w3.org/2000/svg' ) ;
1616
@@ -32,18 +32,27 @@ export const D3Chart = Base => class extends Margin(InitSize(Base)) {
3232 . classed ( 'plot' , true ) ;
3333 }
3434
35- initD3Chart ( ) {
36- this . svg . attr ( 'width' , this . width )
37- . attr ( 'height' , this . height ) ;
35+ init ( ) {
36+ this . svg . attr ( 'width' , this . that . width )
37+ . attr ( 'height' , this . that . height ) ;
3838
39- const margin = this . margin . get ( ) ;
39+ const margin = this . that . margin . get ( ) ;
4040
4141 this . left . attr ( 'transform' , `translate(0,${ margin . top } )` ) ;
42- this . bottom . attr ( 'transform' , `translate(${ margin . left } ,${ this . height - margin . bottom } )` ) ;
43- this . right . attr ( 'transform' , `translate(${ this . width - margin . right } ,${ margin . top } )` ) ;
42+ this . bottom . attr ( 'transform' , `translate(${ margin . left } ,${ this . that . height - margin . bottom } )` ) ;
43+ this . right . attr ( 'transform' , `translate(${ this . that . width - margin . right } ,${ margin . top } )` ) ;
4444 this . top . attr ( 'transform' , `translate(${ margin . left } ,0)` ) ;
4545 this . plot . attr ( 'transform' , `translate(${ margin . left } ,${ margin . top } )` ) ;
4646 }
47+ }
48+
49+ export const D3Chart = Base => class extends Margin ( InitSize ( Base ) ) {
50+ constructor ( ) {
51+ super ( ...arguments ) ;
52+ if ( ! this . d3chart ) {
53+ this . d3chart = new D3ChartImpl ( this ) ;
54+ }
55+ }
4756} ;
4857
4958export class Swatches extends D3Chart ( VisComponent ) {
@@ -52,44 +61,44 @@ export class Swatches extends D3Chart(VisComponent) {
5261
5362 this . width = options . width ;
5463 this . height = options . height ;
55- this . margin . set ( options . margin )
56- . initD3Chart ( ) ;
64+ this . margin . set ( options . margin ) ;
65+ this . d3chart . init ( ) ;
5766
5867 const margin = this . margin . get ( ) ;
5968
60- this . left . append ( 'rect' )
69+ this . d3chart . left . append ( 'rect' )
6170 . attr ( 'x' , 0 )
6271 . attr ( 'y' , 0 )
6372 . attr ( 'width' , margin . left )
6473 . attr ( 'height' , this . height - margin . bottom - margin . top )
6574 . style ( 'stroke' , 'black' )
6675 . style ( 'fill' , 'red' ) ;
6776
68- this . bottom . append ( 'rect' )
77+ this . d3chart . bottom . append ( 'rect' )
6978 . attr ( 'x' , 0 )
7079 . attr ( 'y' , 0 )
7180 . attr ( 'width' , this . width - margin . left - margin . right )
7281 . attr ( 'height' , margin . bottom )
7382 . style ( 'stroke' , 'black' )
7483 . style ( 'fill' , 'green' ) ;
7584
76- this . right . append ( 'rect' )
85+ this . d3chart . right . append ( 'rect' )
7786 . attr ( 'x' , 0 )
7887 . attr ( 'y' , 0 )
7988 . attr ( 'width' , margin . right )
8089 . attr ( 'height' , this . height - margin . bottom - margin . top )
8190 . style ( 'stroke' , 'black' )
8291 . style ( 'fill' , 'cyan' ) ;
8392
84- this . top . append ( 'rect' )
93+ this . d3chart . top . append ( 'rect' )
8594 . attr ( 'x' , 0 )
8695 . attr ( 'y' , 0 )
8796 . attr ( 'width' , this . width - margin . left - margin . right )
8897 . attr ( 'height' , margin . top )
8998 . style ( 'stroke' , 'black' )
9099 . style ( 'fill' , 'yellow' ) ;
91100
92- this . plot . append ( 'rect' )
101+ this . d3chart . plot . append ( 'rect' )
93102 . attr ( 'x' , 0 )
94103 . attr ( 'y' , 0 )
95104 . attr ( 'width' , this . width - margin . left - margin . right )
0 commit comments