1717* - src: an optional filename or pathname of an image for background
1818*=== Methods ===
1919*
20+ *=== Focus area indices ===
21+ * an example of 3x3 divided focus area
22+ * _|1|2|3|
23+ * 1|x|x|x|
24+ * 2|x|x|x|
25+ * 3|x|x|x|
2026*/
2127//============================================================================
2228function dataMappingGuide ( canvas , src ) {
@@ -36,8 +42,8 @@ function dataMappingGuide(canvas,src){
3642 X :+ 1 ,
3743 Y :+ 1 ,
3844 /*rgb color and alpha value*/
39- color :'#f00 ' ,
40- alpha :+ 0.25
45+ color :'#000 ' ,
46+ alpha :+ 1.0
4147 } ;
4248 //default background image
4349 cvs . img = ! src ?'none' :src ;
@@ -53,6 +59,8 @@ function dataMappingGuide(canvas,src){
5359 canvas . style . backgroundRepeat = 'no-repeat' ;
5460 canvas . style . backgroundImage = ! src ?'none' :'url(' + src + ')' ;
5561 //sizes and focus area sizes
62+ w = ! w ?100 :w ;
63+ h = ! h ?100 :h ;
5664 canvas . width = + w ;
5765 canvas . height = + h ;
5866 cvs . dw = + w / cvs . Nx ;
@@ -63,6 +71,8 @@ function dataMappingGuide(canvas,src){
6371 cvs . setDivisions = function ( x , y ) {
6472 // - x: a number of horizontal division
6573 // - y: a number of vertical division
74+ x = ! x ?1 :x ;
75+ y = ! y ?1 :y ;
6676 cvs . Nx = + x < 1 ?+ 1 :Math . floor ( + x ) ;
6777 cvs . Ny = + y < 1 ?+ 1 :Math . floor ( + y ) ;
6878 cvs . dw = + canvas . width / cvs . Nx ;
@@ -94,11 +104,23 @@ function dataMappingGuide(canvas,src){
94104 ctx . clearRect ( 0 , 0 , canvas . width , canvas . height ) ;
95105 ctx . globalAlpha = cvs . alpha ;
96106 ctx . fillStyle = cvs . color ;
107+ ctx . strokeStyle = cvs . color ;
108+ ctx . lineWidth = 1.0 ;
97109 //vertical area
98110 ctx . fillRect ( ( cvs . X - 1 ) * cvs . dw , 0 , cvs . dw , canvas . height ) ;
99111 //horizontal area
100112 ctx . fillRect ( 0 , ( cvs . Y - 1 ) * cvs . dh , canvas . width , cvs . dh ) ;
113+ //focus area
101114 ctx . clearRect ( ( cvs . X - 1 ) * cvs . dw , ( cvs . Y - 1 ) * cvs . dh , cvs . dw , cvs . dh ) ;
115+ ctx . beginPath ( ) ;
116+ //(X-1)*dx+dx/2=dx*(2*X-1)/2
117+ //horizontal line
118+ ctx . moveTo ( ( cvs . X - 1 ) * cvs . dw , cvs . dh * ( 2 * cvs . Y - 1 ) / 2 ) ;
119+ ctx . lineTo ( cvs . X * cvs . dw , cvs . dh * ( 2 * cvs . Y - 1 ) / 2 ) ;
120+ //vertical line
121+ ctx . moveTo ( cvs . dw * ( 2 * cvs . X - 1 ) / 2 , ( cvs . Y - 1 ) * cvs . dh ) ;
122+ ctx . lineTo ( cvs . dw * ( 2 * cvs . X - 1 ) / 2 , cvs . Y * cvs . dh ) ;
123+ ctx . stroke ( ) ;
102124 ctx = null ;
103125 return [ cvs . X , cvs . Y ] ;
104126 } ;
0 commit comments