Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
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-platform
Commits
96637e9a
Commit
96637e9a
authored
Apr 11, 2013
by
Valera Rozuvan
Committed by
Vasyl Nakvasiuk
May 13, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change some code styling. Added statistics display. Minor tweaks.
parent
6deeb602
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
18 deletions
+25
-18
common/lib/xmodule/xmodule/js/src/word_cloud/word_cloud_main.js
+25
-18
No files found.
common/lib/xmodule/xmodule/js/src/word_cloud/word_cloud_main.js
View file @
96637e9a
...
@@ -6,13 +6,10 @@ define('WordCloudMain', ['logme'], function (logme) {
...
@@ -6,13 +6,10 @@ define('WordCloudMain', ['logme'], function (logme) {
WordCloudMain
.
prototype
=
{
WordCloudMain
.
prototype
=
{
'submitAnswer'
:
function
()
{
'submitAnswer'
:
function
()
{
var
_this
,
data
;
var
_this
=
this
,
data
=
{
data
=
{
'student_words'
:
[]
'student_words'
:
[]
};
};
_this
=
this
;
this
.
wordCloudEl
.
find
(
'input.input-cloud'
).
each
(
function
(
index
,
value
){
this
.
wordCloudEl
.
find
(
'input.input-cloud'
).
each
(
function
(
index
,
value
){
data
.
student_words
.
push
(
$
(
value
).
val
());
data
.
student_words
.
push
(
$
(
value
).
val
());
...
@@ -23,13 +20,12 @@ WordCloudMain.prototype = {
...
@@ -23,13 +20,12 @@ WordCloudMain.prototype = {
$
.
postWithPrefix
(
$
.
postWithPrefix
(
_this
.
ajax_url
+
'/'
+
'submit'
,
$
.
param
(
data
),
_this
.
ajax_url
+
'/'
+
'submit'
,
$
.
param
(
data
),
function
(
response
)
{
function
(
response
)
{
if
(
if
(
response
.
status
!==
'success'
)
{
(
response
.
hasOwnProperty
(
'status'
)
!==
true
)
||
logme
(
'ERROR: '
+
response
.
error
);
(
typeof
response
.
status
!==
'string'
)
||
(
response
.
status
.
toLowerCase
()
!==
'success'
))
{
return
;
return
;
}
}
_this
.
showWordCloud
(
response
);
_this
.
showWordCloud
(
response
);
}
}
);
);
...
@@ -44,6 +40,8 @@ WordCloudMain.prototype = {
...
@@ -44,6 +40,8 @@ WordCloudMain.prototype = {
this
.
wordCloudEl
.
find
(
'#input-cloud-section'
).
hide
();
this
.
wordCloudEl
.
find
(
'#input-cloud-section'
).
hide
();
console
.
log
(
'response: '
,
response
);
words
=
response
.
top_words
;
words
=
response
.
top_words
;
maxSize
=
0
;
maxSize
=
0
;
...
@@ -67,7 +65,7 @@ WordCloudMain.prototype = {
...
@@ -67,7 +65,7 @@ WordCloudMain.prototype = {
.
fontSize
(
function
(
d
)
{
.
fontSize
(
function
(
d
)
{
var
size
;
var
size
;
size
=
(
d
.
size
/
maxSize
)
*
1
4
0
;
size
=
(
d
.
size
/
maxSize
)
*
1
0
0
;
if
(
size
<
20
)
{
if
(
size
<
20
)
{
return
0
;
return
0
;
...
@@ -82,22 +80,32 @@ WordCloudMain.prototype = {
...
@@ -82,22 +80,32 @@ WordCloudMain.prototype = {
return
;
return
;
function
draw
(
words
)
{
function
draw
(
words
)
{
var
el
;
var
el
,
firstWord
=
false
;
$
(
'#word_cloud_d3_'
+
_this
.
hash
).
remove
();
$
(
'#word_cloud_d3_'
+
_this
.
hash
).
remove
();
el
=
$
(
el
=
$
(
'<div '
+
'<div '
+
'id="'
+
'word_cloud_d3_'
+
_this
.
hash
+
'" '
+
'id="'
+
'word_cloud_d3_'
+
_this
.
hash
+
'" '
+
'style="display: block; width: 500px; height:
500px
; margin-left: auto; margin-right: auto;" '
+
'style="display: block; width: 500px; height:
auto
; margin-left: auto; margin-right: auto;" '
+
'></div>'
'></div>'
);
);
el
.
append
(
'<h3>Your words</h3>'
);
$
.
each
(
response
.
student_words
,
function
(
index
,
value
)
{
if
(
firstWord
===
false
)
{
firstWord
=
true
;
}
else
{
el
.
append
(
', '
);
}
el
.
append
(
index
+
': '
+
(
100.0
*
(
value
/
response
.
total_count
))
+
' %'
);
});
el
.
append
(
'<br /><br /><h3>Overall number of words: '
+
response
.
total_count
+
'</h3><br />'
);
_this
.
wordCloudEl
.
append
(
el
);
_this
.
wordCloudEl
.
append
(
el
);
d3
.
select
(
'#word_cloud_d3_'
+
_this
.
hash
).
append
(
'svg'
)
d3
.
select
(
'#word_cloud_d3_'
+
_this
.
hash
).
append
(
'svg'
)
.
attr
(
'width'
,
500
)
.
attr
(
'width'
,
500
)
.
attr
(
'height'
,
500
)
.
attr
(
'height'
,
500
)
.
attr
(
'id'
,
'word_cloud_d3_'
+
_this
.
hash
)
.
append
(
'g'
)
.
append
(
'g'
)
.
attr
(
'transform'
,
'translate(190,250)'
)
.
attr
(
'transform'
,
'translate(190,250)'
)
.
selectAll
(
'text'
)
.
selectAll
(
'text'
)
...
@@ -125,7 +133,7 @@ WordCloudMain.prototype = {
...
@@ -125,7 +133,7 @@ WordCloudMain.prototype = {
return
WordCloudMain
;
return
WordCloudMain
;
function
WordCloudMain
(
el
)
{
function
WordCloudMain
(
el
)
{
var
_this
;
var
_this
=
this
;
this
.
wordCloudEl
=
$
(
el
).
find
(
'.word_cloud'
);
this
.
wordCloudEl
=
$
(
el
).
find
(
'.word_cloud'
);
if
(
this
.
wordCloudEl
.
length
!==
1
)
{
if
(
this
.
wordCloudEl
.
length
!==
1
)
{
...
@@ -135,9 +143,9 @@ function WordCloudMain(el) {
...
@@ -135,9 +143,9 @@ function WordCloudMain(el) {
return
;
return
;
}
}
// Later on used to create a unique DOM element.
hash
+=
1
;
hash
+=
1
;
this
.
hash
=
hash
;
this
.
hash
=
hash
;
this
.
wordCloudEl
.
addClass
(
'word_cloud_d3_'
+
this
.
hash
);
this
.
configJson
=
null
;
this
.
configJson
=
null
;
try
{
try
{
...
@@ -160,7 +168,6 @@ function WordCloudMain(el) {
...
@@ -160,7 +168,6 @@ function WordCloudMain(el) {
// Get the URL to which we will post the users words.
// Get the URL to which we will post the users words.
this
.
ajax_url
=
this
.
wordCloudEl
.
data
(
'ajax-url'
);
this
.
ajax_url
=
this
.
wordCloudEl
.
data
(
'ajax-url'
);
_this
=
this
;
this
.
inputSaveEl
.
on
(
'click'
,
function
()
{
this
.
inputSaveEl
.
on
(
'click'
,
function
()
{
_this
.
submitAnswer
();
_this
.
submitAnswer
();
});
});
...
...
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