Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-analytics-dashboard
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-analytics-dashboard
Commits
f18745f5
Commit
f18745f5
authored
Sep 12, 2014
by
Clinton Blackburn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added percentage to enrollment geolocation tooltip
parent
27778da4
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
62 additions
and
31 deletions
+62
-31
analytics_dashboard/static/js/test/specs/utils-spec.js
+18
-5
analytics_dashboard/static/js/test/specs/world-map-view-spec.js
+17
-11
analytics_dashboard/static/js/utils/utils.js
+20
-6
analytics_dashboard/static/js/views/data-table-view.js
+1
-4
analytics_dashboard/static/js/views/world-map-view.js
+6
-5
No files found.
analytics_dashboard/static/js/test/specs/utils-spec.js
View file @
f18745f5
define
([
'utils/utils'
],
function
(
Utils
)
{
define
([
'utils/utils'
],
function
(
Utils
)
{
'use strict'
;
'use strict'
;
describe
(
'Utils'
,
function
()
{
describe
(
'Utils'
,
function
()
{
...
@@ -15,10 +15,10 @@ define(['utils/utils'], function(Utils) {
...
@@ -15,10 +15,10 @@ define(['utils/utils'], function(Utils) {
actualAttributes
=
Utils
.
getNodeProperties
(
element
.
attributes
);
actualAttributes
=
Utils
.
getNodeProperties
(
element
.
attributes
);
expect
(
actualAttributes
).
toEqual
({
expect
(
actualAttributes
).
toEqual
({
attribute
:
'myAttribute'
,
attribute
:
'myAttribute'
,
'data-type'
:
'my-data-type'
,
'data-type'
:
'my-data-type'
,
'data-category'
:
'my-data-category'
,
'data-category'
:
'my-data-category'
,
'data-event'
:
'my-data-event'
'data-event'
:
'my-data-event'
});
});
actualAttributes
=
Utils
.
getNodeProperties
(
element
.
attributes
,
actualAttributes
=
Utils
.
getNodeProperties
(
element
.
attributes
,
...
@@ -42,4 +42,17 @@ define(['utils/utils'], function(Utils) {
...
@@ -42,4 +42,17 @@ define(['utils/utils'], function(Utils) {
});
});
});
});
describe
(
'formatDisplayPercentage'
,
function
()
{
it
(
'should return < 1% if the parameter is < 0.01'
,
function
()
{
expect
(
Utils
.
formatDisplayPercentage
(
0
)).
toEqual
(
'< 1%'
);
expect
(
Utils
.
formatDisplayPercentage
(
0.002
)).
toEqual
(
'< 1%'
);
});
it
(
'should return a percentage formatted to a single decimal place if the parameter is >= 0.01'
,
function
()
{
expect
(
Utils
.
formatDisplayPercentage
(
0.01
)).
toEqual
(
'1.0%'
);
expect
(
Utils
.
formatDisplayPercentage
(
0.396
)).
toEqual
(
'39.6%'
);
expect
(
Utils
.
formatDisplayPercentage
(
1
)).
toEqual
(
'100.0%'
);
});
});
});
});
analytics_dashboard/static/js/test/specs/world-map-view-spec.js
View file @
f18745f5
...
@@ -11,15 +11,16 @@ define(['models/course-model', 'views/world-map-view'], function(CourseModel, Wo
...
@@ -11,15 +11,16 @@ define(['models/course-model', 'views/world-map-view'], function(CourseModel, Wo
actual
=
view
.
popupTemplate
({
actual
=
view
.
popupTemplate
({
name
:
'My Map'
,
name
:
'My Map'
,
value
:
100
value
:
100
,
percent
:
'100%'
});
});
expect
(
actual
).
toBe
(
'<div class="hoverinfo">My Map: 100</div>'
);
expect
(
actual
).
toBe
(
'<div class="hoverinfo">My Map: 100
(100%)
</div>'
);
});
});
it
(
'should format data for Datamaps'
,
function
()
{
it
(
'should format data for Datamaps'
,
function
()
{
var
rawData
=
[
var
rawData
=
[
{
countryCode
:
'USA'
,
count
:
100
},
{
countryCode
:
'USA'
,
count
:
100
,
percent
:
0.3333
},
{
countryCode
:
'ARG'
,
count
:
200
}],
{
countryCode
:
'ARG'
,
count
:
200
,
percent
:
0.6666
}],
model
=
new
CourseModel
({
mapData
:
rawData
}),
model
=
new
CourseModel
({
mapData
:
rawData
}),
view
=
new
WorldMapView
({
view
=
new
WorldMapView
({
model
:
model
,
model
:
model
,
...
@@ -30,30 +31,35 @@ define(['models/course-model', 'views/world-map-view'], function(CourseModel, Wo
...
@@ -30,30 +31,35 @@ define(['models/course-model', 'views/world-map-view'], function(CourseModel, Wo
actual
=
view
.
formatData
();
actual
=
view
.
formatData
();
expected
=
{
expected
=
{
USA
:
{
value
:
100
,
fillKey
:
'USA'
},
USA
:
{
value
:
100
,
fillKey
:
'USA'
,
percent
:
0.3333
},
ARG
:
{
value
:
200
,
fillKey
:
'ARG'
}
ARG
:
{
value
:
200
,
fillKey
:
'ARG'
,
percent
:
0.6666
}
};
};
expect
(
actual
).
toEqual
(
expected
);
expect
(
actual
).
toEqual
(
expected
);
});
});
it
(
'should fill in colors for countries'
,
function
()
{
it
(
'should fill in colors for countries'
,
function
()
{
var
countryData
=
{
var
lowColor
=
'#000000'
,
highColor
=
'#ffffff'
,
countryData
=
{
USA
:
{
value
:
0
,
fillKey
:
'USA'
},
USA
:
{
value
:
0
,
fillKey
:
'USA'
},
BLV
:
{
value
:
100
,
fillKey
:
'BLV'
},
BLV
:
{
value
:
100
,
fillKey
:
'BLV'
},
ARG
:
{
value
:
200
,
fillKey
:
'ARG'
}},
ARG
:
{
value
:
200
,
fillKey
:
'ARG'
}},
view
=
new
WorldMapView
({
view
=
new
WorldMapView
({
model
:
new
CourseModel
(),
model
:
new
CourseModel
(),
lowColor
:
'#000000'
,
lowColor
:
lowColor
,
highColor
:
'#ffffff'
highColor
:
highColor
}),
}),
actual
,
actual
,
expected
;
expected
,
colorMap
=
d3
.
scale
.
sqrt
()
.
domain
([
0
,
200
])
.
range
([
lowColor
,
highColor
]);
actual
=
view
.
getFills
(
countryData
,
200
);
actual
=
view
.
getFills
(
countryData
,
200
);
expected
=
{
expected
=
{
defaultFill
:
'#000000'
,
defaultFill
:
'#000000'
,
USA
:
'#000000'
,
USA
:
'#000000'
,
BLV
:
'#808080'
,
BLV
:
colorMap
(
100
)
,
ARG
:
'#ffffff'
ARG
:
'#ffffff'
};
};
expect
(
actual
).
toEqual
(
expected
);
expect
(
actual
).
toEqual
(
expected
);
...
...
analytics_dashboard/static/js/utils/utils.js
View file @
f18745f5
...
@@ -10,19 +10,19 @@ define(['moment', 'underscore'], function (moment, _) {
...
@@ -10,19 +10,19 @@ define(['moment', 'underscore'], function (moment, _) {
* @param blackList Exclude attributes in this array of strings.
* @param blackList Exclude attributes in this array of strings.
* @returns Hash of found attributes.
* @returns Hash of found attributes.
*/
*/
getNodeProperties
:
function
(
nodeAttributes
,
startsWithAndStrip
,
blackList
)
{
getNodeProperties
:
function
(
nodeAttributes
,
startsWithAndStrip
,
blackList
)
{
var
properties
=
{};
var
properties
=
{};
// fill in defaults
// fill in defaults
startsWithAndStrip
=
startsWithAndStrip
||
''
;
startsWithAndStrip
=
startsWithAndStrip
||
''
;
blackList
=
blackList
||
[];
blackList
=
blackList
||
[];
_
(
_
(
nodeAttributes
.
length
).
range
()).
each
(
function
(
i
)
{
_
(
_
(
nodeAttributes
.
length
).
range
()).
each
(
function
(
i
)
{
var
nodeName
=
nodeAttributes
.
item
(
i
).
nodeName
,
var
nodeName
=
nodeAttributes
.
item
(
i
).
nodeName
,
strippedName
;
strippedName
;
// filter the attributes to just the ones that start with our
// filter the attributes to just the ones that start with our
// selection and aren't in our blacklist
// selection and aren't in our blacklist
if
(
nodeName
.
indexOf
(
startsWithAndStrip
)
===
0
&&
!
_
(
blackList
).
contains
(
nodeName
))
{
if
(
nodeName
.
indexOf
(
startsWithAndStrip
)
===
0
&&
!
_
(
blackList
).
contains
(
nodeName
))
{
// remove the
// remove the
strippedName
=
nodeName
.
replace
(
startsWithAndStrip
,
''
);
strippedName
=
nodeName
.
replace
(
startsWithAndStrip
,
''
);
properties
[
strippedName
]
=
properties
[
strippedName
]
=
...
@@ -34,11 +34,25 @@ define(['moment', 'underscore'], function (moment, _) {
...
@@ -34,11 +34,25 @@ define(['moment', 'underscore'], function (moment, _) {
/**
/**
* Takes a standard string date and returns a formatted date.
* Takes a standard string date and returns a formatted date.
* @param
String
date (ex. 2014-01-31)
* @param
{string}
date (ex. 2014-01-31)
* @returns Returns a formatted date (ex. January 31, 2014)
* @returns
{string}
Returns a formatted date (ex. January 31, 2014)
*/
*/
formatDate
:
function
(
date
)
{
formatDate
:
function
(
date
)
{
return
moment
(
date
).
format
(
'MMMM D, YYYY'
);
return
moment
(
date
).
format
(
'MMMM D, YYYY'
);
},
/**
* Format the given value as a percentage to be displayed to the end user.
* @param value {number}
* @returns {string}
*/
formatDisplayPercentage
:
function
(
value
)
{
var
display
=
'< 1%'
;
if
(
value
>=
0.01
)
{
display
=
(
value
*
100
).
toFixed
(
1
)
+
'%'
;
}
return
display
;
}
}
};
};
...
...
analytics_dashboard/static/js/views/data-table-view.js
View file @
f18745f5
...
@@ -92,10 +92,7 @@ define(['dataTablesBootstrap', 'jquery', 'underscore', 'utils/utils', 'views/att
...
@@ -92,10 +92,7 @@ define(['dataTablesBootstrap', 'jquery', 'underscore', 'utils/utils', 'views/att
var
value
=
row
[
columnKey
],
var
value
=
row
[
columnKey
],
display
=
value
;
display
=
value
;
if
(
type
===
'display'
)
{
if
(
type
===
'display'
)
{
display
=
' < 1%'
;
display
=
' '
+
Utils
.
formatDisplayPercentage
(
value
);
if
(
value
>=
0.01
)
{
display
=
(
value
*
100
).
toFixed
(
1
)
+
'%'
;
}
}
}
return
display
;
return
display
;
};
};
...
...
analytics_dashboard/static/js/views/world-map-view.js
View file @
f18745f5
define
([
'jquery'
,
'd3'
,
'datamaps'
,
'underscore'
,
'views/attribute-listener-view'
],
define
([
'jquery'
,
'd3'
,
'datamaps'
,
'underscore'
,
'
utils/utils'
,
'
views/attribute-listener-view'
],
function
(
$
,
d3
,
Datamap
,
_
,
AttributeListenerView
)
{
function
(
$
,
d3
,
Datamap
,
_
,
Utils
,
AttributeListenerView
)
{
'use strict'
;
'use strict'
;
/**
/**
...
@@ -40,6 +40,7 @@ define(['jquery', 'd3', 'datamaps', 'underscore', 'views/attribute-listener-view
...
@@ -40,6 +40,7 @@ define(['jquery', 'd3', 'datamaps', 'underscore', 'views/attribute-listener-view
var
key
=
country
.
countryCode
;
var
key
=
country
.
countryCode
;
formattedData
[
key
]
=
{
formattedData
[
key
]
=
{
value
:
country
.
count
,
value
:
country
.
count
,
percent
:
country
.
percent
,
fillKey
:
key
fillKey
:
key
};
};
});
});
...
@@ -56,7 +57,6 @@ define(['jquery', 'd3', 'datamaps', 'underscore', 'views/attribute-listener-view
...
@@ -56,7 +57,6 @@ define(['jquery', 'd3', 'datamaps', 'underscore', 'views/attribute-listener-view
fills
=
{},
fills
=
{},
colorMap
;
colorMap
;
// single hue linear scaled
colorMap
=
d3
.
scale
.
sqrt
()
colorMap
=
d3
.
scale
.
sqrt
()
.
domain
([
0
,
max
])
.
domain
([
0
,
max
])
.
range
([
self
.
options
.
lowColor
,
self
.
options
.
highColor
]);
.
range
([
self
.
options
.
lowColor
,
self
.
options
.
highColor
]);
...
@@ -151,7 +151,7 @@ define(['jquery', 'd3', 'datamaps', 'underscore', 'views/attribute-listener-view
...
@@ -151,7 +151,7 @@ define(['jquery', 'd3', 'datamaps', 'underscore', 'views/attribute-listener-view
* Underscore style template for the hover popup that displays a
* Underscore style template for the hover popup that displays a
* label/name and value.
* label/name and value.
*/
*/
popupTemplate
:
_
.
template
(
'<div class="hoverinfo"><%=name%>: <%=value%></div>'
),
popupTemplate
:
_
.
template
(
'<div class="hoverinfo"><%=name%>: <%=value%>
(<%=percent%>)
</div>'
),
render
:
function
()
{
render
:
function
()
{
AttributeListenerView
.
prototype
.
render
.
call
(
this
);
AttributeListenerView
.
prototype
.
render
.
call
(
this
);
...
@@ -181,7 +181,8 @@ define(['jquery', 'd3', 'datamaps', 'underscore', 'views/attribute-listener-view
...
@@ -181,7 +181,8 @@ define(['jquery', 'd3', 'datamaps', 'underscore', 'views/attribute-listener-view
popupTemplate
:
function
(
geography
,
data
)
{
popupTemplate
:
function
(
geography
,
data
)
{
return
self
.
popupTemplate
({
return
self
.
popupTemplate
({
name
:
geography
.
properties
.
name
,
name
:
geography
.
properties
.
name
,
value
:
data
?
data
.
value
:
0
value
:
data
?
data
.
value
:
0
,
percent
:
data
?
Utils
.
formatDisplayPercentage
(
data
.
percent
)
:
0
});
});
}
}
},
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment