1+ import ArchimedesSpiral from './algorithms/ArchimedesSpiral' ;
2+ import getMaxShapeSize from './positioning/getMaxShapeSize' ;
13import position from './positioning/position' ;
24
5+ const defaultConfig = {
6+ algorithm : ArchimedesSpiral ,
7+ cover : true ,
8+ padding : 10 ,
9+ proportional : false ,
10+ spread : 0.25 ,
11+ } ;
12+
313export default class SysPlot {
414 constructor ( ) {
5- this . config = { } ;
15+ this . config = Object . assign ( { } , defaultConfig ) ;
616 }
717
818 setConfig ( config = { } ) {
19+ const {
20+ algorithm = defaultConfig . algorithm ,
21+ cover = defaultConfig . cover ,
22+ padding = defaultConfig . padding ,
23+ proportional = defaultConfig . proportional ,
24+ spread = defaultConfig . spread ,
25+ } = config ;
26+
927 const updateVectors =
10- this . config . algorithm !== config . algorithm ||
11- this . config . proportional !== config . proportional ||
12- this . config . spread !== config . spread ;
28+ this . config . algorithm !== algorithm ||
29+ this . config . cover !== cover ||
30+ this . config . proportional !== proportional ||
31+ this . config . spread !== spread ;
1332
1433 const updatePositions = updateVectors ||
15- this . config . padding !== config . padding ;
34+ this . config . padding !== padding ;
1635
1736 this . config = {
18- algorithm : config . algorithm ,
19- padding : config . padding ,
20- proportional : config . proportional ,
21- spread : config . spread ,
37+ algorithm,
38+ cover,
39+ padding,
40+ proportional,
41+ spread,
2242 } ;
2343
2444 if ( updateVectors ) this . vectors = null ;
@@ -39,28 +59,38 @@ export default class SysPlot {
3959 }
4060
4161 setShapes ( shapes ) {
42- this . shapes = shapes ;
62+ const shapesBoundaryOffset = this . config . cover ? 0 : ( getMaxShapeSize ( shapes ) / 2 ) ;
63+
4364 this . positions = null ;
65+ this . shapes = shapes ;
66+
67+ if ( this . shapesBoundaryOffset !== shapesBoundaryOffset ) {
68+ this . shapesBoundaryOffset = shapesBoundaryOffset ;
69+ this . vectors = null ;
70+ }
4471
4572 return this ;
4673 }
4774
4875 getVectors ( ) {
4976 if ( ! this . vectors ) {
50- const { config, width : w , height : h } = this ;
77+ const { config, width, height } = this ;
78+ const h = height - this . shapesBoundaryOffset ;
79+ const w = width - this . shapesBoundaryOffset ;
5180 const [ xDim , yDim ] = config . proportional ? [ w , h ] : ( w > h ? [ w , w ] : [ h , h ] ) ;
5281 const spread = Math . max ( 0.1 , Math . min ( 1 , config . spread ) ) / 10 ;
5382
54- this . vectors = this . config . algorithm (
55- this . width ,
56- this . height ,
57- this . width / 2 ,
58- this . height / 2 ,
59- ( xDim * ( spread * ( xDim / yDim ) ) )
83+ this . vectors = this . config . algorithm ( {
84+ cover : config . cover ,
85+ height : h ,
86+ width : w ,
87+ xCenter : ( w / 2 ) + ( this . shapesBoundaryOffset / 2 ) ,
88+ xDistance : ( xDim * ( spread * ( xDim / yDim ) ) )
6089 * this . config . algorithm . NORMALISATION_FACTOR ,
61- ( yDim * ( spread * ( yDim / xDim ) ) )
90+ yCenter : ( h / 2 ) + ( this . shapesBoundaryOffset / 2 ) ,
91+ yDistance : ( yDim * ( spread * ( yDim / xDim ) ) )
6292 * this . config . algorithm . NORMALISATION_FACTOR ,
63- ) ;
93+ } ) ;
6494 }
6595
6696 return this . vectors ;
0 commit comments