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
5ab1abf5
Commit
5ab1abf5
authored
Dec 18, 2012
by
Valera Rozuvan
Committed by
Alexander Kryklia
Jan 15, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Debug info for GST.
parent
f0ec3928
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
36 deletions
+67
-36
common/lib/xmodule/xmodule/js/src/graphical_slider_tool/graph.js
+59
-35
common/lib/xmodule/xmodule/js/src/graphical_slider_tool/state.js
+8
-1
No files found.
common/lib/xmodule/xmodule/js/src/graphical_slider_tool/graph.js
View file @
5ab1abf5
...
@@ -7,17 +7,26 @@ define('Graph', ['logme'], function (logme) {
...
@@ -7,17 +7,26 @@ define('Graph', ['logme'], function (logme) {
return
Graph
;
return
Graph
;
function
Graph
(
gstId
,
config
,
state
)
{
function
Graph
(
gstId
,
config
,
state
)
{
var
plotDiv
,
dataSeries
,
functions
,
xaxis
,
yaxis
,
xrange
;
var
plotDiv
,
dataSeries
,
functions
,
xaxis
,
yaxis
,
numPoints
,
xrange
;
// We must have a graph container DIV element available in order to
// We must have a graph container DIV element available in order to
// proceed.
// proceed.
plotDiv
=
$
(
'#'
+
gstId
+
'_plot'
);
plotDiv
=
$
(
'#'
+
gstId
+
'_plot'
);
if
(
plotDiv
.
length
===
0
)
{
if
(
plotDiv
.
length
===
0
)
{
logme
(
'ERROR: Could not find the plot DIV with ID "'
+
gstId
+
'_plot".'
);
return
;
return
;
}
}
if
(
plotDiv
.
width
()
===
0
)
{
plotDiv
.
width
(
300
);
}
if
(
plotDiv
.
height
()
===
0
)
{
plotDiv
.
height
(
plotDiv
.
width
());
}
// Configure some settings for the graph.
// Configure some settings for the graph.
setGraphDimensions
();
setGraphAxes
();
setGraphAxes
();
setGraphXRange
();
setGraphXRange
();
...
@@ -25,6 +34,8 @@ define('Graph', ['logme'], function (logme) {
...
@@ -25,6 +34,8 @@ define('Graph', ['logme'], function (logme) {
// anything else.
// anything else.
createFunctions
();
createFunctions
();
if
(
functions
.
length
===
0
)
{
if
(
functions
.
length
===
0
)
{
logme
(
'ERROR: No functions were specified, or something went wrong.'
);
return
;
return
;
}
}
...
@@ -38,34 +49,6 @@ define('Graph', ['logme'], function (logme) {
...
@@ -38,34 +49,6 @@ define('Graph', ['logme'], function (logme) {
return
;
return
;
function
setGraphDimensions
()
{
var
dimObj
,
width
,
height
,
tempInt
;
// If no dimensions are specified by the user, the graph will have
// predefined dimensions.
width
=
300
;
height
=
300
;
// Get the user specified dimensions, if any.
if
(
$
.
isPlainObject
(
config
.
plot
[
'dimensions'
])
===
true
)
{
dimObj
=
config
.
plot
[
'dimensions'
];
tempInt
=
parseInt
(
dimObj
[
'@width'
],
10
);
if
(
isNaN
(
tempInt
)
===
false
)
{
width
=
tempInt
;
}
tempInt
=
parseInt
(
dimObj
[
'@height'
],
10
);
if
(
isNaN
(
tempInt
)
===
false
)
{
height
=
tempInt
;
}
}
// Apply the dimensions to the graph container DIV element.
plotDiv
.
width
(
width
);
plotDiv
.
height
(
height
);
}
function
setGraphAxes
()
{
function
setGraphAxes
()
{
// Define the xaxis Flot configuration, and then see if the user
// Define the xaxis Flot configuration, and then see if the user
// supplied custom values.
// supplied custom values.
...
@@ -76,6 +59,8 @@ define('Graph', ['logme'], function (logme) {
...
@@ -76,6 +59,8 @@ define('Graph', ['logme'], function (logme) {
};
};
if
(
typeof
config
.
plot
[
'xticks'
]
===
'string'
)
{
if
(
typeof
config
.
plot
[
'xticks'
]
===
'string'
)
{
processTicks
(
config
.
plot
[
'xticks'
],
xaxis
);
processTicks
(
config
.
plot
[
'xticks'
],
xaxis
);
}
else
{
logme
(
'MESSAGE: "xticks" were not specified. Using defaults.'
);
}
}
// Define the yaxis Flot configuration, and then see if the user
// Define the yaxis Flot configuration, and then see if the user
...
@@ -87,6 +72,8 @@ define('Graph', ['logme'], function (logme) {
...
@@ -87,6 +72,8 @@ define('Graph', ['logme'], function (logme) {
};
};
if
(
typeof
config
.
plot
[
'yticks'
]
===
'string'
)
{
if
(
typeof
config
.
plot
[
'yticks'
]
===
'string'
)
{
processTicks
(
config
.
plot
[
'yticks'
],
yaxis
);
processTicks
(
config
.
plot
[
'yticks'
],
yaxis
);
}
else
{
logme
(
'MESSAGE: "yticks" were not specified. Using defaults.'
);
}
}
return
;
return
;
...
@@ -99,27 +86,37 @@ define('Graph', ['logme'], function (logme) {
...
@@ -99,27 +86,37 @@ define('Graph', ['logme'], function (logme) {
ticksBlobs
=
ticksStr
.
split
(
','
);
ticksBlobs
=
ticksStr
.
split
(
','
);
if
(
ticksBlobs
.
length
!==
3
)
{
if
(
ticksBlobs
.
length
!==
3
)
{
logme
(
'ERROR: Did not get 3 blobs from ticksStr = "'
+
ticksStr
+
'".'
);
return
;
return
;
}
}
tempFloat
=
parseFloat
(
ticksBlobs
[
0
]);
tempFloat
=
parseFloat
(
ticksBlobs
[
0
]);
if
(
isNaN
(
tempFloat
)
===
false
)
{
if
(
isNaN
(
tempFloat
)
===
false
)
{
ticksObj
.
min
=
tempFloat
;
ticksObj
.
min
=
tempFloat
;
}
else
{
logme
(
'ERROR: Invalid "min". ticksBlobs[0] = '
,
ticksBlobs
[
0
]);
}
}
tempFloat
=
parseFloat
(
ticksBlobs
[
1
]);
tempFloat
=
parseFloat
(
ticksBlobs
[
1
]);
if
(
isNaN
(
tempFloat
)
===
false
)
{
if
(
isNaN
(
tempFloat
)
===
false
)
{
ticksObj
.
tickSize
=
tempFloat
;
ticksObj
.
tickSize
=
tempFloat
;
}
else
{
logme
(
'ERROR: Invalid "tickSize". ticksBlobs[1] = '
,
ticksBlobs
[
1
]);
}
}
tempFloat
=
parseFloat
(
ticksBlobs
[
2
]);
tempFloat
=
parseFloat
(
ticksBlobs
[
2
]);
if
(
isNaN
(
tempFloat
)
===
false
)
{
if
(
isNaN
(
tempFloat
)
===
false
)
{
ticksObj
.
max
=
tempFloat
;
ticksObj
.
max
=
tempFloat
;
}
else
{
logme
(
'ERROR: Invalid "max". ticksBlobs[2] = '
,
ticksBlobs
[
2
]);
}
}
// Is the starting tick to the left of the ending tick (on the
// Is the starting tick to the left of the ending tick (on the
// x-axis)? If not, set default starting and ending tick.
// x-axis)? If not, set default starting and ending tick.
if
(
ticksObj
.
min
>=
ticksObj
.
max
)
{
if
(
ticksObj
.
min
>=
ticksObj
.
max
)
{
logme
(
'ERROR: min >= max. Setting defaults.'
);
ticksObj
.
min
=
0
;
ticksObj
.
min
=
0
;
ticksObj
.
max
=
10
;
ticksObj
.
max
=
10
;
}
}
...
@@ -128,6 +125,8 @@ define('Graph', ['logme'], function (logme) {
...
@@ -128,6 +125,8 @@ define('Graph', ['logme'], function (logme) {
// least 3 ticks. If not, set a tickSize which will produce
// least 3 ticks. If not, set a tickSize which will produce
// 11 ticks. tickSize is the spacing between the ticks.
// 11 ticks. tickSize is the spacing between the ticks.
if
(
ticksObj
.
tickSize
*
2
>=
ticksObj
.
max
-
ticksObj
.
min
)
{
if
(
ticksObj
.
tickSize
*
2
>=
ticksObj
.
max
-
ticksObj
.
min
)
{
logme
(
'ERROR: tickSize * 2 >= max - min. Setting defaults.'
);
ticksObj
.
tickSize
=
(
ticksObj
.
max
-
ticksObj
.
min
)
/
10.0
;
ticksObj
.
tickSize
=
(
ticksObj
.
max
-
ticksObj
.
min
)
/
10.0
;
}
}
}
}
...
@@ -170,10 +169,10 @@ define('Graph', ['logme'], function (logme) {
...
@@ -170,10 +169,10 @@ define('Graph', ['logme'], function (logme) {
}
}
}
else
{
}
else
{
logme
(
'ERROR: xrange does not contain 2 blobs.
'
);
logme
(
'ERROR: xrange does not contain 2 blobs.
xRangeBlobs.length = '
+
xRangeBlobs
.
length
);
}
}
}
else
{
}
else
{
logme
(
'ERROR: xrange is not a string.
'
);
logme
(
'ERROR: xrange is not a string.
config.plot["xrange"] = '
,
config
.
plot
[
'xrange'
]
);
}
}
// The user can specify the number of points. However, internally
// The user can specify the number of points. However, internally
...
@@ -184,9 +183,10 @@ define('Graph', ['logme'], function (logme) {
...
@@ -184,9 +183,10 @@ define('Graph', ['logme'], function (logme) {
if
(
if
(
(
isNaN
(
tempNum
)
===
false
)
||
(
isNaN
(
tempNum
)
===
false
)
||
(
tempNum
>=
2
)
&&
(
tempNum
>=
2
)
&&
(
tempNum
<=
5
00
)
(
tempNum
<=
10
00
)
)
{
)
{
xrange
.
step
=
(
xrange
.
end
-
xrange
.
start
)
/
(
tempNum
-
1
);
numPoints
=
tempNum
;
xrange
.
step
=
(
xrange
.
end
-
xrange
.
start
)
/
(
numPoints
-
1
);
}
else
{
}
else
{
logme
(
'ERROR: num_points was not parsed as a number, or num_points < 2, or num_points > 500.'
);
logme
(
'ERROR: num_points was not parsed as a number, or num_points < 2, or num_points > 500.'
);
}
}
...
@@ -201,6 +201,8 @@ define('Graph', ['logme'], function (logme) {
...
@@ -201,6 +201,8 @@ define('Graph', ['logme'], function (logme) {
functions
=
[];
functions
=
[];
if
(
typeof
config
.
plot
[
'function'
]
===
'undefined'
)
{
if
(
typeof
config
.
plot
[
'function'
]
===
'undefined'
)
{
logme
(
'ERROR: config.plot["function"] is undefined.'
);
return
;
return
;
}
}
...
@@ -234,6 +236,10 @@ define('Graph', ['logme'], function (logme) {
...
@@ -234,6 +236,10 @@ define('Graph', ['logme'], function (logme) {
}
}
}
}
}
else
{
logme
(
'ERROR: config.plot["function"] is of an unsupported type.'
);
return
;
}
}
return
;
return
;
...
@@ -348,7 +354,7 @@ define('Graph', ['logme'], function (logme) {
...
@@ -348,7 +354,7 @@ define('Graph', ['logme'], function (logme) {
}
}
function
generateData
()
{
function
generateData
()
{
var
c0
,
functionObj
,
seriesObj
,
dataPoints
,
paramValues
,
x
,
y
;
var
c0
,
c1
,
functionObj
,
seriesObj
,
dataPoints
,
paramValues
,
x
,
y
;
paramValues
=
state
.
getAllParameterValues
();
paramValues
=
state
.
getAllParameterValues
();
...
@@ -360,6 +366,11 @@ define('Graph', ['logme'], function (logme) {
...
@@ -360,6 +366,11 @@ define('Graph', ['logme'], function (logme) {
seriesObj
=
{};
seriesObj
=
{};
dataPoints
=
[];
dataPoints
=
[];
// For counting number of points added. In the end we will
// compare this number to 'numPoints' specified in the config
// JSON.
c1
=
0
;
// Generate the data points.
// Generate the data points.
for
(
x
=
xrange
.
start
;
x
<=
xrange
.
end
;
x
+=
xrange
.
step
)
{
for
(
x
=
xrange
.
start
;
x
<=
xrange
.
end
;
x
+=
xrange
.
step
)
{
...
@@ -378,6 +389,19 @@ define('Graph', ['logme'], function (logme) {
...
@@ -378,6 +389,19 @@ define('Graph', ['logme'], function (logme) {
// Add the generated point to the data points set.
// Add the generated point to the data points set.
dataPoints
.
push
([
x
,
y
]);
dataPoints
.
push
([
x
,
y
]);
c1
+=
1
;
}
// If the last point did not get included because of rounding
// of floating-point number addition, then we will include it
// manually.
if
(
c1
!=
numPoints
)
{
x
=
xrange
.
end
;
paramValues
.
push
(
x
);
y
=
functionObj
.
func
.
apply
(
window
,
paramValues
);
paramValues
.
pop
();
dataPoints
.
push
([
x
,
y
]);
}
}
// Put the entire data points set into the series object.
// Put the entire data points set into the series object.
...
...
common/lib/xmodule/xmodule/js/src/graphical_slider_tool/state.js
View file @
5ab1abf5
...
@@ -3,12 +3,16 @@
...
@@ -3,12 +3,16 @@
(
function
(
requirejs
,
require
,
define
)
{
(
function
(
requirejs
,
require
,
define
)
{
define
(
'State'
,
[
'logme'
],
function
(
logme
)
{
define
(
'State'
,
[
'logme'
],
function
(
logme
)
{
var
stateInst
;
// 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
// configuration object (parsed from a JSON string). It will return an
// configuration object (parsed from a JSON string). It will return an
// object containing methods to set and get the private state properties.
// object containing methods to set and get the private state properties.
stateInst
=
0
;
// This module defines and returns a factory constructor.
// This module defines and returns a factory constructor.
return
State
;
return
State
;
...
@@ -16,6 +20,9 @@ define('State', ['logme'], function (logme) {
...
@@ -16,6 +20,9 @@ define('State', ['logme'], function (logme) {
var
parameters
,
allParameterNames
,
allParameterValues
,
var
parameters
,
allParameterNames
,
allParameterValues
,
plotDiv
;
plotDiv
;
stateInst
+=
1
;
logme
(
'MESSAGE: Creating state instance # '
+
stateInst
+
'.'
);
// Initially, there are no parameters to track. So, we will instantiate
// Initially, there are no parameters to track. So, we will instantiate
// an empty object.
// an empty object.
//
//
...
@@ -48,7 +55,7 @@ define('State', ['logme'], function (logme) {
...
@@ -48,7 +55,7 @@ define('State', ['logme'], function (logme) {
// If config.parameters.param is an object, pass this object to the
// If config.parameters.param is an object, pass this object to the
// processor directly.
// processor directly.
else
if
(
$
.
isPlainObject
(
config
.
inputs
.
input
)
===
true
)
{
else
if
(
$
.
isPlainObject
(
config
.
parameters
.
param
)
===
true
)
{
processParameter
(
config
.
parameters
.
param
);
processParameter
(
config
.
parameters
.
param
);
}
}
...
...
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