@@ -3,7 +3,10 @@ HTMLWidgets.widget({
3
3
type : 'output' ,
4
4
5
5
factory : function ( el , width , height ) {
6
- var data ,
6
+ var
7
+ graphContainer ,
8
+ style ,
9
+ data ,
7
10
series ,
8
11
titleOptions ,
9
12
legendOptions ;
@@ -14,6 +17,18 @@ HTMLWidgets.widget({
14
17
// Clear out the container if it has anything
15
18
d3 . select ( el ) . selectAll ( '*' ) . remove ( ) ;
16
19
20
+ el . style [ "height" ] = "100%"
21
+
22
+ // Apply styles
23
+ if ( style && typeof style === 'object' && Object . keys ( style ) . length > 0 ) {
24
+ // Apply styles from the style object
25
+ for ( var key in style ) {
26
+ if ( style . hasOwnProperty ( key ) ) {
27
+ el . style [ key ] = style [ key ] ;
28
+ }
29
+ }
30
+ }
31
+
17
32
// Add Title
18
33
19
34
if ( titleOptions !== null && titleOptions ?. height !== null && titleOptions ?. show ) {
@@ -23,26 +38,21 @@ HTMLWidgets.widget({
23
38
. attr ( "id" , `GCvieweR-title-container-${ widgetId } ` )
24
39
. classed ( "GCVieweR-container" , true ) ;
25
40
26
- var titleHeight = computeSize ( titleOptions ?. height , height )
27
- var titleWidth = computeSize ( titleOptions ?. width , width )
41
+
42
+ titleOptions . width = el . clientWidth
43
+ titleOptions . height = computeSize ( titleOptions . height , el . clientHeight )
28
44
29
45
var title = createContainer (
30
46
`#GCvieweR-title-container-${ widgetId } ` ,
31
47
"svg-container" ,
32
48
"titleOptions" ,
33
- {
34
- width : titleWidth ,
35
- height : titleHeight ,
36
- backgroundColor : titleOptions ?. backgroundColor ?? "#0000" ,
37
- margin : titleOptions ?. margin
38
- } )
49
+ titleOptions )
39
50
. title ( titleOptions ?. title , titleOptions ?. subtitle , titleOptions ?. show ?? false , titleOptions )
40
-
41
51
}
42
52
43
53
// Add legend
44
54
45
- var legendHeight = ( legendOptions ?. show === false ) ? 0 : computeSize ( legendOptions ?. height , height ) ;
55
+ var legendHeight = ( legendOptions ?. show === false ) ? 0 : computeSize ( legendOptions ?. height , el . clientHeight ) ;
46
56
47
57
if ( legendOptions ?. group !== null && legendOptions ?. show ) {
48
58
@@ -51,15 +61,13 @@ HTMLWidgets.widget({
51
61
. attr ( "id" , `GCvieweR-legend-container-${ widgetId } ` )
52
62
. classed ( "GCVieweR-container" , true ) ;
53
63
64
+ legendOptions . width = width
65
+ legendOptions . height = computeSize ( legendOptions . height , el . clientHeight )
66
+
54
67
var legendContainer = createContainer ( `#GCvieweR-legend-container-${ widgetId } ` ,
55
68
"svg-container" ,
56
69
"legendOptions" ,
57
- {
58
- width : computeSize ( legendOptions ?. width , width ) ,
59
- height : legendHeight ,
60
- backgroundColor : legendOptions ?. backgroundColor ?? "#0000" ,
61
- margin : legendOptions . margin
62
- } )
70
+ legendOptions )
63
71
. legendData ( data )
64
72
. legend ( legendOptions ?. group ?? false , legendOptions ?. show ?? false , el . id , legendOptions ) ;
65
73
@@ -72,16 +80,16 @@ HTMLWidgets.widget({
72
80
var graph = d3 . select ( el )
73
81
. append ( "div" )
74
82
. attr ( "id" , `GCvieweR-graph-container-${ widgetId } ` )
83
+ . style ( "flex-direction" , graphContainer [ "direction" ] )
75
84
. classed ( "GCVieweR-container" , true ) ;
76
85
77
86
// Add Clusters
78
-
79
87
var clusters = Object . keys ( series ) ;
80
88
81
89
clusters . forEach ( function ( clusterKey ) {
82
90
83
91
var cluster = series [ clusterKey ] ,
84
- clusterStyle = cluster . style ,
92
+ clusterOptions = cluster . options ,
85
93
clusterData = HTMLWidgets . dataframeToD3 ( series [ clusterKey ] . data ) ,
86
94
scaleOptions = cluster . scale ,
87
95
clusterTitleOptions = cluster . clusterTitle ,
@@ -94,26 +102,15 @@ HTMLWidgets.widget({
94
102
scaleBarOptions = cluster . scaleBar ;
95
103
tooltipOptions = cluster . tooltip ;
96
104
97
- // Calculate height and width
98
- var clusterHeight = computeSize ( series [ clusterKey ] [ "grid" ] . height , el . clientHeight ) ;
99
- clusterHeight -= titleHeight ? ( titleHeight / clusters . length ) : 0 ;
100
- clusterHeight -= legendHeight ? ( legendHeight / clusters . length ) : 0 ;
101
- var clusterWidth = computeSize ( series [ clusterKey ] [ "grid" ] . width , width ) ;
102
- var clusterMargins = series [ clusterKey ] [ "grid" ] . margin ;
103
-
104
- var clusterOptions = {
105
- width : clusterWidth ,
106
- height : clusterHeight ,
107
- style : clusterStyle ,
108
- margin : {
109
- top : computeSize ( clusterMargins ?. top ?? 0 , height ) ,
110
- right : computeSize ( clusterMargins ?. right ?? 50 , width ) ,
111
- bottom : computeSize ( clusterMargins ?. bottom ?? 0 , height ) ,
112
- left : computeSize ( clusterMargins ?. left ?? 50 , width )
113
- }
114
- } ;
115
105
116
- var cluster = createContainer ( `#GCvieweR-graph-container-${ widgetId } ` , "svg-container" , 'clusterOptions' , clusterOptions )
106
+
107
+ var clonedClusterOptions = JSON . parse ( JSON . stringify ( clusterOptions ) ) ;
108
+ clonedClusterOptions . height = computeSize ( clonedClusterOptions . height , el . clientHeight ) ;
109
+ clonedClusterOptions . height -= titleOptions . height ? ( titleOptions . height / clusters . length ) : 0 ;
110
+ clonedClusterOptions . height -= legendHeight ? ( legendHeight / clusters . length ) : 0 ;
111
+ clonedClusterOptions . width = computeSize ( clonedClusterOptions . width , el . clientWidth ) ;
112
+
113
+ var cluster = createContainer ( `#GCvieweR-graph-container-${ widgetId } ` , "svg-container" , 'clusterOptions' , clonedClusterOptions )
117
114
. theme ( "preset" )
118
115
. title ( clusterTitleOptions ?. title , clusterTitleOptions ?. subtitle , clusterTitleOptions ?. show ?? false , clusterTitleOptions )
119
116
. footer ( footerOptions ?. title , footerOptions ?. subtitle , footerOptions ?. show ?? false , footerOptions )
@@ -141,47 +138,18 @@ HTMLWidgets.widget({
141
138
var legendContainer = createContainer ( `#GCvieweR-legend-container-${ widgetId } ` ,
142
139
"svg-container" ,
143
140
"legendOptions" ,
144
- {
145
- width : computeSize ( legendOptions ?. width , width ) ,
146
- height : legendHeight ,
147
- backgroundColor : legendOptions ?. backgroundColor ?? "#0000" ,
148
- margin : legendOptions . margin
149
- } )
141
+ legendOptions )
150
142
. legendData ( data )
151
143
. legend ( legendOptions ?. group ?? false , legendOptions ?. show ?? false , el . id , legendOptions ) ;
152
144
153
-
154
-
155
- }
156
-
157
- // Bottom Title
158
- if ( titleOptions ?. position == "bottom" && titleOptions !== null && titleOptions ?. height !== null && titleOptions ?. show ) {
159
-
160
- d3 . select ( `#GCvieweR-title-container-${ widgetId } ` ) . remove ( ) ;
161
-
162
- var titleContainer = d3 . select ( el )
163
- . append ( "div" )
164
- . attr ( "id" , `GCvieweR-title-container-${ widgetId } ` )
165
- . classed ( "GCVieweR-container" , true ) ;
166
-
167
- var title = createContainer (
168
- `#GCvieweR-title-container-${ widgetId } ` ,
169
- "svg-container" ,
170
- "titleOptions" ,
171
- {
172
- width : width ,
173
- height : titleHeight ,
174
- backgroundColor : titleOptions ?. backgroundColor ?? "#0000" ,
175
- margin : titleOptions ?. margin
176
- } )
177
- . title ( titleOptions ?. title , titleOptions ?. subtitle , titleOptions ?. show ?? false , titleOptions )
178
-
179
145
}
180
146
181
147
} ;
182
148
183
149
return {
184
150
renderValue : function ( input ) {
151
+ graphContainer = input . graphContainer ;
152
+ style = input . style ;
185
153
data = HTMLWidgets . dataframeToD3 ( input . data ) ;
186
154
series = input . series ;
187
155
titleOptions = input . title ;
0 commit comments