@@ -80,30 +80,83 @@ <h4>Administration Time and Dosage</h4>
80
80
< script >
81
81
let json_src = '{% url ' dataview:dump_dose_graph_data ' sub_id %}' ;
82
82
83
- fetch ( json_src )
84
- . then ( res => res . json ( ) )
85
- . then ( ( out ) => {
86
- //debugging schitt
87
- //out = [ 7, 15, 2, 12, 13 ];
88
- console . log ( out ) ;
89
-
90
- var data = [ ] ;
91
- for ( var ouah in out . dosages ) {
92
- data . push ( out . dosages [ ouah ] ) ;
93
- }
94
-
95
- var x = d3 . scale . linear ( )
96
- . domain ( [ 0 , d3 . max ( data ) ] )
97
- . range ( [ 0 , d3 . max ( data ) ] ) ;
98
-
99
- d3 . select ( ".dose_chart" )
100
- . selectAll ( "div" )
101
- . data ( data )
102
- . enter ( ) . append ( "div" )
103
- . style ( "width" , function ( d ) { return x ( d ) + "px" ; } )
104
- . text ( function ( d ) { return ( d / out . scale_factor ) ; } ) ;
105
- } )
106
- . catch ( err => { throw err } ) ;
83
+ var margin = { top : 20 , right : 20 , bottom : 70 , left : 40 } ,
84
+ width = 600 - margin . left - margin . right ,
85
+ height = 300 - margin . top - margin . bottom ;
86
+
87
+ var x = d3 . scale . ordinal ( ) . rangeRoundBands ( [ 0 , width ] , .05 ) ;
88
+ var y = d3 . scale . linear ( ) . range ( [ height , 0 ] ) ;
89
+
90
+ var xAxis = d3 . svg . axis ( )
91
+ . scale ( x )
92
+ . orient ( "bottom" )
93
+ . ticks ( 5 ) ;
94
+
95
+ var yAxis = d3 . svg . axis ( )
96
+ . scale ( y )
97
+ . orient ( "left" )
98
+ . ticks ( 10 ) ;
99
+
100
+ var svg = d3 . select ( "body" ) . append ( "svg" )
101
+ . attr ( "width" , width + margin . left + margin . right )
102
+ . attr ( "height" , height + margin . top + margin . bottom )
103
+ . append ( "g" )
104
+ . attr ( "transform" ,
105
+ "translate(" + margin . left + "," + margin . top + ")" ) ;
106
+
107
+ d3 . json ( json_src , function ( error , data ) {
108
+ var ouah = [ ]
109
+ var ouah2 = [ ]
110
+ var ouah3 = [ ]
111
+ for ( var cntr = 0 ; cntr < data . dosages . length ; cntr ++ ) {
112
+ ouah [ cntr ] = { }
113
+ ouah2 [ cntr ] = ( cntr + 1 ) ;
114
+ ouah3 [ cntr ] = data . dosages [ cntr ] ;
115
+ ouah [ cntr ] . date = ouah2 [ cntr ]
116
+ ouah [ cntr ] . value = ouah3 [ cntr ]
117
+ }
118
+
119
+ console . log ( ouah ) ;
120
+
121
+ ouah . forEach ( function ( d ) {
122
+ d . date = d . date ;
123
+ d . value = + d . value ;
124
+ } ) ;
125
+
126
+ x . domain ( ouah . map ( function ( d ) { return d . date ; } ) ) ;
127
+ y . domain ( [ 0 , d3 . max ( ouah3 ) ] ) ;
128
+
129
+ svg . append ( "g" )
130
+ . attr ( "class" , "x axis" )
131
+ . attr ( "transform" , "translate(0," + height + ")" )
132
+ . call ( xAxis )
133
+ . selectAll ( "text" )
134
+ . style ( "text-anchor" , "end" )
135
+ . attr ( "dx" , "-.8em" )
136
+ . attr ( "dy" , "-.55em" )
137
+ . attr ( "transform" , "rotate(-90)" ) ;
138
+
139
+ svg . append ( "g" )
140
+ . attr ( "class" , "y axis" )
141
+ . call ( yAxis )
142
+ . append ( "text" )
143
+ . attr ( "transform" , "rotate(-90)" )
144
+ . attr ( "y" , 6 )
145
+ . attr ( "dy" , ".71em" )
146
+ . style ( "text-anchor" , "end" )
147
+ . text ( "Dosage" ) ;
148
+
149
+ svg . selectAll ( "bar" )
150
+ . data ( ouah )
151
+ . enter ( ) . append ( "rect" )
152
+ . style ( "fill" , "steelblue" )
153
+ . attr ( "x" , function ( d ) { return x ( d . date ) ; } )
154
+ . attr ( "width" , x . rangeBand ( ) )
155
+ . attr ( "y" , function ( d ) { return y ( d . value ) ; } )
156
+ . attr ( "height" , function ( d ) { return height - y ( d . value ) ; } ) ;
157
+
158
+ } ) ;
159
+
107
160
</ script >
108
161
109
162
{% else %}
@@ -128,27 +181,82 @@ <h4>Time Between Subsequent Administrations</h4>
128
181
< div class ="interval_chart "> </ div >
129
182
< script src ="//d3js.org/d3.v3.min.js "> </ script >
130
183
< script >
131
- let json_src2 = '{% url ' dataview:dump_interval_graph_data ' sub_id %}' ;
132
-
133
- fetch ( json_src2 )
134
- . then ( res => res . json ( ) )
135
- . then ( ( out ) => {
136
- //debugging schitt
137
- //out = [ 7, 15, 2, 12, 13 ];
138
- console . log ( out ) ;
139
-
140
- var x = d3 . scale . linear ( )
141
- . domain ( [ 0 , d3 . max ( out . timespans ) ] )
142
- . range ( [ 0 , d3 . max ( out . timespans ) ] ) ;
143
-
144
- d3 . select ( ".interval_chart" )
145
- . selectAll ( "div" )
146
- . data ( out . timespans )
147
- . enter ( ) . append ( "div" )
148
- . style ( "width" , function ( d ) { return x ( d ) + "px" ; } )
149
- . text ( function ( d ) { return ( secondsToHms ( d / out . scale_factor ) ) ; } ) ;
150
- } )
151
- . catch ( err => { throw err } ) ;
184
+ let json_src2 = '{% url ' dataview:dump_interval_graph_data ' sub_id %}' ;
185
+
186
+ var margin = { top : 20 , right : 20 , bottom : 70 , left : 40 } ,
187
+ width = 600 - margin . left - margin . right ,
188
+ height = 300 - margin . top - margin . bottom ;
189
+
190
+ var x2 = d3 . scale . ordinal ( ) . rangeRoundBands ( [ 0 , width ] , .05 ) ;
191
+ var y2 = d3 . scale . linear ( ) . range ( [ height , 0 ] ) ;
192
+
193
+ var xAxis2 = d3 . svg . axis ( )
194
+ . scale ( x2 )
195
+ . orient ( "bottom" )
196
+ . ticks ( 10 ) ;
197
+
198
+ var yAxis2 = d3 . svg . axis ( )
199
+ . scale ( y2 )
200
+ . orient ( "left" )
201
+ . ticks ( 10 ) ;
202
+
203
+ var svg2 = d3 . select ( "body" ) . append ( "svg" )
204
+ . attr ( "width" , width + margin . left + margin . right )
205
+ . attr ( "height" , height + margin . top + margin . bottom )
206
+ . append ( "g" )
207
+ . attr ( "transform" ,
208
+ "translate(" + margin . left + "," + margin . top + ")" ) ;
209
+
210
+ d3 . json ( json_src2 , function ( error , data ) {
211
+
212
+ var ouah_interval = [ ] ;
213
+ for ( var cntr = 0 ; cntr < data . timespans . length ; cntr ++ ) {
214
+ ouah_interval [ cntr ] = { }
215
+ ouah_interval [ cntr ] . num = cntr + 1 ;
216
+ ouah_interval [ cntr ] . value = data . timespans [ cntr ] ;
217
+ } ;
218
+
219
+ ouah_interval . forEach ( function ( d ) {
220
+ d . num = d . num ;
221
+ d . value = + d . value ;
222
+ } ) ;
223
+
224
+ //debugging
225
+ //console.log(ouah_interval);
226
+
227
+ x2 . domain ( ouah_interval . map ( function ( d ) { return d . num ; } ) ) ;
228
+ y2 . domain ( [ 0 , d3 . max ( ouah_interval , function ( d ) { return d . value ; } ) ] ) ;
229
+
230
+ svg2 . append ( "g" )
231
+ . attr ( "class" , "x axis" )
232
+ . attr ( "transform" , "translate(0," + height + ")" )
233
+ . call ( xAxis2 )
234
+ . selectAll ( "text" )
235
+ . style ( "text-anchor" , "end" )
236
+ . attr ( "dx" , "-.8em" )
237
+ . attr ( "dy" , "-.55em" )
238
+ . attr ( "transform" , "rotate(-90)" ) ;
239
+
240
+ svg2 . append ( "g" )
241
+ . attr ( "class" , "y axis" )
242
+ . call ( yAxis2 )
243
+ . append ( "text" )
244
+ . attr ( "transform" , "rotate(-90)" )
245
+ . attr ( "y2" , 6 )
246
+ . attr ( "dy" , ".71em" )
247
+ . style ( "text-anchor" , "end" )
248
+ . text ( "Timespan" ) ;
249
+
250
+ svg2 . selectAll ( "bar" )
251
+ . data ( ouah_interval )
252
+ . enter ( ) . append ( "rect" )
253
+ . style ( "fill" , "steelblue" )
254
+ . attr ( "x" , function ( d ) { return x2 ( d . num ) ; } )
255
+ . attr ( "width" , x2 . rangeBand ( ) )
256
+ . attr ( "y" , function ( d ) { return y2 ( d . value ) ; } )
257
+ . attr ( "height" , function ( d ) { return height - y2 ( d . value ) ; } ) ;
258
+
259
+ } ) ;
152
260
</ script >
153
261
154
262
{% else %}
0 commit comments