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
3e46ecef
Commit
3e46ecef
authored
Dec 11, 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
28f49219
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
108 additions
and
118 deletions
+108
-118
common/lib/xmodule/xmodule/js/src/graphical_slider_tool/graph.js
+104
-28
common/lib/xmodule/xmodule/js/src/graphical_slider_tool/gst_main.js
+4
-0
common/static/js/graphical_slider_tool/gst_module.js
+0
-15
common/static/js/graphical_slider_tool/main.js
+0
-75
No files found.
common/lib/xmodule/xmodule/js/src/graphical_slider_tool/graph.js
View file @
3e46ecef
...
...
@@ -7,7 +7,7 @@ define('Graph', ['logme'], function (logme) {
return
Graph
;
function
Graph
(
gstId
,
config
,
state
)
{
var
plotDiv
,
dataSe
t
s
,
functions
;
var
plotDiv
,
dataSe
rie
s
,
functions
;
logme
(
config
);
...
...
@@ -39,37 +39,55 @@ define('Graph', ['logme'], function (logme) {
}
if
(
typeof
config
.
plot
[
'function'
]
===
'string'
)
{
// If just one function string is present.
addFunction
(
config
.
plot
[
'function'
]);
}
else
if
(
$
.
isPlainObject
(
config
.
plot
[
'function'
])
===
true
)
{
addFunction
(
config
.
plot
[
'function'
][
'#text'
],
config
.
plot
[
'function'
][
'@color'
],
config
.
plot
[
'function'
][
'@dot'
],
config
.
plot
[
'function'
][
'@label'
],
config
.
plot
[
'function'
][
'@line'
],
config
.
plot
[
'function'
][
'@point_size'
],
config
.
plot
[
'function'
][
'@style'
]
);
// If a function is present, but it also has properties
// defined.
callAddFunction
(
config
.
plot
[
'function'
]);
}
else
if
(
$
.
isArray
(
config
.
plot
[
'function'
]))
{
// If more than one function is defined.
for
(
c1
=
0
;
c1
<
config
.
plot
[
'function'
].
length
;
c1
++
)
{
// For each definition, we must check if it is a simple
// string definition, or a complex one with properties.
if
(
typeof
config
.
plot
[
'function'
][
c1
]
===
'string'
)
{
// Simple string.
addFunction
(
config
.
plot
[
'function'
][
c1
]);
}
else
if
(
$
.
isPlainObject
(
config
.
plot
[
'function'
][
c1
]))
{
addFunction
(
config
.
plot
[
'function'
][
c1
][
'#text'
],
config
.
plot
[
'function'
][
c1
][
'@color'
],
config
.
plot
[
'function'
][
c1
][
'@dot'
],
config
.
plot
[
'function'
][
c1
][
'@label'
],
config
.
plot
[
'function'
][
c1
][
'@line'
],
config
.
plot
[
'function'
][
c1
][
'@point_size'
],
config
.
plot
[
'function'
][
c1
][
'@style'
]
);
// Properties are present.
callAddFunction
(
config
.
plot
[
'function'
][
c1
]);
}
}
}
return
;
// This function will reduce code duplications. We have to call
// the function addFunction() several times passing object
// properties. A parameters. Rather than writing them out every
// time, we will have a single point of
function
callAddFunction
(
obj
)
{
addFunction
(
obj
[
'#text'
],
obj
[
'@color'
],
obj
[
'@line'
],
obj
[
'@dot'
],
obj
[
'@label'
],
obj
[
'@style'
],
obj
[
'@point_size'
]
);
}
function
addFunction
(
funcString
,
color
,
line
,
dot
,
label
,
style
,
point_size
)
{
var
newFunctionObject
,
func
,
constNames
;
...
...
@@ -95,7 +113,7 @@ define('Graph', ['logme'], function (logme) {
newFunctionObject
[
'color'
]
=
color
;
}
if
(
typeof
line
===
'boolean'
)
{
if
(
(
typeof
line
===
'boolean'
)
||
(
typeof
line
===
'string'
)
)
{
if
((
line
===
'true'
)
||
(
line
===
true
))
{
newFunctionObject
[
'line'
]
=
true
;
}
else
{
...
...
@@ -111,6 +129,9 @@ define('Graph', ['logme'], function (logme) {
}
}
// By default, if no preference was set, or if the preference
// is conflicting (we must have either line or dot, none is
// not an option), we will show line.
if
((
newFunctionObject
[
'dot'
]
===
false
)
&&
(
newFunctionObject
[
'line'
]
===
false
))
{
newFunctionObject
[
'line'
]
=
true
;
}
...
...
@@ -131,33 +152,68 @@ define('Graph', ['logme'], function (logme) {
}
function
generateData
()
{
var
c0
,
c1
,
datap
oints
,
constValues
,
x
,
y
;
var
c0
,
c1
,
functionObj
,
seriesObj
,
dataP
oints
,
constValues
,
x
,
y
;
constValues
=
state
.
getAllConstantValues
();
dataSe
t
s
=
[];
dataSe
rie
s
=
[];
for
(
c0
=
0
;
c0
<
functions
.
length
;
c0
+=
1
)
{
datapoints
=
[];
functionObj
=
functions
[
c0
];
logme
(
'Functions obj:'
,
functionObj
);
seriesObj
=
{};
dataPoints
=
[];
for
(
c1
=
0
;
c1
<
30
;
c1
+=
0.
1
)
{
for
(
c1
=
0
;
c1
<
30
;
c1
+=
1
)
{
x
=
c1
;
// Push the 'x' variable to the end of the parameter array.
constValues
.
push
(
x
);
y
=
functions
[
c0
].
func
.
apply
(
window
,
constValues
);
// We call the user defined function, passing all of the
// available constant values. inside this function they
// will be accessible by their names.
y
=
functionObj
.
func
.
apply
(
window
,
constValues
);
// Return the constValues array to how it was before we
// added 'x' variable to the end of it.
constValues
.
pop
();
datapoints
.
push
([
x
,
y
]);
// Add the generated point to the data points set.
dataPoints
.
push
([
x
,
y
]);
}
// Put the entire data points set into the series object.
seriesObj
.
data
=
dataPoints
;
// See if user defined a specific color for this function.
if
(
functionObj
.
hasOwnProperty
(
'color'
)
===
true
)
{
seriesObj
.
color
=
functionObj
.
color
;
}
// See if a user defined a label for this function.
if
(
functionObj
.
hasOwnProperty
(
'label'
)
===
true
)
{
seriesObj
.
label
=
functionObj
.
label
;
}
dataSets
.
push
(
datapoints
);
seriesObj
.
lines
=
{
'show'
:
functionObj
.
line
};
seriesObj
.
points
=
{
'show'
:
functionObj
.
dot
};
dataSeries
.
push
(
seriesObj
);
}
}
function
updatePlot
()
{
$
.
plot
(
plotDiv
,
dataSe
t
s
,
dataSe
rie
s
,
{
'xaxis'
:
{
'min'
:
0
,
...
...
@@ -166,9 +222,29 @@ define('Graph', ['logme'], function (logme) {
'yaxis'
:
{
'min'
:
-
5
,
'max'
:
5
},
'legend'
:
{
// To show the legend or not. Note, even if 'show' is
// 'true', the legend will only show if labels are
// provided for at least one of the series that are
// going to be plotted.
'show'
:
true
,
// A floating point number in the range [0, 1]. The
// smaller the number, the more transparent will the
// legend background become.
'backgroundOpacity'
:
0
}
}
);
MathJax
.
Hub
.
Queue
([
'Typeset'
,
MathJax
.
Hub
,
plotDiv
.
attr
(
'id'
)
]);
}
}
});
...
...
common/lib/xmodule/xmodule/js/src/graphical_slider_tool/gst_main.js
View file @
3e46ecef
...
...
@@ -4,6 +4,10 @@
define
(
'GstMain'
,
// Even though it is not explicitly in this module, we have to specify
// 'GeneralMethods' as a dependency. It expands some of the core JS objects
// with additional useful methods that are used in other modules.
[
'State'
,
'GeneralMethods'
,
'Sliders'
,
'Inputs'
,
'Graph'
],
function
(
State
,
GeneralMethods
,
Sliders
,
Inputs
,
Graph
)
{
...
...
common/static/js/graphical_slider_tool/gst_module.js
deleted
100644 → 0
View file @
28f49219
// Wrapper for RequireJS. It will make the standard requirejs(), require(), and
// define() functions from Require JS available inside the anonymous function.
(
function
(
requirejs
,
require
,
define
)
{
define
([],
function
()
{
return
{
'module_status'
:
'OK'
};
});
// End of wrapper for RequireJS. As you can see, we are passing
// namespaced Require JS variables to an anonymous function. Within
// it, you can use the standard requirejs(), require(), and define()
// functions as if they were in the global namespace.
}(
RequireJS
.
requirejs
,
RequireJS
.
require
,
RequireJS
.
define
));
// End-of: (function (requirejs, require, define)
common/static/js/graphical_slider_tool/main.js
deleted
100644 → 0
View file @
28f49219
// Wrapper for RequireJS. It will make the standard requirejs(), require(), and
// define() functions from Require JS available inside the anonymous function.
(
function
(
requirejs
,
require
,
define
)
{
// For documentation please check:
// http://requirejs.org/docs/api.html
requirejs
.
config
({
// Because require.js is included as a simple <script> tag (and is
// forcefully namespaced) it does not get it's configuration from a
// predefined 'data-main' attribute. Therefore, from the start, it assumes
// that the 'baseUrl' is the same directory that require.js itself is
// contained in - i.e. in '/static/js/vendor'. So, we must specify a
// correct 'baseUrl'.
//
// Require JS initially searches this directory for all of the specified
// dependencies. If the dependency is
//
// 'sylvester'
//
// then it will try to get it from
//
// baseUrl + '/' + 'sylvester' + '.js'
//
// If the dependency is
//
// 'vendor_libs/sylvester'
//
// then it will try to get it from
//
// baseUrl + '/' + 'vendor_libs/sylvester' + '.js'
//
// This means two things. One - you can use sub-folders to separate your
// code. Two - don't include the '.js' suffix when specifying a dependency.
//
// For documentation please check:
// http://requirejs.org/docs/api.html#config-baseUrl
'baseUrl'
:
'/static/js/graphical_slider_tool'
,
// If you need to load from another path, you can specify it here on a
// per-module basis. For example you can specify CDN sources here, or
// absolute paths that lie outside of the 'baseUrl' directory.
//
// For documentation please check:
// http://requirejs.org/docs/api.html#config-paths
'paths'
:
{
},
// Since all of the modules that we require are not aware of our custom
// RequireJS solution, that means all of them will be working in the
// "old mode". I.e. they will populate the global namespace with their
// module object.
//
// For each module that we will use, we will specify what is exports into
// the global namespace, and, if necessary, other modules that it depends.
// on. Module dependencies (downloading them, inserting into the document,
// etc.) are handled by RequireJS.
//
// For documentation please check:
// http://requirejs.org/docs/api.html#config-shim
'shim'
:
{
}
});
// End-of: requirejs.config({
// Start the main app logic.
requirejs
([
'gst_module'
],
function
(
GstModule
)
{
console
.
log
(
GstModule
);
});
// End-of: requirejs(['gst_module'], function (GstModule)
// End of wrapper for RequireJS. As you can see, we are passing
// namespaced Require JS variables to an anonymous function. Within
// it, you can use the standard requirejs(), require(), and define()
// functions as if they were in the global namespace.
}(
RequireJS
.
requirejs
,
RequireJS
.
require
,
RequireJS
.
define
));
// End-of: (function (requirejs, require, define)
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