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
32c70a52
Commit
32c70a52
authored
Dec 10, 2012
by
Valera Rozuvan
Committed by
Alexander Kryklia
Jan 15, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
GST work in progress.
parent
7de575a8
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
113 additions
and
35 deletions
+113
-35
common/lib/xmodule/xmodule/js/src/graphical_slider_tool/graph.js
+81
-14
common/lib/xmodule/xmodule/js/src/graphical_slider_tool/gst_main.js
+3
-4
common/lib/xmodule/xmodule/js/src/graphical_slider_tool/sliders.js
+1
-11
common/lib/xmodule/xmodule/js/src/graphical_slider_tool/state.js
+28
-6
No files found.
common/lib/xmodule/xmodule/js/src/graphical_slider_tool/graph.js
View file @
32c70a52
...
@@ -2,13 +2,12 @@
...
@@ -2,13 +2,12 @@
// define() functions from Require JS available inside the anonymous function.
// define() functions from Require JS available inside the anonymous function.
(
function
(
requirejs
,
require
,
define
)
{
(
function
(
requirejs
,
require
,
define
)
{
define
(
'Graph'
,
[
'logme'
],
function
(
logme
)
{
define
(
'Graph'
,
[
],
function
(
)
{
return
Graph
;
return
Graph
;
function
Graph
(
gstId
,
state
)
{
function
Graph
(
gstId
,
config
,
state
)
{
var
plotDiv
,
data
;
var
plotDiv
,
dataSets
,
functions
;
logme
(
'We are inside Graph module.'
,
gstId
,
state
);
plotDiv
=
$
(
'#'
+
gstId
+
'_plot'
);
plotDiv
=
$
(
'#'
+
gstId
+
'_plot'
);
...
@@ -21,34 +20,102 @@ define('Graph', ['logme'], function (logme) {
...
@@ -21,34 +20,102 @@ define('Graph', ['logme'], function (logme) {
state
.
bindUpdatePlotEvent
(
plotDiv
,
onUpdatePlot
);
state
.
bindUpdatePlotEvent
(
plotDiv
,
onUpdatePlot
);
createFunctions
();
generateData
();
generateData
();
updatePlot
();
updatePlot
();
return
;
return
;
function
onUpdatePlot
(
event
)
{
function
createFunctions
()
{
logme
(
'redrawing plot'
);
functions
=
[];
if
(
typeof
config
.
plot
[
'function'
]
===
'undefined'
)
{
return
;
}
if
(
typeof
config
.
plot
[
'function'
]
===
'string'
)
{
addFunction
(
config
.
plot
[
'function'
]);
}
else
if
(
$
.
isPlainObject
(
config
.
plot
[
'function'
])
===
true
)
{
}
else
if
(
$
.
isArray
(
config
.
plot
[
'function'
]))
{
}
return
;
function
addFunction
(
funcString
,
color
,
line
,
dot
,
label
,
style
,
point_size
)
{
var
newFunctionObject
,
func
,
constNames
;
if
(
typeof
funcString
!==
'string'
)
{
return
;
}
newFunctionObject
=
{};
constNames
=
state
.
getAllConstantNames
();
// The 'x' is always one of the function parameters.
constNames
.
push
(
'x'
);
// Must make sure that the function body also gets passed to
// the Function cosntructor.
constNames
.
push
(
funcString
);
func
=
Function
.
apply
(
null
,
constNames
);
newFunctionObject
[
'func'
]
=
func
;
if
(
typeof
color
===
'string'
)
{
newFunctionObject
[
'color'
]
=
color
;
}
if
(
typeof
line
===
'boolean'
)
{
newFunctionObject
[
'line'
]
=
line
;
}
if
(
typeof
dot
===
'boolean'
)
{
newFunctionObject
[
'dot'
]
=
dot
;
}
if
(
typeof
label
===
'string'
)
{
newFunctionObject
[
'label'
]
=
label
;
}
functions
.
push
(
newFunctionObject
);
}
}
function
onUpdatePlot
(
event
)
{
generateData
();
generateData
();
updatePlot
();
updatePlot
();
}
}
function
generateData
()
{
function
generateData
()
{
var
a
,
b
,
c1
;
var
c0
,
c1
,
datapoints
,
constValues
,
x
,
y
;
constValues
=
state
.
getAllConstantValues
();
dataSets
=
[];
for
(
c0
=
0
;
c0
<
functions
.
length
;
c0
+=
1
)
{
datapoints
=
[];
a
=
state
.
getConstValue
(
'a'
);
for
(
c1
=
0
;
c1
<
30
;
c1
+=
0.1
)
{
b
=
state
.
getConstValue
(
'b'
);
x
=
c1
;
// Push the 'x' variable to the end of the parameter array.
constValues
.
push
(
x
);
y
=
functions
[
c0
].
func
.
apply
(
window
,
constValues
);
constValues
.
pop
();
data
=
[]
;
datapoints
.
push
([
x
,
y
])
;
data
.
push
([]);
}
for
(
c1
=
0
;
c1
<
30
;
c1
++
)
{
dataSets
.
push
(
datapoints
);
data
[
0
].
push
([
c1
,
a
*
c1
*
(
c1
+
a
)
*
(
c1
-
b
)
+
b
*
c1
*
(
c1
+
b
*
a
)]);
}
}
}
}
function
updatePlot
()
{
function
updatePlot
()
{
$
.
plot
(
plotDiv
,
data
,
{
xaxis
:
{
min
:
0
,
max
:
30
}}
);
$
.
plot
(
plotDiv
,
data
Sets
);
}
}
}
}
});
});
...
...
common/lib/xmodule/xmodule/js/src/graphical_slider_tool/gst_main.js
View file @
32c70a52
...
@@ -4,9 +4,8 @@
...
@@ -4,9 +4,8 @@
define
(
define
(
'GstMain'
,
'GstMain'
,
[
'State'
,
'logme'
,
'GeneralMethods'
,
'Sliders'
,
'Graph'
],
[
'State'
,
'GeneralMethods'
,
'Sliders'
,
'Graph'
],
function
(
State
,
logme
,
GeneralMethods
,
Sliders
,
Graph
)
{
function
(
State
,
GeneralMethods
,
Sliders
,
Graph
)
{
logme
(
GeneralMethods
);
return
GstMain
;
return
GstMain
;
...
@@ -19,7 +18,7 @@ define(
...
@@ -19,7 +18,7 @@ define(
Sliders
(
gstId
,
config
,
state
);
Sliders
(
gstId
,
config
,
state
);
Graph
(
gstId
,
state
);
Graph
(
gstId
,
config
,
state
);
}
}
});
});
...
...
common/lib/xmodule/xmodule/js/src/graphical_slider_tool/sliders.js
View file @
32c70a52
...
@@ -2,16 +2,10 @@
...
@@ -2,16 +2,10 @@
// define() functions from Require JS available inside the anonymous function.
// define() functions from Require JS available inside the anonymous function.
(
function
(
requirejs
,
require
,
define
)
{
(
function
(
requirejs
,
require
,
define
)
{
define
(
'Sliders'
,
[
'logme'
],
function
(
logme
)
{
define
(
'Sliders'
,
[
],
function
(
)
{
return
Sliders
;
return
Sliders
;
function
Sliders
(
gstId
,
config
,
state
)
{
function
Sliders
(
gstId
,
config
,
state
)
{
logme
(
'We are inside Sliders function.'
);
logme
(
'gstId: '
+
gstId
);
logme
(
config
);
logme
(
state
);
// We will go through all of the sliders. For each one, we will make a
// We will go through all of the sliders. For each one, we will make a
// jQuery UI slider for it, attach "on change" events, and set it's
// jQuery UI slider for it, attach "on change" events, and set it's
// state - initial value, max, and min parameters.
// state - initial value, max, and min parameters.
...
@@ -102,12 +96,8 @@ define('Sliders', ['logme'], function (logme) {
...
@@ -102,12 +96,8 @@ define('Sliders', ['logme'], function (logme) {
// The default slider width.
// The default slider width.
sliderWidth
=
400
;
sliderWidth
=
400
;
logme
(
'width: 0'
);
logme
(
obj
[
'@width'
]);
if
(
typeof
obj
[
'@width'
]
===
'string'
)
{
if
(
typeof
obj
[
'@width'
]
===
'string'
)
{
logme
(
'width: 1'
);
if
(
isNaN
(
parseInt
(
obj
[
'@width'
],
10
))
===
false
)
{
if
(
isNaN
(
parseInt
(
obj
[
'@width'
],
10
))
===
false
)
{
logme
(
'width: 2'
);
sliderWidth
=
parseInt
(
obj
[
'@width'
],
10
);
sliderWidth
=
parseInt
(
obj
[
'@width'
],
10
);
}
}
}
}
...
...
common/lib/xmodule/xmodule/js/src/graphical_slider_tool/state.js
View file @
32c70a52
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
// define() functions from Require JS available inside the anonymous function.
// define() functions from Require JS available inside the anonymous function.
(
function
(
requirejs
,
require
,
define
)
{
(
function
(
requirejs
,
require
,
define
)
{
define
(
'State'
,
[
'logme'
],
function
(
logme
)
{
define
(
'State'
,
[
],
function
(
)
{
// Since there will be (can be) multiple GST on a page, and each will have
// Since there will be (can be) multiple GST on a page, and each will have
// a separate state, we will create a factory constructor function. The
// a separate state, we will create a factory constructor function. The
// constructor will expect the ID of the DIV with the GST contents, and the
// constructor will expect the ID of the DIV with the GST contents, and the
...
@@ -56,16 +56,40 @@ define('State', ['logme'], function (logme) {
...
@@ -56,16 +56,40 @@ define('State', ['logme'], function (logme) {
}
}
}
}
logme
(
constants
);
// The constructor will return an object with methods to operate on
// The constructor will return an object with methods to operate on
// it's private properties.
// it's private properties.
return
{
return
{
'getConstValue'
:
getConstValue
,
'getConstValue'
:
getConstValue
,
'setConstValue'
:
setConstValue
,
'setConstValue'
:
setConstValue
,
'bindUpdatePlotEvent'
:
bindUpdatePlotEvent
'bindUpdatePlotEvent'
:
bindUpdatePlotEvent
,
'getAllConstantNames'
:
getAllConstantNames
,
'getAllConstantValues'
:
getAllConstantValues
};
};
function
getAllConstantNames
()
{
var
constName
,
allConstNames
;
allConstNames
=
[];
for
(
constName
in
constants
)
{
allConstNames
.
push
(
constName
);
}
return
allConstNames
;
}
function
getAllConstantValues
()
{
var
constName
,
allConstValues
;
allConstValues
=
[];
for
(
constName
in
constants
)
{
allConstValues
.
push
(
constants
[
constName
]);
}
return
allConstValues
;
}
function
bindUpdatePlotEvent
(
newPlotDiv
,
callback
)
{
function
bindUpdatePlotEvent
(
newPlotDiv
,
callback
)
{
plotDiv
=
newPlotDiv
;
plotDiv
=
newPlotDiv
;
...
@@ -96,8 +120,6 @@ define('State', ['logme'], function (logme) {
...
@@ -96,8 +120,6 @@ define('State', ['logme'], function (logme) {
constants
[
constName
]
=
parseFloat
(
constValue
);
constants
[
constName
]
=
parseFloat
(
constValue
);
logme
(
'From setConstValue: new value for "'
+
constName
+
'" is '
+
constValue
);
if
(
plotDiv
!==
undefined
)
{
if
(
plotDiv
!==
undefined
)
{
plotDiv
.
trigger
(
'update_plot'
);
plotDiv
.
trigger
(
'update_plot'
);
}
}
...
...
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