1
1
// Fetch source data for charts from Django REST API
2
- fetch ( 'https://django-ecommerce1 .herokuapp.com/tickets/api/tickets' )
2
+ fetch ( 'https://django-issue-tracker-1 .herokuapp.com/tickets/api/tickets' )
3
3
. then ( ( response ) => {
4
4
return response . json ( ) ;
5
5
} )
6
6
. then ( ( data ) => {
7
- // Date parsing
7
+ // Parse datetime
8
8
const dateFormatSpecifier = '%Y-%m-%dT%H:%M:%S.%f%Z' ;
9
9
const dateFormatParser = d3 . timeParse ( dateFormatSpecifier ) ;
10
10
@@ -17,7 +17,7 @@ fetch('https://django-ecommerce1.herokuapp.com/tickets/api/tickets')
17
17
d . created_date_month = d3 . timeMonth ( d . created_date_dd ) ;
18
18
// Month
19
19
d . created_date_year = d3 . timeYear ( d . created_date_dd ) ;
20
- // RESOLVED DATE parsed, if resolved
20
+ // If ticket status is resolved, parse RESOLVED DATE
21
21
if ( d . resolved_date ) {
22
22
// Parsed date
23
23
d . resolved_date_dd = dateFormatParser ( d . resolved_date ) ;
@@ -33,6 +33,7 @@ fetch('https://django-ecommerce1.herokuapp.com/tickets/api/tickets')
33
33
} ) ;
34
34
35
35
function drawGraphs ( data ) {
36
+ // Crossfilter data
36
37
let ndx = crossfilter ( data ) ;
37
38
38
39
// Pass crossfiltered data to charts
@@ -43,16 +44,18 @@ function drawGraphs(data) {
43
44
drawStatusByMonthBarChart ( ndx ) ;
44
45
showFilteredCount ( ndx ) ;
45
46
47
+ // Render all charts
46
48
dc . renderAll ( ) ;
47
49
}
48
50
49
- // Status by month
51
+ // Status by Month Bar Chart
50
52
function drawStatusByMonthBarChart ( ndx ) {
51
53
let dateCreatedDim = ndx . dimension ( ( d ) => d . created_date_day ) ;
52
54
let statusGroup = dateCreatedDim
53
55
. group ( )
54
56
. reduce ( reduceAdd , reduceRemove , reduceInitial ) ;
55
57
58
+ // Custom reducer
56
59
function reduceAdd ( i , d ) {
57
60
i [ d . status ] = ( i [ d . status ] || 0 ) + 1 ;
58
61
return i ;
@@ -137,14 +140,16 @@ function drawStatusRowChart(ndx) {
137
140
let statusDim = ndx . dimension ( ( d ) => d . status ) ;
138
141
let statusGroup = statusDim . group ( ) ;
139
142
140
- // Open/Closed
143
+ // Open/Closed Dimension
141
144
let openClosedDim = ndx . dimension ( function ( d ) {
142
145
if ( d . status == 'Resolved' || d . status == 'Cancelled' ) {
143
146
return 'Closed' ;
144
147
} else {
145
148
return 'Open' ;
146
149
}
147
150
} ) ;
151
+
152
+ // Open/Closed Group
148
153
let openClosedGroup = openClosedDim . group ( ) ;
149
154
150
155
// Status Row Chart
0 commit comments