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
2b5e55b6
Commit
2b5e55b6
authored
Oct 31, 2012
by
Don Mitchell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use try/catch to detect undefined globals for canvas
parent
6bbe82b6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
68 additions
and
59 deletions
+68
-59
common/lib/xmodule/xmodule/js/src/capa/schematic.js
+68
-59
No files found.
common/lib/xmodule/xmodule/js/src/capa/schematic.js
View file @
2b5e55b6
...
@@ -3339,23 +3339,28 @@ schematic = (function() {
...
@@ -3339,23 +3339,28 @@ schematic = (function() {
}
}
// add method to canvas to compute relative coords for event
// add method to canvas to compute relative coords for event
if
(
HTMLCanvasElement
)
HTMLCanvasElement
.
prototype
.
relMouseCoords
=
function
(
event
){
try
{
// run up the DOM tree to figure out coords for top,left of canvas
if
(
HTMLCanvasElement
)
var
totalOffsetX
=
0
;
HTMLCanvasElement
.
prototype
.
relMouseCoords
=
function
(
event
){
var
totalOffsetY
=
0
;
// run up the DOM tree to figure out coords for top,left of canvas
var
currentElement
=
this
;
var
totalOffsetX
=
0
;
do
{
var
totalOffsetY
=
0
;
totalOffsetX
+=
currentElement
.
offsetLeft
;
var
currentElement
=
this
;
totalOffsetY
+=
currentElement
.
offsetTop
;
do
{
}
totalOffsetX
+=
currentElement
.
offsetLeft
;
while
(
currentElement
=
currentElement
.
offsetParent
);
totalOffsetY
+=
currentElement
.
offsetTop
;
}
// now compute relative position of click within the canvas
while
(
currentElement
=
currentElement
.
offsetParent
);
this
.
mouse_x
=
event
.
pageX
-
totalOffsetX
;
this
.
mouse_y
=
event
.
pageY
-
totalOffsetY
;
// now compute relative position of click within the canvas
this
.
mouse_x
=
event
.
pageX
-
totalOffsetX
;
this
.
page_x
=
event
.
pageX
;
this
.
mouse_y
=
event
.
pageY
-
totalOffsetY
;
this
.
page_y
=
event
.
pageY
;
this
.
page_x
=
event
.
pageX
;
this
.
page_y
=
event
.
pageY
;
}
}
catch
(
err
)
{
// ignore
}
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
...
@@ -4091,48 +4096,52 @@ schematic = (function() {
...
@@ -4091,48 +4096,52 @@ schematic = (function() {
// add dashed lines!
// add dashed lines!
// from http://davidowens.wordpress.com/2010/09/07/html-5-canvas-and-dashed-lines/
// from http://davidowens.wordpress.com/2010/09/07/html-5-canvas-and-dashed-lines/
CanvasRenderingContext2D
.
prototype
.
dashedLineTo
=
function
(
fromX
,
fromY
,
toX
,
toY
,
pattern
)
{
try
{
// Our growth rate for our line can be one of the following:
if
(
CanvasRenderingContext2D
)
// (+,+), (+,-), (-,+), (-,-)
CanvasRenderingContext2D
.
prototype
.
dashedLineTo
=
function
(
fromX
,
fromY
,
toX
,
toY
,
pattern
)
{
// Because of this, our algorithm needs to understand if the x-coord and
// Our growth rate for our line can be one of the following:
// y-coord should be getting smaller or larger and properly cap the values
// (+,+), (+,-), (-,+), (-,-)
// based on (x,y).
// Because of this, our algorithm needs to understand if the x-coord and
var
lt
=
function
(
a
,
b
)
{
return
a
<=
b
;
};
// y-coord should be getting smaller or larger and properly cap the values
var
gt
=
function
(
a
,
b
)
{
return
a
>=
b
;
};
// based on (x,y).
var
capmin
=
function
(
a
,
b
)
{
return
Math
.
min
(
a
,
b
);
};
var
lt
=
function
(
a
,
b
)
{
return
a
<=
b
;
};
var
capmax
=
function
(
a
,
b
)
{
return
Math
.
max
(
a
,
b
);
};
var
gt
=
function
(
a
,
b
)
{
return
a
>=
b
;
};
var
capmin
=
function
(
a
,
b
)
{
return
Math
.
min
(
a
,
b
);
};
var
checkX
=
{
thereYet
:
gt
,
cap
:
capmin
};
var
capmax
=
function
(
a
,
b
)
{
return
Math
.
max
(
a
,
b
);
};
var
checkY
=
{
thereYet
:
gt
,
cap
:
capmin
};
var
checkX
=
{
thereYet
:
gt
,
cap
:
capmin
};
if
(
fromY
-
toY
>
0
)
{
var
checkY
=
{
thereYet
:
gt
,
cap
:
capmin
};
checkY
.
thereYet
=
lt
;
checkY
.
cap
=
capmax
;
if
(
fromY
-
toY
>
0
)
{
}
checkY
.
thereYet
=
lt
;
if
(
fromX
-
toX
>
0
)
{
checkY
.
cap
=
capmax
;
checkX
.
thereYet
=
lt
;
}
checkX
.
cap
=
capmax
;
if
(
fromX
-
toX
>
0
)
{
}
checkX
.
thereYet
=
lt
;
checkX
.
cap
=
capmax
;
this
.
moveTo
(
fromX
,
fromY
);
}
var
offsetX
=
fromX
;
var
offsetY
=
fromY
;
this
.
moveTo
(
fromX
,
fromY
);
var
idx
=
0
,
dash
=
true
;
var
offsetX
=
fromX
;
while
(
!
(
checkX
.
thereYet
(
offsetX
,
toX
)
&&
checkY
.
thereYet
(
offsetY
,
toY
)))
{
var
offsetY
=
fromY
;
var
ang
=
Math
.
atan2
(
toY
-
fromY
,
toX
-
fromX
);
var
idx
=
0
,
dash
=
true
;
var
len
=
pattern
[
idx
];
while
(
!
(
checkX
.
thereYet
(
offsetX
,
toX
)
&&
checkY
.
thereYet
(
offsetY
,
toY
)))
{
var
ang
=
Math
.
atan2
(
toY
-
fromY
,
toX
-
fromX
);
offsetX
=
checkX
.
cap
(
toX
,
offsetX
+
(
Math
.
cos
(
ang
)
*
len
));
var
len
=
pattern
[
idx
];
offsetY
=
checkY
.
cap
(
toY
,
offsetY
+
(
Math
.
sin
(
ang
)
*
len
));
offsetX
=
checkX
.
cap
(
toX
,
offsetX
+
(
Math
.
cos
(
ang
)
*
len
));
if
(
dash
)
this
.
lineTo
(
offsetX
,
offsetY
);
offsetY
=
checkY
.
cap
(
toY
,
offsetY
+
(
Math
.
sin
(
ang
)
*
len
));
else
this
.
moveTo
(
offsetX
,
offsetY
);
if
(
dash
)
this
.
lineTo
(
offsetX
,
offsetY
);
idx
=
(
idx
+
1
)
%
pattern
.
length
;
else
this
.
moveTo
(
offsetX
,
offsetY
);
dash
=
!
dash
;
}
idx
=
(
idx
+
1
)
%
pattern
.
length
;
};
dash
=
!
dash
;
}
};
}
catch
(
err
)
{
//noop
}
// given a range of values, return a new range [vmin',vmax'] where the limits
// given a range of values, return a new range [vmin',vmax'] where the limits
// have been chosen "nicely". Taken from matplotlib.ticker.LinearLocator
// have been chosen "nicely". Taken from matplotlib.ticker.LinearLocator
function
view_limits
(
vmin
,
vmax
)
{
function
view_limits
(
vmin
,
vmax
)
{
...
...
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