5350 |
25 May 10 |
nicklas |
1 |
/********************************************************************************** |
5350 |
25 May 10 |
nicklas |
2 |
* |
5350 |
25 May 10 |
nicklas |
* Project Name: jsDraw2D (Graphics Library for JavaScript) |
5350 |
25 May 10 |
nicklas |
* Version: Beta 1.1.0 (17-August-2009) (Uncompressed) |
5350 |
25 May 10 |
nicklas |
* Project Homepage: http://jsdraw2d.jsfiction.com |
5350 |
25 May 10 |
nicklas |
* Author: Sameer Burle |
5350 |
25 May 10 |
nicklas |
* Copyright 2009: jsFiction.com (http://www.jsfiction.com) |
5350 |
25 May 10 |
nicklas |
* Licensed Under: LGPL |
5350 |
25 May 10 |
nicklas |
9 |
* |
5350 |
25 May 10 |
nicklas |
* This program (library) is free software: you can redistribute it and/or modify |
5350 |
25 May 10 |
nicklas |
* it under the terms of the GNU Lesser General Public License as published by |
5350 |
25 May 10 |
nicklas |
* the Free Software Foundation, either version 3 of the License, or |
5350 |
25 May 10 |
nicklas |
* (at your option) any later version. |
5350 |
25 May 10 |
nicklas |
14 |
* |
5350 |
25 May 10 |
nicklas |
* This program is distributed in the hope that it will be useful, |
5350 |
25 May 10 |
nicklas |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
5350 |
25 May 10 |
nicklas |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5350 |
25 May 10 |
nicklas |
* GNU Lesser General Public License for more details. |
5350 |
25 May 10 |
nicklas |
19 |
* |
5350 |
25 May 10 |
nicklas |
* You should have received a copy of the GNU General Public License |
5350 |
25 May 10 |
nicklas |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
5350 |
25 May 10 |
nicklas |
22 |
* |
5350 |
25 May 10 |
nicklas |
23 |
************************************************************************************/ |
7419 |
03 Nov 17 |
nicklas |
'use strict'; |
5350 |
25 May 10 |
nicklas |
25 |
|
5350 |
25 May 10 |
nicklas |
//jsColor class holds the color information and provides some color related basic functions. |
5350 |
25 May 10 |
nicklas |
function jsColor() |
5350 |
25 May 10 |
nicklas |
28 |
{ |
5350 |
25 May 10 |
nicklas |
//Member variables |
5350 |
25 May 10 |
nicklas |
var hex="#000000"; |
5350 |
25 May 10 |
nicklas |
31 |
|
5350 |
25 May 10 |
nicklas |
switch(arguments.length) |
5350 |
25 May 10 |
nicklas |
33 |
{ |
5350 |
25 May 10 |
nicklas |
//Hexadecimal Color |
5350 |
25 May 10 |
nicklas |
case 1: |
5350 |
25 May 10 |
nicklas |
setHex(arguments[0]); |
5350 |
25 May 10 |
nicklas |
break; |
5350 |
25 May 10 |
nicklas |
//RGB Color |
5350 |
25 May 10 |
nicklas |
case 3: |
5350 |
25 May 10 |
nicklas |
var red=arguments[0]; |
5350 |
25 May 10 |
nicklas |
var green=arguments[1]; |
5350 |
25 May 10 |
nicklas |
var blue=arguments[2]; |
5350 |
25 May 10 |
nicklas |
hex=rgbToHex(red,green,blue); |
5350 |
25 May 10 |
nicklas |
if(hex==false) |
5350 |
25 May 10 |
nicklas |
hex="#000000"; |
5350 |
25 May 10 |
nicklas |
break; |
5350 |
25 May 10 |
nicklas |
47 |
} |
5350 |
25 May 10 |
nicklas |
48 |
|
5350 |
25 May 10 |
nicklas |
//Public Methods |
5350 |
25 May 10 |
nicklas |
50 |
|
5350 |
25 May 10 |
nicklas |
//Set color by specifying the hexa-decimal value. |
5350 |
25 May 10 |
nicklas |
this.setHex=setHex; |
5350 |
25 May 10 |
nicklas |
function setHex(hexColor) |
5350 |
25 May 10 |
nicklas |
54 |
{ |
5350 |
25 May 10 |
nicklas |
if(hexColor.charAt(0)=="#") |
5350 |
25 May 10 |
nicklas |
56 |
{ |
5350 |
25 May 10 |
nicklas |
hex=hexColor; |
5350 |
25 May 10 |
nicklas |
58 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
60 |
{ |
5350 |
25 May 10 |
nicklas |
if(isNaN(hexColor)) |
5350 |
25 May 10 |
nicklas |
62 |
{ |
5350 |
25 May 10 |
nicklas |
setNamedColor(hexColor.toLowerCase()); |
5350 |
25 May 10 |
nicklas |
64 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
66 |
{ |
5350 |
25 May 10 |
nicklas |
hex="#" + hexColor; |
5350 |
25 May 10 |
nicklas |
68 |
} |
5350 |
25 May 10 |
nicklas |
69 |
} |
5350 |
25 May 10 |
nicklas |
70 |
|
5350 |
25 May 10 |
nicklas |
var rgbArray=hexToRgb(hex); |
5350 |
25 May 10 |
nicklas |
if(!rgbArray) |
5350 |
25 May 10 |
nicklas |
73 |
{ |
5350 |
25 May 10 |
nicklas |
hex="#000000" |
5350 |
25 May 10 |
nicklas |
75 |
} |
5350 |
25 May 10 |
nicklas |
76 |
} |
5350 |
25 May 10 |
nicklas |
//Get the hexa-decimal value of the object |
5350 |
25 May 10 |
nicklas |
this.getHex=getHex; |
5350 |
25 May 10 |
nicklas |
function getHex() |
5350 |
25 May 10 |
nicklas |
80 |
{ |
5350 |
25 May 10 |
nicklas |
return hex; |
5350 |
25 May 10 |
nicklas |
82 |
} |
5350 |
25 May 10 |
nicklas |
83 |
|
5350 |
25 May 10 |
nicklas |
//Set color by specifying the RGB values. |
5350 |
25 May 10 |
nicklas |
this.setRGB=setRGB; |
5350 |
25 May 10 |
nicklas |
function setRGB(redValue,greenValue,blueValue) |
5350 |
25 May 10 |
nicklas |
87 |
{ |
5350 |
25 May 10 |
nicklas |
hex=rgbToHex(redValue,greenValue,blueValue); |
5350 |
25 May 10 |
nicklas |
if(hex==false) |
5350 |
25 May 10 |
nicklas |
hex="#000000"; |
5350 |
25 May 10 |
nicklas |
91 |
} |
5350 |
25 May 10 |
nicklas |
92 |
|
5350 |
25 May 10 |
nicklas |
//Get the RGB values of the object |
5350 |
25 May 10 |
nicklas |
this.getRGB=getRGB; |
5350 |
25 May 10 |
nicklas |
function getRGB() |
5350 |
25 May 10 |
nicklas |
96 |
{ |
5350 |
25 May 10 |
nicklas |
return hexToRgb(hex); |
5350 |
25 May 10 |
nicklas |
98 |
} |
5350 |
25 May 10 |
nicklas |
99 |
|
5350 |
25 May 10 |
nicklas |
//Returns new jsColor object with darker color shade |
5350 |
25 May 10 |
nicklas |
this.getDarkerShade=getDarkerShade; |
5350 |
25 May 10 |
nicklas |
function getDarkerShade(value) |
5350 |
25 May 10 |
nicklas |
103 |
{ |
5350 |
25 May 10 |
nicklas |
var redValue,greenValue,blueValue; |
5350 |
25 May 10 |
nicklas |
var resArray=getRGB(); |
5350 |
25 May 10 |
nicklas |
106 |
|
5350 |
25 May 10 |
nicklas |
if(!isNaN(value)) |
5350 |
25 May 10 |
nicklas |
108 |
{ |
5350 |
25 May 10 |
nicklas |
redValue=parseInt(resArray[0]-value); |
5350 |
25 May 10 |
nicklas |
greenValue=parseInt(resArray[1]-value); |
5350 |
25 May 10 |
nicklas |
blueValue=parseInt(resArray[2]-value); |
5350 |
25 May 10 |
nicklas |
112 |
} |
5350 |
25 May 10 |
nicklas |
113 |
|
5350 |
25 May 10 |
nicklas |
if(redValue<0) |
5350 |
25 May 10 |
nicklas |
redValue=0; |
5350 |
25 May 10 |
nicklas |
if(greenValue<0) |
5350 |
25 May 10 |
nicklas |
greenValue=0; |
5350 |
25 May 10 |
nicklas |
if(blueValue<0) |
5350 |
25 May 10 |
nicklas |
blueValue=0; |
5350 |
25 May 10 |
nicklas |
120 |
|
5350 |
25 May 10 |
nicklas |
return new jsColor(redValue,greenValue,blueValue); |
5350 |
25 May 10 |
nicklas |
122 |
} |
5350 |
25 May 10 |
nicklas |
123 |
|
5350 |
25 May 10 |
nicklas |
//Returns new jsColor object with lighter color shade |
5350 |
25 May 10 |
nicklas |
this.getLighterShade=getLighterShade; |
5350 |
25 May 10 |
nicklas |
function getLighterShade(value) |
5350 |
25 May 10 |
nicklas |
127 |
{ |
5350 |
25 May 10 |
nicklas |
var redValue,greenValue,blueValue; |
5350 |
25 May 10 |
nicklas |
var resArray=getRGB(); |
5350 |
25 May 10 |
nicklas |
130 |
|
5350 |
25 May 10 |
nicklas |
if(!isNaN(value)) |
5350 |
25 May 10 |
nicklas |
132 |
{ |
5350 |
25 May 10 |
nicklas |
redValue=parseInt(resArray[0]+value); |
5350 |
25 May 10 |
nicklas |
greenValue=parseInt(resArray[1]+value); |
5350 |
25 May 10 |
nicklas |
blueValue=parseInt(resArray[2]+value); |
5350 |
25 May 10 |
nicklas |
136 |
} |
5350 |
25 May 10 |
nicklas |
137 |
|
5350 |
25 May 10 |
nicklas |
if(redValue>255) |
5350 |
25 May 10 |
nicklas |
redValue=255; |
5350 |
25 May 10 |
nicklas |
if(greenValue>255) |
5350 |
25 May 10 |
nicklas |
greenValue=255; |
5350 |
25 May 10 |
nicklas |
if(blueValue>255) |
5350 |
25 May 10 |
nicklas |
blueValue=255; |
5350 |
25 May 10 |
nicklas |
144 |
|
5350 |
25 May 10 |
nicklas |
return new jsColor(redValue,greenValue,blueValue); |
5350 |
25 May 10 |
nicklas |
146 |
} |
5350 |
25 May 10 |
nicklas |
147 |
|
5350 |
25 May 10 |
nicklas |
//Static-Shared Utility Methods |
5350 |
25 May 10 |
nicklas |
149 |
|
5350 |
25 May 10 |
nicklas |
//Convert RGB color to Hex color |
5350 |
25 May 10 |
nicklas |
this.rgbToHex=rgbToHex; |
5350 |
25 May 10 |
nicklas |
function rgbToHex(redValue, greenValue, blueValue) |
5350 |
25 May 10 |
nicklas |
153 |
{ |
5350 |
25 May 10 |
nicklas |
//Check argument values |
5350 |
25 May 10 |
nicklas |
if(redValue<0 || redValue>255 || greenValue<0 || greenValue>255 || blueValue<0 || blueValue>255) |
5350 |
25 May 10 |
nicklas |
156 |
{ |
5350 |
25 May 10 |
nicklas |
return false; |
5350 |
25 May 10 |
nicklas |
158 |
} |
5350 |
25 May 10 |
nicklas |
159 |
|
5350 |
25 May 10 |
nicklas |
var colorDec = Math.round(blueValue) + 256 * Math.round(greenValue) + 65536 * Math.round(redValue); |
5350 |
25 May 10 |
nicklas |
return "#" + zeroPad(colorDec.toString(16),6); |
5350 |
25 May 10 |
nicklas |
162 |
} |
5350 |
25 May 10 |
nicklas |
163 |
|
5350 |
25 May 10 |
nicklas |
//Convert Hex color to RGB color |
5350 |
25 May 10 |
nicklas |
this.hexToRgb=hexToRgb; |
5350 |
25 May 10 |
nicklas |
function hexToRgb(hexValue) |
5350 |
25 May 10 |
nicklas |
167 |
{ |
5350 |
25 May 10 |
nicklas |
var redValue,greenValue,blueValue; |
5350 |
25 May 10 |
nicklas |
if(hexValue.charAt(0)=="#") |
5350 |
25 May 10 |
nicklas |
170 |
{ |
5350 |
25 May 10 |
nicklas |
hexValue=hexValue.substring(1,7); |
5350 |
25 May 10 |
nicklas |
172 |
} |
5350 |
25 May 10 |
nicklas |
173 |
|
5350 |
25 May 10 |
nicklas |
redValue=parseInt(hexValue.substring(0,2),16); |
5350 |
25 May 10 |
nicklas |
greenValue=parseInt(hexValue.substring(2,4),16); |
5350 |
25 May 10 |
nicklas |
blueValue=parseInt(hexValue.substring(4,6),16); |
5350 |
25 May 10 |
nicklas |
177 |
|
5350 |
25 May 10 |
nicklas |
//Check argument values |
5350 |
25 May 10 |
nicklas |
if(redValue<0 || redValue>255 || greenValue<0 || greenValue>255 || blueValue<0 || blueValue>255) |
5350 |
25 May 10 |
nicklas |
180 |
{ |
5350 |
25 May 10 |
nicklas |
return false; |
5350 |
25 May 10 |
nicklas |
182 |
} |
5350 |
25 May 10 |
nicklas |
183 |
|
5350 |
25 May 10 |
nicklas |
return new Array(redValue,greenValue,blueValue); |
5350 |
25 May 10 |
nicklas |
185 |
} |
5350 |
25 May 10 |
nicklas |
186 |
|
5350 |
25 May 10 |
nicklas |
//Private Methods |
5350 |
25 May 10 |
nicklas |
//Set the color using specified name of the color out of 16 web colors. |
5350 |
25 May 10 |
nicklas |
function setNamedColor(colorName) |
5350 |
25 May 10 |
nicklas |
190 |
{ |
5350 |
25 May 10 |
nicklas |
switch(colorName) |
5350 |
25 May 10 |
nicklas |
192 |
{ |
5350 |
25 May 10 |
nicklas |
case "aqua": |
5350 |
25 May 10 |
nicklas |
hex="#00FFFF"; |
5350 |
25 May 10 |
nicklas |
break; |
5350 |
25 May 10 |
nicklas |
case "black": |
5350 |
25 May 10 |
nicklas |
hex="#000000"; |
5350 |
25 May 10 |
nicklas |
break; |
5350 |
25 May 10 |
nicklas |
case "blue": |
5350 |
25 May 10 |
nicklas |
hex="#0000FF"; |
5350 |
25 May 10 |
nicklas |
break; |
5350 |
25 May 10 |
nicklas |
case "fuchsia": |
5350 |
25 May 10 |
nicklas |
hex="#FF00FF"; |
5350 |
25 May 10 |
nicklas |
break; |
5350 |
25 May 10 |
nicklas |
case "green": |
5350 |
25 May 10 |
nicklas |
hex="#008000"; |
5350 |
25 May 10 |
nicklas |
break; |
5350 |
25 May 10 |
nicklas |
case "gray": |
5350 |
25 May 10 |
nicklas |
hex="#808080"; |
5350 |
25 May 10 |
nicklas |
break; |
5350 |
25 May 10 |
nicklas |
case "lime": |
5350 |
25 May 10 |
nicklas |
hex="#00FF00"; |
5350 |
25 May 10 |
nicklas |
break; |
5350 |
25 May 10 |
nicklas |
case "maroon": |
5350 |
25 May 10 |
nicklas |
hex="#800000"; |
5350 |
25 May 10 |
nicklas |
break; |
5350 |
25 May 10 |
nicklas |
case "navy": |
5350 |
25 May 10 |
nicklas |
hex="#000080"; |
5350 |
25 May 10 |
nicklas |
break; |
5350 |
25 May 10 |
nicklas |
case "olive": |
5350 |
25 May 10 |
nicklas |
hex="#808000"; |
5350 |
25 May 10 |
nicklas |
break; |
5350 |
25 May 10 |
nicklas |
case "purple": |
5350 |
25 May 10 |
nicklas |
hex="#800080"; |
5350 |
25 May 10 |
nicklas |
break; |
5350 |
25 May 10 |
nicklas |
case "red": |
5350 |
25 May 10 |
nicklas |
hex="#FF0000"; |
5350 |
25 May 10 |
nicklas |
break; |
5350 |
25 May 10 |
nicklas |
case "silver": |
5350 |
25 May 10 |
nicklas |
hex="#C0C0C0"; |
5350 |
25 May 10 |
nicklas |
break; |
5350 |
25 May 10 |
nicklas |
case "teal": |
5350 |
25 May 10 |
nicklas |
hex="#008080"; |
5350 |
25 May 10 |
nicklas |
break; |
5350 |
25 May 10 |
nicklas |
case "white": |
5350 |
25 May 10 |
nicklas |
hex="#FFFFFF"; |
5350 |
25 May 10 |
nicklas |
break; |
5350 |
25 May 10 |
nicklas |
case "yellow": |
5350 |
25 May 10 |
nicklas |
hex="#FFFF00"; |
5350 |
25 May 10 |
nicklas |
break; |
5350 |
25 May 10 |
nicklas |
241 |
} |
5350 |
25 May 10 |
nicklas |
242 |
} |
5350 |
25 May 10 |
nicklas |
243 |
|
5350 |
25 May 10 |
nicklas |
//Add zero padding to the left. Used for building hexa-decimal string. |
5350 |
25 May 10 |
nicklas |
function zeroPad(val,count) |
5350 |
25 May 10 |
nicklas |
246 |
{ |
5350 |
25 May 10 |
nicklas |
var valZeropad = val + ""; |
5350 |
25 May 10 |
nicklas |
while(valZeropad.length < count) |
5350 |
25 May 10 |
nicklas |
249 |
{ |
5350 |
25 May 10 |
nicklas |
valZeropad = "0" + valZeropad; |
5350 |
25 May 10 |
nicklas |
251 |
} |
5350 |
25 May 10 |
nicklas |
return valZeropad; |
5350 |
25 May 10 |
nicklas |
253 |
} |
5350 |
25 May 10 |
nicklas |
254 |
|
5350 |
25 May 10 |
nicklas |
255 |
} |
5350 |
25 May 10 |
nicklas |
256 |
|
5350 |
25 May 10 |
nicklas |
//jsFont class holds the font information which can be used by other objects in object oriented way. |
5350 |
25 May 10 |
nicklas |
function jsFont(family,weight,size,style,variant) |
5350 |
25 May 10 |
nicklas |
259 |
{ |
5350 |
25 May 10 |
nicklas |
//Properties: family, weight, size, style and varient with default value null |
5350 |
25 May 10 |
nicklas |
this.family=null; |
5350 |
25 May 10 |
nicklas |
this.weight=null; |
5350 |
25 May 10 |
nicklas |
this.size=null; |
5350 |
25 May 10 |
nicklas |
this.style=null; |
5350 |
25 May 10 |
nicklas |
this.variant=null; |
5350 |
25 May 10 |
nicklas |
266 |
|
5350 |
25 May 10 |
nicklas |
if(family && family!="") |
5350 |
25 May 10 |
nicklas |
this.family=family; |
5350 |
25 May 10 |
nicklas |
269 |
|
5350 |
25 May 10 |
nicklas |
if(weight && weight!="") |
5350 |
25 May 10 |
nicklas |
this.weight=weight; |
5350 |
25 May 10 |
nicklas |
272 |
|
5350 |
25 May 10 |
nicklas |
if(size && size!="") |
5350 |
25 May 10 |
nicklas |
this.size=size; |
5350 |
25 May 10 |
nicklas |
275 |
|
5350 |
25 May 10 |
nicklas |
if(style && style!="") |
5350 |
25 May 10 |
nicklas |
this.style=style; |
5350 |
25 May 10 |
nicklas |
278 |
|
5350 |
25 May 10 |
nicklas |
if(variant && variant!="") |
5350 |
25 May 10 |
nicklas |
this.variant=variant; |
5350 |
25 May 10 |
nicklas |
281 |
} |
5350 |
25 May 10 |
nicklas |
282 |
|
5350 |
25 May 10 |
nicklas |
//jsPen class holds the drawing pen/stroke information. Mainly it holds the color and width values to be used for 2D drawing. |
5350 |
25 May 10 |
nicklas |
//All draw methods take jsPen object as a parameter. Acts like a pen for drawing. |
5350 |
25 May 10 |
nicklas |
function jsPen(color,width) |
5350 |
25 May 10 |
nicklas |
286 |
{ |
5350 |
25 May 10 |
nicklas |
this.color=new jsColor(); //color proprty of jsColor type |
5350 |
25 May 10 |
nicklas |
this.width="1px"; //width property with 1px default value |
5350 |
25 May 10 |
nicklas |
289 |
|
5350 |
25 May 10 |
nicklas |
if(arguments.length>0) |
5350 |
25 May 10 |
nicklas |
291 |
{ |
5350 |
25 May 10 |
nicklas |
this.color=color; |
5350 |
25 May 10 |
nicklas |
293 |
} |
5350 |
25 May 10 |
nicklas |
if(arguments.length>=2) |
5350 |
25 May 10 |
nicklas |
295 |
{ |
5350 |
25 May 10 |
nicklas |
this.width=width; |
5350 |
25 May 10 |
nicklas |
297 |
} |
5350 |
25 May 10 |
nicklas |
if(!isNaN(width)) |
5350 |
25 May 10 |
nicklas |
299 |
{ |
5350 |
25 May 10 |
nicklas |
this.width=width+"px"; |
5350 |
25 May 10 |
nicklas |
301 |
} |
5350 |
25 May 10 |
nicklas |
302 |
} |
5350 |
25 May 10 |
nicklas |
303 |
|
5350 |
25 May 10 |
nicklas |
//jsPoint class holds the 2D drawing point information. It holds values of x and y coordinates of the point. |
5350 |
25 May 10 |
nicklas |
function jsPoint(x,y) |
5350 |
25 May 10 |
nicklas |
306 |
{ |
5350 |
25 May 10 |
nicklas |
this.x=0; |
5350 |
25 May 10 |
nicklas |
this.y=0; |
5350 |
25 May 10 |
nicklas |
309 |
|
5350 |
25 May 10 |
nicklas |
if(arguments.length==2) |
5350 |
25 May 10 |
nicklas |
311 |
{ |
5350 |
25 May 10 |
nicklas |
this.x=x; |
5350 |
25 May 10 |
nicklas |
this.y=y; |
5350 |
25 May 10 |
nicklas |
314 |
} |
5350 |
25 May 10 |
nicklas |
315 |
} |
5350 |
25 May 10 |
nicklas |
316 |
|
5350 |
25 May 10 |
nicklas |
function jsGraphics(canvasDivElement) |
5350 |
25 May 10 |
nicklas |
318 |
{ |
5350 |
25 May 10 |
nicklas |
//Private member variables |
5350 |
25 May 10 |
nicklas |
var origin=new jsPoint(0,0); |
5350 |
25 May 10 |
nicklas |
var scale=1; |
5350 |
25 May 10 |
nicklas |
var coordinateSystem="default"; //Possible values "default" or "cartecian" |
5350 |
25 May 10 |
nicklas |
var canvasDiv; |
5350 |
25 May 10 |
nicklas |
324 |
|
5350 |
25 May 10 |
nicklas |
if(canvasDivElement) |
5350 |
25 May 10 |
nicklas |
canvasDiv=canvasDivElement; |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
canvasDiv=document.body; //Document will be used directly for drawing |
5350 |
25 May 10 |
nicklas |
329 |
|
5350 |
25 May 10 |
nicklas |
var gridDiv=null; |
5350 |
25 May 10 |
nicklas |
331 |
|
5350 |
25 May 10 |
nicklas |
//Public Methods |
5350 |
25 May 10 |
nicklas |
this.drawLine=drawLine; |
5350 |
25 May 10 |
nicklas |
this.drawRectangle=drawRectangle; |
5350 |
25 May 10 |
nicklas |
this.fillRectangle=fillRectangle; |
5350 |
25 May 10 |
nicklas |
this.drawCircle=drawCircle; |
5350 |
25 May 10 |
nicklas |
this.drawEllipse=drawEllipse; |
5350 |
25 May 10 |
nicklas |
this.fillCircle=fillCircle; |
5350 |
25 May 10 |
nicklas |
this.fillEllipse=fillEllipse; |
5350 |
25 May 10 |
nicklas |
this.fillArc=fillArc; |
5350 |
25 May 10 |
nicklas |
this.drawArc=drawArc; |
5350 |
25 May 10 |
nicklas |
this.drawPolyline=drawPolyline; |
5350 |
25 May 10 |
nicklas |
this.drawPolygon=drawPolygon; |
5350 |
25 May 10 |
nicklas |
this.fillPolygon=fillPolygon; |
5350 |
25 May 10 |
nicklas |
this.drawBezier=drawBezier; |
5350 |
25 May 10 |
nicklas |
this.drawPolyBezier=drawPolyBezier; |
5350 |
25 May 10 |
nicklas |
this.drawCurve=drawCurve; |
5350 |
25 May 10 |
nicklas |
this.drawClosedCurve=drawClosedCurve; |
5350 |
25 May 10 |
nicklas |
this.fillClosedCurve=fillClosedCurve; |
5350 |
25 May 10 |
nicklas |
this.drawText=drawText; |
5350 |
25 May 10 |
nicklas |
this.drawImage=drawImage; |
5350 |
25 May 10 |
nicklas |
this.clear=clear; |
5527 |
13 Dec 10 |
nicklas |
this.clearDrawing=clearDrawing; |
5350 |
25 May 10 |
nicklas |
this.showGrid=showGrid; |
5350 |
25 May 10 |
nicklas |
this.hideGrid=hideGrid; |
5350 |
25 May 10 |
nicklas |
this.setOrigin=setOrigin; |
5350 |
25 May 10 |
nicklas |
this.getOrigin=getOrigin; |
5350 |
25 May 10 |
nicklas |
this.setScale=setScale; |
5350 |
25 May 10 |
nicklas |
this.getScale=getScale; |
5350 |
25 May 10 |
nicklas |
this.setCoordinateSystem=setCoordinateSystem; |
5350 |
25 May 10 |
nicklas |
this.getCoordinateSystem=getCoordinateSystem; |
5350 |
25 May 10 |
nicklas |
this.logicalToPhysicalPoint=logicalToPhysicalPoint; |
5350 |
25 May 10 |
nicklas |
363 |
|
5350 |
25 May 10 |
nicklas |
//Initialization |
5350 |
25 May 10 |
nicklas |
365 |
|
5350 |
25 May 10 |
nicklas |
//Grid initialization |
5350 |
25 May 10 |
nicklas |
gridDiv=document.createElement("div"); |
5350 |
25 May 10 |
nicklas |
gridDiv.style.left="0px"; |
5350 |
25 May 10 |
nicklas |
gridDiv.style.top="0px"; |
5350 |
25 May 10 |
nicklas |
if(canvasDiv.clientWidth>0 && canvasDiv.clientHeight>0) |
5350 |
25 May 10 |
nicklas |
371 |
{ |
5350 |
25 May 10 |
nicklas |
gridDiv.style.width=(parseInt(canvasDiv.clientWidth)-1) + "px"; |
5350 |
25 May 10 |
nicklas |
gridDiv.style.height=(parseInt(canvasDiv.clientHeight)-1) + "px"; |
5350 |
25 May 10 |
nicklas |
374 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
376 |
{ |
5350 |
25 May 10 |
nicklas |
gridDiv.style.width="0px"; |
5350 |
25 May 10 |
nicklas |
gridDiv.style.height="0px"; |
5350 |
25 May 10 |
nicklas |
379 |
} |
5350 |
25 May 10 |
nicklas |
gridDiv.style.zIndex=0; |
5350 |
25 May 10 |
nicklas |
gridDiv.style.position="absolute"; |
5350 |
25 May 10 |
nicklas |
gridDiv.style.display="none"; |
5350 |
25 May 10 |
nicklas |
canvasDiv.appendChild(gridDiv); |
5350 |
25 May 10 |
nicklas |
384 |
|
5350 |
25 May 10 |
nicklas |
//Origin |
5350 |
25 May 10 |
nicklas |
function setOrigin(point) |
5350 |
25 May 10 |
nicklas |
387 |
{ |
5350 |
25 May 10 |
nicklas |
origin=point; |
5350 |
25 May 10 |
nicklas |
389 |
} |
5350 |
25 May 10 |
nicklas |
390 |
|
5350 |
25 May 10 |
nicklas |
function getOrigin() |
5350 |
25 May 10 |
nicklas |
392 |
{ |
5350 |
25 May 10 |
nicklas |
return origin; |
5350 |
25 May 10 |
nicklas |
394 |
} |
5350 |
25 May 10 |
nicklas |
395 |
|
5350 |
25 May 10 |
nicklas |
//Scale |
5350 |
25 May 10 |
nicklas |
function setScale(value) |
5350 |
25 May 10 |
nicklas |
398 |
{ |
5350 |
25 May 10 |
nicklas |
scale=value; |
5350 |
25 May 10 |
nicklas |
400 |
} |
5350 |
25 May 10 |
nicklas |
401 |
|
5350 |
25 May 10 |
nicklas |
function getScale() |
5350 |
25 May 10 |
nicklas |
403 |
{ |
5350 |
25 May 10 |
nicklas |
return scale; |
5350 |
25 May 10 |
nicklas |
405 |
} |
5350 |
25 May 10 |
nicklas |
406 |
|
5350 |
25 May 10 |
nicklas |
//Coordinate System |
5350 |
25 May 10 |
nicklas |
function setCoordinateSystem(name) |
5350 |
25 May 10 |
nicklas |
409 |
{ |
5350 |
25 May 10 |
nicklas |
name=name.toLowerCase() |
5350 |
25 May 10 |
nicklas |
if(name.toLowerCase() != "default" && name.toLowerCase() != "cartecian") |
5350 |
25 May 10 |
nicklas |
412 |
{ |
5350 |
25 May 10 |
nicklas |
coordinateSystem="default"; |
5350 |
25 May 10 |
nicklas |
414 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
416 |
{ |
5350 |
25 May 10 |
nicklas |
coordinateSystem=name; |
5350 |
25 May 10 |
nicklas |
418 |
} |
5350 |
25 May 10 |
nicklas |
419 |
} |
5350 |
25 May 10 |
nicklas |
420 |
|
5350 |
25 May 10 |
nicklas |
function getCoordinateSystem() |
5350 |
25 May 10 |
nicklas |
422 |
{ |
5350 |
25 May 10 |
nicklas |
return coordinateSystem=name; |
5350 |
25 May 10 |
nicklas |
424 |
} |
5350 |
25 May 10 |
nicklas |
425 |
|
5350 |
25 May 10 |
nicklas |
//Conversion of logical point to physical point based on coordinate system, origin and scale. |
5350 |
25 May 10 |
nicklas |
function logicalToPhysicalPoint(point) |
5350 |
25 May 10 |
nicklas |
428 |
{ |
5350 |
25 May 10 |
nicklas |
if(coordinateSystem=="cartecian") |
5350 |
25 May 10 |
nicklas |
430 |
{ |
5350 |
25 May 10 |
nicklas |
return new jsPoint(point.x*scale+origin.x,origin.y-point.y*scale) |
5350 |
25 May 10 |
nicklas |
432 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
434 |
{ |
5350 |
25 May 10 |
nicklas |
return new jsPoint(point.x*scale+origin.x,point.y*scale+origin.y) |
5350 |
25 May 10 |
nicklas |
436 |
} |
5350 |
25 May 10 |
nicklas |
437 |
} |
5350 |
25 May 10 |
nicklas |
438 |
|
5350 |
25 May 10 |
nicklas |
//Display background grid |
5350 |
25 May 10 |
nicklas |
function showGrid(range,showRange,color) |
5350 |
25 May 10 |
nicklas |
441 |
{ |
5350 |
25 May 10 |
nicklas |
if(showRange==null) |
5350 |
25 May 10 |
nicklas |
showRange=true; //range is grid interval. The values will be shown if showRange is true. |
5350 |
25 May 10 |
nicklas |
444 |
|
5350 |
25 May 10 |
nicklas |
var x0,x1,y0,y1; |
5350 |
25 May 10 |
nicklas |
var isLeft=false; //range display on left side of y-axis if true otherwise right side. |
5350 |
25 May 10 |
nicklas |
var isUp=false; //range display above the x-axis if true otherwise below. |
5350 |
25 May 10 |
nicklas |
gridDiv.innerHTML=""; |
5350 |
25 May 10 |
nicklas |
449 |
|
5350 |
25 May 10 |
nicklas |
if(!color) |
5350 |
25 May 10 |
nicklas |
color=new jsColor(200,200,200); |
5350 |
25 May 10 |
nicklas |
452 |
|
5350 |
25 May 10 |
nicklas |
if(!range) |
5350 |
25 May 10 |
nicklas |
range=Math.round(parseInt(gridDiv.style.width)/10); //If range not specified, use grid with devided by 10 as range. |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
range=range*scale; |
5350 |
25 May 10 |
nicklas |
457 |
|
5350 |
25 May 10 |
nicklas |
var hexColor=color.getHex(); |
5350 |
25 May 10 |
nicklas |
459 |
|
5350 |
25 May 10 |
nicklas |
//If grid height or width is not available, the grid will not be displayed. |
5350 |
25 May 10 |
nicklas |
if(parseInt(gridDiv.style.width)<=0 || parseInt(gridDiv.style.height)<=0) |
5350 |
25 May 10 |
nicklas |
return; |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
gridDiv.style.display=""; |
5350 |
25 May 10 |
nicklas |
465 |
|
5350 |
25 May 10 |
nicklas |
x0=parseInt(gridDiv.style.left) |
5350 |
25 May 10 |
nicklas |
x1=parseInt(gridDiv.style.left)+parseInt(gridDiv.style.width); |
5350 |
25 May 10 |
nicklas |
y0=parseInt(gridDiv.style.top); |
5350 |
25 May 10 |
nicklas |
y1=parseInt(gridDiv.style.top)+parseInt(gridDiv.style.height); |
5350 |
25 May 10 |
nicklas |
470 |
|
5350 |
25 May 10 |
nicklas |
//On which side of the axis the range to be displayed is decided based on position of the origin in the canvas. |
5350 |
25 May 10 |
nicklas |
//Range is displyed on opposite side of the largest section(out of 4 section divided by the 2 axis) |
5350 |
25 May 10 |
nicklas |
if(origin.x-parseInt(gridDiv.style.left)<=parseInt(gridDiv.style.left)+gridDiv.offsetWidth-origin.x) |
5350 |
25 May 10 |
nicklas |
isLeft=true |
5350 |
25 May 10 |
nicklas |
475 |
|
5350 |
25 May 10 |
nicklas |
if(origin.y-parseInt(gridDiv.style.top)<=parseInt(gridDiv.style.top)+gridDiv.offsetHeight-origin.y) |
5350 |
25 May 10 |
nicklas |
isUp=true |
5350 |
25 May 10 |
nicklas |
478 |
|
5350 |
25 May 10 |
nicklas |
var iHtml=new Array(); //Holds inner html |
5350 |
25 May 10 |
nicklas |
var rangeFont=new jsFont("arial",null,"9px"); |
5350 |
25 May 10 |
nicklas |
var rangeColor=color.getDarkerShade(150); |
5350 |
25 May 10 |
nicklas |
var hexRangeColor=rangeColor.getHex(); |
5350 |
25 May 10 |
nicklas |
483 |
|
5350 |
25 May 10 |
nicklas |
//Draw the border grids |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;z-index:-100;left:" + x0 + "px;top:" + y0 + "px;width:" + (x1-x0+1) + "px;height:1px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;z-index:-100;left:" + x0 + "px;top:" + y1 + "px;width:" + (x1-x0+1) + "px;height:1px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;z-index:-100;left:" + x0 + "px;top:" + y0 + "px;width:1px;height:" + (y1-y0+1) + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;z-index:-100;left:" + x1 + "px;top:" + y0 + "px;width:1px;height:" + (y1-y0+1) + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
489 |
|
5350 |
25 May 10 |
nicklas |
var gridHeight=gridDiv.offsetHeight; |
5350 |
25 May 10 |
nicklas |
var gridWidth=gridDiv.offsetWidth; |
5350 |
25 May 10 |
nicklas |
var lastRangeDiv; //previous range div |
5350 |
25 May 10 |
nicklas |
var currentRangeDiv //current range div |
5350 |
25 May 10 |
nicklas |
494 |
|
5350 |
25 May 10 |
nicklas |
//Draw vertical grid lines |
5350 |
25 May 10 |
nicklas |
for(var x=(origin.x-x0)%range;x<x1;x+=range) |
5350 |
25 May 10 |
nicklas |
497 |
{ |
5350 |
25 May 10 |
nicklas |
if(x==origin.x && x>=x0) |
5350 |
25 May 10 |
nicklas |
499 |
{ |
5350 |
25 May 10 |
nicklas |
if(x>=x0 && x<=x1) |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;z-index:-99;left:" + x + "px;top:" + y0 + "px;width:1px;height:" + gridHeight + "px;background-color:" + hexRangeColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
502 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
504 |
{ |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;z-index:-100;left:" + x + "px;top:" + y0 + "px;width:1px;height:" + gridHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
506 |
} |
5350 |
25 May 10 |
nicklas |
507 |
|
5350 |
25 May 10 |
nicklas |
if(showRange && x>=x0 && x<x1) |
5350 |
25 May 10 |
nicklas |
509 |
{ |
5350 |
25 May 10 |
nicklas |
if(lastRangeDiv && lastRangeDiv.offsetLeft + lastRangeDiv.offsetWidth + 1 < x) |
5350 |
25 May 10 |
nicklas |
511 |
{ |
5350 |
25 May 10 |
nicklas |
if(lastRangeDiv.offsetWidth < x1-x) |
5350 |
25 May 10 |
nicklas |
currentRangeDiv = drawRange(Math.round((x-origin.x)/scale),new jsPoint(x+2,y0+1+origin.y),rangeFont,rangeColor); |
5350 |
25 May 10 |
nicklas |
514 |
} |
5350 |
25 May 10 |
nicklas |
else if(!lastRangeDiv) |
5350 |
25 May 10 |
nicklas |
currentRangeDiv = drawRange(Math.round((x-origin.x)/scale),new jsPoint(x+2,y0+1+origin.y),rangeFont,rangeColor); |
5350 |
25 May 10 |
nicklas |
517 |
|
5350 |
25 May 10 |
nicklas |
if(currentRangeDiv) |
5350 |
25 May 10 |
nicklas |
519 |
{ |
5350 |
25 May 10 |
nicklas |
if(!isUp) |
5350 |
25 May 10 |
nicklas |
521 |
{ |
5350 |
25 May 10 |
nicklas |
if(parseInt(currentRangeDiv.style.top)+currentRangeDiv.offsetHeight > y1) |
5350 |
25 May 10 |
nicklas |
currentRangeDiv.style.top=y1-currentRangeDiv.offsetHeight-1; |
5350 |
25 May 10 |
nicklas |
524 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
526 |
{ |
5350 |
25 May 10 |
nicklas |
if(parseInt(currentRangeDiv.style.top)-currentRangeDiv.offsetHeight-1>y0) |
5350 |
25 May 10 |
nicklas |
currentRangeDiv.style.top=parseInt(currentRangeDiv.style.top)-currentRangeDiv.offsetHeight-1; |
5350 |
25 May 10 |
nicklas |
529 |
|
5350 |
25 May 10 |
nicklas |
if(parseInt(currentRangeDiv.style.top)<=y0) |
5350 |
25 May 10 |
nicklas |
currentRangeDiv.style.top=y0 + 1; |
5350 |
25 May 10 |
nicklas |
532 |
} |
5350 |
25 May 10 |
nicklas |
533 |
|
5350 |
25 May 10 |
nicklas |
currentRangeDiv.style.visibility="visible"; |
5350 |
25 May 10 |
nicklas |
lastRangeDiv = currentRangeDiv; |
5350 |
25 May 10 |
nicklas |
536 |
} |
5350 |
25 May 10 |
nicklas |
currentRangeDiv=null; |
5350 |
25 May 10 |
nicklas |
538 |
|
5350 |
25 May 10 |
nicklas |
539 |
} |
5350 |
25 May 10 |
nicklas |
540 |
} |
5350 |
25 May 10 |
nicklas |
lastRangeDiv = null; |
5350 |
25 May 10 |
nicklas |
542 |
|
5350 |
25 May 10 |
nicklas |
//Draw horizontal grid lines |
5350 |
25 May 10 |
nicklas |
for(var y=(origin.y-y0)%range;y<=y1;y+=range) |
5350 |
25 May 10 |
nicklas |
545 |
{ |
5350 |
25 May 10 |
nicklas |
if(y==origin.y) |
5350 |
25 May 10 |
nicklas |
547 |
{ |
5350 |
25 May 10 |
nicklas |
if(y>=y0 && y<=y1) |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;z-index:-99;left:" + x0 + "px;top:" + y + "px;width:" + gridWidth + "px;height:1px;background-color:" + hexRangeColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
550 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;z-index:-100;left:" + x0 + "px;top:" + y + "px;width:" + gridWidth + "px;height:1px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
553 |
|
5350 |
25 May 10 |
nicklas |
if(showRange && y!=origin.y && y>=y0 && y<y1) |
5350 |
25 May 10 |
nicklas |
555 |
{ |
5350 |
25 May 10 |
nicklas |
if(lastRangeDiv && lastRangeDiv.offsetTop + lastRangeDiv.offsetHeight < y) |
5350 |
25 May 10 |
nicklas |
557 |
{ |
5350 |
25 May 10 |
nicklas |
if(lastRangeDiv.offsetHeight <= y1-y) |
5350 |
25 May 10 |
nicklas |
559 |
{ |
5350 |
25 May 10 |
nicklas |
if(coordinateSystem=="cartecian") |
5350 |
25 May 10 |
nicklas |
currentRangeDiv = drawRange(Math.round((origin.y-y)/scale),new jsPoint(x0+2+origin.x,y),rangeFont,rangeColor); |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
currentRangeDiv = drawRange(Math.round((y-origin.y)/scale),new jsPoint(x0+2+origin.x,y),rangeFont,rangeColor); |
5350 |
25 May 10 |
nicklas |
564 |
} |
5350 |
25 May 10 |
nicklas |
565 |
} |
5350 |
25 May 10 |
nicklas |
else if(!lastRangeDiv) |
5350 |
25 May 10 |
nicklas |
567 |
{ |
5350 |
25 May 10 |
nicklas |
if(coordinateSystem=="cartecian") |
5350 |
25 May 10 |
nicklas |
currentRangeDiv = drawRange(Math.round((origin.y-y)/scale),new jsPoint(x0+2+origin.x,y),rangeFont,rangeColor); |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
currentRangeDiv = drawRange(Math.round((y-origin.y)/scale),new jsPoint(x0+2+origin.x,y),rangeFont,rangeColor); |
5350 |
25 May 10 |
nicklas |
572 |
} |
5350 |
25 May 10 |
nicklas |
573 |
|
5350 |
25 May 10 |
nicklas |
if(currentRangeDiv) |
5350 |
25 May 10 |
nicklas |
575 |
{ |
5350 |
25 May 10 |
nicklas |
if(!isLeft) |
5350 |
25 May 10 |
nicklas |
577 |
{ |
5350 |
25 May 10 |
nicklas |
if(parseInt(currentRangeDiv.style.left)+1+currentRangeDiv.offsetWidth < x1) |
5350 |
25 May 10 |
nicklas |
currentRangeDiv.style.left=parseInt(currentRangeDiv.style.left)+1; |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
currentRangeDiv.style.left=x1-currentRangeDiv.offsetWidth-3; |
5350 |
25 May 10 |
nicklas |
582 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
584 |
{ |
5350 |
25 May 10 |
nicklas |
if(parseInt(currentRangeDiv.style.left)-currentRangeDiv.offsetWidth-2 > x0) |
5350 |
25 May 10 |
nicklas |
currentRangeDiv.style.left=parseInt(currentRangeDiv.style.left)-currentRangeDiv.offsetWidth-2; |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
currentRangeDiv.style.left=parseInt(currentRangeDiv.style.left)+1; |
5350 |
25 May 10 |
nicklas |
589 |
|
5350 |
25 May 10 |
nicklas |
if(parseInt(currentRangeDiv.style.left)<=x0) |
5350 |
25 May 10 |
nicklas |
currentRangeDiv.style.left=x0 + 1; |
5350 |
25 May 10 |
nicklas |
592 |
} |
5350 |
25 May 10 |
nicklas |
593 |
|
5350 |
25 May 10 |
nicklas |
currentRangeDiv.style.visibility="visible"; |
5350 |
25 May 10 |
nicklas |
595 |
|
5350 |
25 May 10 |
nicklas |
//Hide the overlapping range. |
5350 |
25 May 10 |
nicklas |
if(isUp && parseInt(currentRangeDiv.style.top)+currentRangeDiv.offsetHeight>origin.y-currentRangeDiv.offsetHeight && parseInt(currentRangeDiv.style.top)<origin.y) |
5350 |
25 May 10 |
nicklas |
currentRangeDiv.style.visibility="hidden"; |
5350 |
25 May 10 |
nicklas |
599 |
|
5350 |
25 May 10 |
nicklas |
if(isUp && parseInt(currentRangeDiv.style.top)>origin.y && parseInt(currentRangeDiv.style.top)<origin.y+currentRangeDiv.offsetHeight && parseInt(currentRangeDiv.style.top)>origin.y) |
5350 |
25 May 10 |
nicklas |
currentRangeDiv.style.visibility="hidden"; |
5350 |
25 May 10 |
nicklas |
602 |
|
5350 |
25 May 10 |
nicklas |
if(origin.y>y1 && parseInt(currentRangeDiv.style.top)+currentRangeDiv.offsetHeight>y1-currentRangeDiv.offsetHeight) |
5350 |
25 May 10 |
nicklas |
currentRangeDiv.style.visibility="hidden"; |
5350 |
25 May 10 |
nicklas |
605 |
|
5350 |
25 May 10 |
nicklas |
if(!isUp && parseInt(currentRangeDiv.style.top)<origin.y+currentRangeDiv.offsetHeight && parseInt(currentRangeDiv.style.top)>origin.y) |
5350 |
25 May 10 |
nicklas |
currentRangeDiv.style.visibility="hidden"; |
5350 |
25 May 10 |
nicklas |
608 |
|
5350 |
25 May 10 |
nicklas |
if(!isUp && parseInt(currentRangeDiv.style.top)<origin.y && parseInt(currentRangeDiv.style.top)+currentRangeDiv.offsetHeight>origin.y && parseInt(currentRangeDiv.style.top)<origin.y) |
5350 |
25 May 10 |
nicklas |
610 |
{ |
5350 |
25 May 10 |
nicklas |
alert(parseInt(currentRangeDiv.style.top)); |
5350 |
25 May 10 |
nicklas |
currentRangeDiv.style.visibility="hidden"; |
5350 |
25 May 10 |
nicklas |
613 |
} |
5350 |
25 May 10 |
nicklas |
if(origin.y<y0 && parseInt(currentRangeDiv.style.top)<y0+currentRangeDiv.offsetHeight) |
5350 |
25 May 10 |
nicklas |
currentRangeDiv.style.visibility="hidden"; |
5350 |
25 May 10 |
nicklas |
616 |
|
5350 |
25 May 10 |
nicklas |
lastRangeDiv=currentRangeDiv; |
5350 |
25 May 10 |
nicklas |
618 |
} |
5350 |
25 May 10 |
nicklas |
currentRangeDiv = null; |
5350 |
25 May 10 |
nicklas |
620 |
|
5350 |
25 May 10 |
nicklas |
621 |
} |
5350 |
25 May 10 |
nicklas |
622 |
} |
5350 |
25 May 10 |
nicklas |
623 |
|
5350 |
25 May 10 |
nicklas |
gridDiv.innerHTML=gridDiv.innerHTML + iHtml.join(""); |
5350 |
25 May 10 |
nicklas |
625 |
|
5350 |
25 May 10 |
nicklas |
//Internal function only to be used by showGrid method to draw the range value. |
5350 |
25 May 10 |
nicklas |
function drawRange(text,point,font,color,align) |
5350 |
25 May 10 |
nicklas |
628 |
{ |
5350 |
25 May 10 |
nicklas |
var textDiv=document.createElement("div"); |
5350 |
25 May 10 |
nicklas |
630 |
|
5350 |
25 May 10 |
nicklas |
textDiv.style.position="absolute"; |
5350 |
25 May 10 |
nicklas |
textDiv.style.left=point.x + "px"; |
5350 |
25 May 10 |
nicklas |
textDiv.style.top=point.y + "px"; |
5350 |
25 May 10 |
nicklas |
textDiv.style.color=color.getHex(); |
5350 |
25 May 10 |
nicklas |
textDiv.style.zIndex=-98; |
5350 |
25 May 10 |
nicklas |
textDiv.style.visibility="hidden"; |
5350 |
25 May 10 |
nicklas |
637 |
|
5350 |
25 May 10 |
nicklas |
gridDiv.appendChild(textDiv); |
5350 |
25 May 10 |
nicklas |
639 |
|
5350 |
25 May 10 |
nicklas |
//set font |
5350 |
25 May 10 |
nicklas |
if(font.family) |
5350 |
25 May 10 |
nicklas |
textDiv.style.fontFamily=font.family; |
5350 |
25 May 10 |
nicklas |
643 |
|
5350 |
25 May 10 |
nicklas |
if(font.weight) |
5350 |
25 May 10 |
nicklas |
textDiv.style.fontWeight=font.weight; |
5350 |
25 May 10 |
nicklas |
646 |
|
5350 |
25 May 10 |
nicklas |
if(font.size) |
5350 |
25 May 10 |
nicklas |
textDiv.style.fontSize=font.size; |
5350 |
25 May 10 |
nicklas |
649 |
|
5350 |
25 May 10 |
nicklas |
if(font.style) |
5350 |
25 May 10 |
nicklas |
textDiv.style.fontStyle=font.style; |
5350 |
25 May 10 |
nicklas |
652 |
|
5350 |
25 May 10 |
nicklas |
if(font.variant) |
5350 |
25 May 10 |
nicklas |
textDiv.style.fontVariant=font.variant; |
5350 |
25 May 10 |
nicklas |
655 |
|
5350 |
25 May 10 |
nicklas |
if(align) |
5350 |
25 May 10 |
nicklas |
textDiv.align=align; |
5350 |
25 May 10 |
nicklas |
658 |
|
5350 |
25 May 10 |
nicklas |
textDiv.innerHTML=text; |
5350 |
25 May 10 |
nicklas |
return textDiv; |
5350 |
25 May 10 |
nicklas |
661 |
} |
5350 |
25 May 10 |
nicklas |
662 |
} |
5350 |
25 May 10 |
nicklas |
663 |
|
5350 |
25 May 10 |
nicklas |
//Clear the grid. |
5350 |
25 May 10 |
nicklas |
function hideGrid() |
5350 |
25 May 10 |
nicklas |
666 |
{ |
5350 |
25 May 10 |
nicklas |
gridDiv.innerHTML=""; |
5350 |
25 May 10 |
nicklas |
gridDiv.style.display="none"; |
5350 |
25 May 10 |
nicklas |
669 |
} |
5350 |
25 May 10 |
nicklas |
670 |
|
5350 |
25 May 10 |
nicklas |
//Draw Line between the 2 specified points based on Mid point Algorithm. |
5350 |
25 May 10 |
nicklas |
function drawLine(pen,point0,point1) |
5350 |
25 May 10 |
nicklas |
673 |
{ |
5350 |
25 May 10 |
nicklas |
//Check arguments for null values |
5350 |
25 May 10 |
nicklas |
if(!pen || !point0 || !point1) |
5350 |
25 May 10 |
nicklas |
return false; |
5350 |
25 May 10 |
nicklas |
677 |
|
5350 |
25 May 10 |
nicklas |
var lineDiv=canvasDiv.appendChild(document.createElement("div")); |
5350 |
25 May 10 |
nicklas |
679 |
|
7419 |
03 Nov 17 |
nicklas |
var phPoint0; |
7419 |
03 Nov 17 |
nicklas |
var phPoint1; |
5350 |
25 May 10 |
nicklas |
//Some library functions use drawLine method and need to pass physical points only. So the following check. |
5350 |
25 May 10 |
nicklas |
if(arguments[3]!="physical") |
5350 |
25 May 10 |
nicklas |
684 |
{ |
5350 |
25 May 10 |
nicklas |
phPoint0=logicalToPhysicalPoint(point0); |
5350 |
25 May 10 |
nicklas |
phPoint1=logicalToPhysicalPoint(point1); |
5350 |
25 May 10 |
nicklas |
687 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
689 |
{ |
5350 |
25 May 10 |
nicklas |
phPoint0=new jsPoint(point0.x,point0.y); |
5350 |
25 May 10 |
nicklas |
phPoint1=new jsPoint(point1.x,point1.y); |
5350 |
25 May 10 |
nicklas |
692 |
} |
5350 |
25 May 10 |
nicklas |
693 |
|
5350 |
25 May 10 |
nicklas |
var x0, x1, y0, y1; |
5527 |
13 Dec 10 |
nicklas |
x0=Math.round(phPoint0.x); |
5527 |
13 Dec 10 |
nicklas |
x1=Math.round(phPoint1.x); |
5527 |
13 Dec 10 |
nicklas |
y0=Math.round(phPoint0.y); |
5527 |
13 Dec 10 |
nicklas |
y1=Math.round(phPoint1.y); |
5350 |
25 May 10 |
nicklas |
699 |
|
5350 |
25 May 10 |
nicklas |
var hexColor=pen.color.getHex(); |
5350 |
25 May 10 |
nicklas |
//For Horizontal line |
5350 |
25 May 10 |
nicklas |
if(y0==y1) |
5350 |
25 May 10 |
nicklas |
703 |
{ |
5350 |
25 May 10 |
nicklas |
if(x0<=x1) |
5350 |
25 May 10 |
nicklas |
lineDiv.innerHTML="<DIV style=\"position:absolute;overflow:hidden;left:" + x0 + "px;top:" + y0 + "px;width:" + (x1-x0+1) + "px;height:" + pen.width + ";background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
else if(x0>x1) |
5350 |
25 May 10 |
nicklas |
lineDiv.innerHTML="<DIV style=\"position:absolute;overflow:hidden;left:" + x1 + "px;top:" + y0 + "px;width:" + (x0-x1+1) + "px;height:" + pen.width + ";background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
708 |
|
5350 |
25 May 10 |
nicklas |
return lineDiv; |
5350 |
25 May 10 |
nicklas |
710 |
} |
5350 |
25 May 10 |
nicklas |
711 |
|
5350 |
25 May 10 |
nicklas |
//For Vertical line |
5350 |
25 May 10 |
nicklas |
if(x0==x1) |
5350 |
25 May 10 |
nicklas |
714 |
{ |
5350 |
25 May 10 |
nicklas |
if(y0<=y1) |
5350 |
25 May 10 |
nicklas |
lineDiv.innerHTML="<DIV style=\"position:absolute;overflow:hidden;left:" + x0 + "px;top:" + y0 + "px;width:" + pen.width + ";height:" + (y1-y0+1) + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
else if(y0>y1) |
5350 |
25 May 10 |
nicklas |
lineDiv.innerHTML="<DIV style=\"position:absolute;overflow:hidden;left:" + x0 + "px;top:" + y1 + "px;width:" + pen.width + ";height:" + (y0-y1+1) + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
719 |
|
5350 |
25 May 10 |
nicklas |
return lineDiv; |
5350 |
25 May 10 |
nicklas |
721 |
} |
5350 |
25 May 10 |
nicklas |
722 |
|
5350 |
25 May 10 |
nicklas |
var iHtml=new Array(); |
5350 |
25 May 10 |
nicklas |
var yArray=new Array(); |
5350 |
25 May 10 |
nicklas |
725 |
|
5350 |
25 May 10 |
nicklas |
///Pixel Height Width Start |
5350 |
25 May 10 |
nicklas |
var dx=Math.abs(x1-x0); |
5350 |
25 May 10 |
nicklas |
var dy=Math.abs(y1-y0); |
5350 |
25 May 10 |
nicklas |
var pixHeight,pixWidth; |
5350 |
25 May 10 |
nicklas |
var penWidth=parseInt(pen.width); |
5350 |
25 May 10 |
nicklas |
731 |
|
5350 |
25 May 10 |
nicklas |
pixHeight=Math.round(Math.sqrt((penWidth*penWidth)/((dy*dy)/(dx*dx)+1))); |
5350 |
25 May 10 |
nicklas |
pixWidth=Math.round(Math.sqrt(penWidth*penWidth-pixHeight*pixHeight)); |
5350 |
25 May 10 |
nicklas |
734 |
|
5350 |
25 May 10 |
nicklas |
if(pixWidth==0) |
5350 |
25 May 10 |
nicklas |
736 |
{ |
5350 |
25 May 10 |
nicklas |
pixWidth=1; |
5350 |
25 May 10 |
nicklas |
738 |
} |
5350 |
25 May 10 |
nicklas |
if(pixHeight==0) |
5350 |
25 May 10 |
nicklas |
740 |
{ |
5350 |
25 May 10 |
nicklas |
pixHeight=1; |
5350 |
25 May 10 |
nicklas |
742 |
} |
5350 |
25 May 10 |
nicklas |
///Pixel Height Width End |
5350 |
25 May 10 |
nicklas |
744 |
|
5350 |
25 May 10 |
nicklas |
var steep = Math.abs(y1 - y0) > Math.abs(x1 - x0); |
5350 |
25 May 10 |
nicklas |
if (steep) |
5350 |
25 May 10 |
nicklas |
747 |
{ |
5350 |
25 May 10 |
nicklas |
// swap |
5350 |
25 May 10 |
nicklas |
var tmp=x0; |
5350 |
25 May 10 |
nicklas |
x0=y0; |
5350 |
25 May 10 |
nicklas |
y0=tmp; |
5350 |
25 May 10 |
nicklas |
tmp=x1; |
5350 |
25 May 10 |
nicklas |
x1=y1; |
5350 |
25 May 10 |
nicklas |
y1=tmp; |
5350 |
25 May 10 |
nicklas |
755 |
} |
5350 |
25 May 10 |
nicklas |
756 |
|
5350 |
25 May 10 |
nicklas |
if (x0 > x1) |
5350 |
25 May 10 |
nicklas |
758 |
{ |
5350 |
25 May 10 |
nicklas |
// swap |
5350 |
25 May 10 |
nicklas |
var tmp=x0; |
5350 |
25 May 10 |
nicklas |
x0=x1; |
5350 |
25 May 10 |
nicklas |
x1=tmp; |
5350 |
25 May 10 |
nicklas |
tmp=y0; |
5350 |
25 May 10 |
nicklas |
y0=y1; |
5350 |
25 May 10 |
nicklas |
y1=tmp; |
5350 |
25 May 10 |
nicklas |
766 |
} |
5350 |
25 May 10 |
nicklas |
767 |
|
5350 |
25 May 10 |
nicklas |
var deltax = x1 - x0; |
5350 |
25 May 10 |
nicklas |
var deltay = Math.abs(y1 - y0); |
5350 |
25 May 10 |
nicklas |
var error = deltax/2; |
5350 |
25 May 10 |
nicklas |
var ystep; |
5350 |
25 May 10 |
nicklas |
var y = y0; |
5350 |
25 May 10 |
nicklas |
773 |
|
5350 |
25 May 10 |
nicklas |
if (y0<y1) |
5350 |
25 May 10 |
nicklas |
ystep = 1; |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
ystep = -1; |
5350 |
25 May 10 |
nicklas |
778 |
|
5350 |
25 May 10 |
nicklas |
var xp,yp; |
5350 |
25 May 10 |
nicklas |
var divWidth=0; |
5350 |
25 May 10 |
nicklas |
var divHeight=0; |
5350 |
25 May 10 |
nicklas |
if(steep) |
5350 |
25 May 10 |
nicklas |
783 |
{ |
5350 |
25 May 10 |
nicklas |
divWidth=pixWidth; |
5350 |
25 May 10 |
nicklas |
785 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
787 |
{ |
5350 |
25 May 10 |
nicklas |
divHeight=pixHeight; |
5350 |
25 May 10 |
nicklas |
789 |
} |
7419 |
03 Nov 17 |
nicklas |
for (var x=x0;x<=x1;x++) |
5350 |
25 May 10 |
nicklas |
791 |
{ |
5350 |
25 May 10 |
nicklas |
if (steep) |
5350 |
25 May 10 |
nicklas |
793 |
{ |
5350 |
25 May 10 |
nicklas |
if(x==x0) |
5350 |
25 May 10 |
nicklas |
795 |
{ |
5350 |
25 May 10 |
nicklas |
xp=y; |
5350 |
25 May 10 |
nicklas |
yp=x; |
5350 |
25 May 10 |
nicklas |
798 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
800 |
{ |
5350 |
25 May 10 |
nicklas |
if(y==xp) |
5350 |
25 May 10 |
nicklas |
802 |
{ |
5350 |
25 May 10 |
nicklas |
divHeight=divHeight+ 1; |
5350 |
25 May 10 |
nicklas |
804 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
806 |
{ |
5350 |
25 May 10 |
nicklas |
divHeight=divHeight+pixHeight; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + xp + "px;top:" + yp + "px;width:" + divWidth+ "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
divHeight=0; |
5350 |
25 May 10 |
nicklas |
xp=y; |
5350 |
25 May 10 |
nicklas |
yp=x; |
5350 |
25 May 10 |
nicklas |
812 |
} |
5350 |
25 May 10 |
nicklas |
813 |
} |
5350 |
25 May 10 |
nicklas |
814 |
|
5350 |
25 May 10 |
nicklas |
if(x==x1) |
5350 |
25 May 10 |
nicklas |
816 |
{ |
5350 |
25 May 10 |
nicklas |
if(divHeight!=0) |
5350 |
25 May 10 |
nicklas |
818 |
{ |
5350 |
25 May 10 |
nicklas |
divHeight=divHeight+pixHeight; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + xp + "px;top:" + yp + "px;width:" + divWidth+ "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
821 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
823 |
{ |
5350 |
25 May 10 |
nicklas |
divHeight=pixHeight; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + y + "px;top:" + x + "px;width:" + divWidth+ "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
826 |
} |
5350 |
25 May 10 |
nicklas |
827 |
} |
5350 |
25 May 10 |
nicklas |
828 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
830 |
{ |
5350 |
25 May 10 |
nicklas |
if(x==x0) |
5350 |
25 May 10 |
nicklas |
832 |
{ |
5350 |
25 May 10 |
nicklas |
xp=x; |
5350 |
25 May 10 |
nicklas |
yp=y; |
5350 |
25 May 10 |
nicklas |
835 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
837 |
{ |
5350 |
25 May 10 |
nicklas |
if(y==yp) |
5350 |
25 May 10 |
nicklas |
839 |
{ |
5350 |
25 May 10 |
nicklas |
divWidth=divWidth + 1; |
5350 |
25 May 10 |
nicklas |
841 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
843 |
{ |
5350 |
25 May 10 |
nicklas |
divWidth=divWidth+pixWidth; |
5527 |
13 Dec 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + xp + "px;top:" + yp + "px;width:" + divWidth+ "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
divWidth=0; |
5350 |
25 May 10 |
nicklas |
xp=x; |
5350 |
25 May 10 |
nicklas |
yp=y; |
5350 |
25 May 10 |
nicklas |
849 |
} |
5350 |
25 May 10 |
nicklas |
850 |
} |
5350 |
25 May 10 |
nicklas |
if(x==x1) |
5350 |
25 May 10 |
nicklas |
852 |
{ |
5350 |
25 May 10 |
nicklas |
if(divWidth!=0) |
5350 |
25 May 10 |
nicklas |
854 |
{ |
5350 |
25 May 10 |
nicklas |
divWidth=divWidth+pixWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + xp + "px;top:" + yp + "px;width:" + divWidth+ "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
857 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
859 |
{ |
5350 |
25 May 10 |
nicklas |
divWidth=pixWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + x + "px;top:" + y + "px;width:" + divWidth+ "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
862 |
} |
5350 |
25 May 10 |
nicklas |
863 |
} |
5350 |
25 May 10 |
nicklas |
864 |
} |
5350 |
25 May 10 |
nicklas |
865 |
|
5350 |
25 May 10 |
nicklas |
error = error - deltay; |
5350 |
25 May 10 |
nicklas |
if (error < 0) |
5350 |
25 May 10 |
nicklas |
868 |
{ |
5350 |
25 May 10 |
nicklas |
y = y + ystep; |
5350 |
25 May 10 |
nicklas |
error = error + deltax; |
5350 |
25 May 10 |
nicklas |
871 |
} |
5350 |
25 May 10 |
nicklas |
872 |
} |
5350 |
25 May 10 |
nicklas |
873 |
|
5350 |
25 May 10 |
nicklas |
lineDiv.innerHTML=iHtml.join(""); |
5350 |
25 May 10 |
nicklas |
return lineDiv; |
5350 |
25 May 10 |
nicklas |
876 |
} |
5350 |
25 May 10 |
nicklas |
877 |
|
5350 |
25 May 10 |
nicklas |
//Private function returns array of x coordinates for y values |
5350 |
25 May 10 |
nicklas |
//for a line (algorithm same as drawLine method). |
5350 |
25 May 10 |
nicklas |
//Used by drawArc, fillArc and fillPolygon methods. |
5350 |
25 May 10 |
nicklas |
function getLinePixels(point0,point1) |
5350 |
25 May 10 |
nicklas |
882 |
{ |
5350 |
25 May 10 |
nicklas |
function xData() |
5350 |
25 May 10 |
nicklas |
884 |
{ |
5350 |
25 May 10 |
nicklas |
this.xMax=0; |
5350 |
25 May 10 |
nicklas |
this.xMin=0; |
5350 |
25 May 10 |
nicklas |
this.isVertex=false; |
5350 |
25 May 10 |
nicklas |
888 |
} |
5350 |
25 May 10 |
nicklas |
889 |
|
5350 |
25 May 10 |
nicklas |
var x0, x1, y0, y1; |
5350 |
25 May 10 |
nicklas |
x0=point0.x; |
5350 |
25 May 10 |
nicklas |
x1=point1.x; |
5350 |
25 May 10 |
nicklas |
y0=point0.y; |
5350 |
25 May 10 |
nicklas |
y1=point1.y; |
5350 |
25 May 10 |
nicklas |
var xDataArray=new Array(); |
5350 |
25 May 10 |
nicklas |
var steep = Math.abs(y1 - y0) > Math.abs(x1 - x0); |
5350 |
25 May 10 |
nicklas |
if (steep) |
5350 |
25 May 10 |
nicklas |
898 |
{ |
5350 |
25 May 10 |
nicklas |
// swap |
5350 |
25 May 10 |
nicklas |
var tmp=x0; |
5350 |
25 May 10 |
nicklas |
x0=y0; |
5350 |
25 May 10 |
nicklas |
y0=tmp; |
5350 |
25 May 10 |
nicklas |
tmp=x1; |
5350 |
25 May 10 |
nicklas |
x1=y1; |
5350 |
25 May 10 |
nicklas |
y1=tmp; |
5350 |
25 May 10 |
nicklas |
906 |
} |
5350 |
25 May 10 |
nicklas |
907 |
|
5350 |
25 May 10 |
nicklas |
if (x0 > x1) |
5350 |
25 May 10 |
nicklas |
909 |
{ |
5350 |
25 May 10 |
nicklas |
// swap |
5350 |
25 May 10 |
nicklas |
var tmp=x0; |
5350 |
25 May 10 |
nicklas |
x0=x1; |
5350 |
25 May 10 |
nicklas |
x1=tmp; |
5350 |
25 May 10 |
nicklas |
tmp=y0; |
5350 |
25 May 10 |
nicklas |
y0=y1; |
5350 |
25 May 10 |
nicklas |
y1=tmp; |
5350 |
25 May 10 |
nicklas |
917 |
} |
5350 |
25 May 10 |
nicklas |
918 |
|
5350 |
25 May 10 |
nicklas |
var deltax = x1 - x0; |
5350 |
25 May 10 |
nicklas |
var deltay = Math.abs(y1 - y0); |
5350 |
25 May 10 |
nicklas |
var error = deltax/2; |
5350 |
25 May 10 |
nicklas |
var ystep; |
5350 |
25 May 10 |
nicklas |
var y = y0; |
5350 |
25 May 10 |
nicklas |
924 |
|
5350 |
25 May 10 |
nicklas |
if (y0<y1) |
5350 |
25 May 10 |
nicklas |
ystep = 1; |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
ystep = -1; |
5350 |
25 May 10 |
nicklas |
929 |
|
7419 |
03 Nov 17 |
nicklas |
for (var x=x0;x<=x1;x++) |
5350 |
25 May 10 |
nicklas |
931 |
{ |
5350 |
25 May 10 |
nicklas |
if (steep) |
5350 |
25 May 10 |
nicklas |
933 |
{ |
5350 |
25 May 10 |
nicklas |
xDataArray[x]=new xData(); |
5350 |
25 May 10 |
nicklas |
xDataArray[x].xMin=y; |
5350 |
25 May 10 |
nicklas |
xDataArray[x].xMax=y; |
5350 |
25 May 10 |
nicklas |
937 |
|
5350 |
25 May 10 |
nicklas |
if(x==x0 && y==y0) |
5350 |
25 May 10 |
nicklas |
xDataArray[x].isVertex=true; |
5350 |
25 May 10 |
nicklas |
940 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
942 |
{ |
5350 |
25 May 10 |
nicklas |
if(!xDataArray[y]) |
5350 |
25 May 10 |
nicklas |
944 |
{ |
5350 |
25 May 10 |
nicklas |
xDataArray[y]=new xData(); |
5350 |
25 May 10 |
nicklas |
xDataArray[y].xMin=x; |
5350 |
25 May 10 |
nicklas |
xDataArray[y].xMax=x; |
5350 |
25 May 10 |
nicklas |
948 |
|
5350 |
25 May 10 |
nicklas |
if(x==x0 && y==y0) |
5350 |
25 May 10 |
nicklas |
xDataArray[y].isVertex=true; |
5350 |
25 May 10 |
nicklas |
951 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
953 |
{ |
5350 |
25 May 10 |
nicklas |
xDataArray[y].xMax=x; |
5350 |
25 May 10 |
nicklas |
955 |
} |
5350 |
25 May 10 |
nicklas |
956 |
} |
5350 |
25 May 10 |
nicklas |
957 |
|
5350 |
25 May 10 |
nicklas |
error = error - deltay; |
5350 |
25 May 10 |
nicklas |
if (error < 0) |
5350 |
25 May 10 |
nicklas |
960 |
{ |
5350 |
25 May 10 |
nicklas |
y = y + ystep; |
5350 |
25 May 10 |
nicklas |
error = error + deltax; |
5350 |
25 May 10 |
nicklas |
963 |
} |
5350 |
25 May 10 |
nicklas |
964 |
} |
5350 |
25 May 10 |
nicklas |
return xDataArray; |
5350 |
25 May 10 |
nicklas |
966 |
} |
5350 |
25 May 10 |
nicklas |
967 |
|
5350 |
25 May 10 |
nicklas |
//Draw rectangle at specified point with specified width and height. |
5350 |
25 May 10 |
nicklas |
function drawRectangle(pen,point,width,height) |
5350 |
25 May 10 |
nicklas |
970 |
{ |
5350 |
25 May 10 |
nicklas |
//Check arguments for null values |
5350 |
25 May 10 |
nicklas |
if(!pen || !point || !width || !height) |
5350 |
25 May 10 |
nicklas |
return false; |
5350 |
25 May 10 |
nicklas |
974 |
|
5350 |
25 May 10 |
nicklas |
width=Math.round(width*scale); |
5350 |
25 May 10 |
nicklas |
height=Math.round(height*scale); |
5350 |
25 May 10 |
nicklas |
977 |
|
5350 |
25 May 10 |
nicklas |
var rectDiv=canvasDiv.appendChild(document.createElement("div")); |
5350 |
25 May 10 |
nicklas |
var iHtml=new Array(); |
5350 |
25 May 10 |
nicklas |
980 |
|
5350 |
25 May 10 |
nicklas |
var penWidth=parseInt(pen.width); |
5350 |
25 May 10 |
nicklas |
var hexColor=pen.color.getHex(); |
5350 |
25 May 10 |
nicklas |
983 |
|
5350 |
25 May 10 |
nicklas |
//If pen width is less than height or width specified use fillRectangle method |
5350 |
25 May 10 |
nicklas |
if(penWidth>=height || penWidth>=width) |
5350 |
25 May 10 |
nicklas |
return this.fillRectangle(pen.color,point,width,height); |
5350 |
25 May 10 |
nicklas |
987 |
|
7419 |
03 Nov 17 |
nicklas |
var phPoint=logicalToPhysicalPoint(point); |
5350 |
25 May 10 |
nicklas |
989 |
|
5350 |
25 May 10 |
nicklas |
//Draw 4 sides of the rectangle. |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + phPoint.x + "px;top:" + phPoint.y + "px;width:" + width + "px;height:" + penWidth + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + phPoint.x + "px;top:" + (phPoint.y+height-penWidth) + "px;width:" + width + "px;height:" + penWidth + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + phPoint.x + "px;top:" + (phPoint.y+penWidth) + "px;width:" + penWidth + "px;height:" + (height-2*penWidth+1) + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + (phPoint.x+width-penWidth) + "px;top:" + (phPoint.y+penWidth) + "px;width:" + penWidth + "px;height:" + (height-2*penWidth+1) + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
995 |
|
5350 |
25 May 10 |
nicklas |
rectDiv.innerHTML=iHtml.join(""); |
5350 |
25 May 10 |
nicklas |
return rectDiv; |
5350 |
25 May 10 |
nicklas |
998 |
} |
5350 |
25 May 10 |
nicklas |
999 |
|
5350 |
25 May 10 |
nicklas |
//Draw color filled rectangle at specified point with specified color, width and height |
5350 |
25 May 10 |
nicklas |
function fillRectangle(color,point,width,height) |
5350 |
25 May 10 |
nicklas |
1002 |
{ |
5350 |
25 May 10 |
nicklas |
//Check arguments for null values |
5350 |
25 May 10 |
nicklas |
if(!color || !point || !width || !height) |
5350 |
25 May 10 |
nicklas |
return false; |
5350 |
25 May 10 |
nicklas |
1006 |
|
5350 |
25 May 10 |
nicklas |
width=Math.round(width*scale); |
5350 |
25 May 10 |
nicklas |
height=Math.round(height*scale); |
5350 |
25 May 10 |
nicklas |
1009 |
|
5350 |
25 May 10 |
nicklas |
var rectDiv=canvasDiv.appendChild(document.createElement("div")); |
7419 |
03 Nov 17 |
nicklas |
var phPoint=logicalToPhysicalPoint(point); |
5350 |
25 May 10 |
nicklas |
1012 |
|
5350 |
25 May 10 |
nicklas |
var hexColor=color.getHex(); |
5350 |
25 May 10 |
nicklas |
1014 |
|
5350 |
25 May 10 |
nicklas |
//Draw a single div element |
5350 |
25 May 10 |
nicklas |
rectDiv.innerHTML="<DIV style=\"position:absolute;overflow:hidden;left:" + phPoint.x + "px;top:" + phPoint.y + "px;width:" + width + "px;height:" + height + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
return rectDiv; |
5350 |
25 May 10 |
nicklas |
1018 |
} |
5350 |
25 May 10 |
nicklas |
1019 |
|
5350 |
25 May 10 |
nicklas |
//This is a private function to draw an ellipse with width 1px. |
5350 |
25 May 10 |
nicklas |
//It is used by drawEllipse method. |
5350 |
25 May 10 |
nicklas |
//Mid point algorithm is used for the drawing |
5350 |
25 May 10 |
nicklas |
function drawEllipseSingle(pen,center,width,height) |
5350 |
25 May 10 |
nicklas |
1024 |
{ |
5350 |
25 May 10 |
nicklas |
//Check arguments for null values |
5350 |
25 May 10 |
nicklas |
if(!pen || !center || !width || !height) |
5350 |
25 May 10 |
nicklas |
return false; |
5350 |
25 May 10 |
nicklas |
1028 |
|
5350 |
25 May 10 |
nicklas |
var ellipseDiv=canvasDiv.appendChild(document.createElement("div")); |
5350 |
25 May 10 |
nicklas |
var iHtml=new Array(); |
5350 |
25 May 10 |
nicklas |
1031 |
|
5350 |
25 May 10 |
nicklas |
var penWidth=parseInt(pen.width); |
5350 |
25 May 10 |
nicklas |
var hexColor=pen.color.getHex(); |
5350 |
25 May 10 |
nicklas |
1034 |
|
5350 |
25 May 10 |
nicklas |
var a=Math.round(width/2); |
5350 |
25 May 10 |
nicklas |
var b=Math.round(height/2); |
5350 |
25 May 10 |
nicklas |
var xc=center.x; |
5350 |
25 May 10 |
nicklas |
var yc=center.y; |
5350 |
25 May 10 |
nicklas |
1039 |
|
5350 |
25 May 10 |
nicklas |
var x=0; |
5350 |
25 May 10 |
nicklas |
var y=b; |
5350 |
25 May 10 |
nicklas |
var a2=a*a; |
5350 |
25 May 10 |
nicklas |
var b2=b*b; |
5350 |
25 May 10 |
nicklas |
1044 |
|
5350 |
25 May 10 |
nicklas |
var yp=y; |
5350 |
25 May 10 |
nicklas |
var xp=x; |
5350 |
25 May 10 |
nicklas |
var divWidth; |
5350 |
25 May 10 |
nicklas |
var divHeight; |
5350 |
25 May 10 |
nicklas |
1049 |
|
5350 |
25 May 10 |
nicklas |
while(b2*x < a2*y) |
5350 |
25 May 10 |
nicklas |
1051 |
{ |
5350 |
25 May 10 |
nicklas |
x++; |
5350 |
25 May 10 |
nicklas |
if((b2*x*x + a2*(y-0.5)*(y-0.5) - a2*b2) >=0) |
5350 |
25 May 10 |
nicklas |
y--; |
5350 |
25 May 10 |
nicklas |
1055 |
|
5350 |
25 May 10 |
nicklas |
if(x==1 && y!=yp) |
5350 |
25 May 10 |
nicklas |
1057 |
{ |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + (xc+x) + "px;top:" + (yc+y) + "px;width:1px;height:1px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + (xc+x) + "px;top:" + (yc-y) + "px;width:1px;height:1px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
1060 |
} |
5350 |
25 May 10 |
nicklas |
if(y!=yp) |
5350 |
25 May 10 |
nicklas |
1062 |
{ |
5350 |
25 May 10 |
nicklas |
divWidth=x-xp; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + (xc+xp) + "px;top:" + (yc+yp-penWidth+1) + "px;height:" + penWidth + "px;width:" + divWidth + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + (xc-xp-divWidth+1) + "px;top:" + (yc+yp-penWidth+1) + "px;height:" + penWidth + "px;width:" + divWidth + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + (xc+xp) + "px;top:" + (yc-yp) + "px;height:" + penWidth + "px;width:" + divWidth + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + (xc-xp-divWidth+1) + "px;top:" + (yc-yp) + "px;height:" + penWidth + "px;width:" + divWidth + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
1068 |
|
5350 |
25 May 10 |
nicklas |
yp=y; |
5350 |
25 May 10 |
nicklas |
xp=x; |
5350 |
25 May 10 |
nicklas |
1071 |
} |
5350 |
25 May 10 |
nicklas |
1072 |
|
5350 |
25 May 10 |
nicklas |
if(b2*x >= a2*y) |
5350 |
25 May 10 |
nicklas |
1074 |
{ |
5350 |
25 May 10 |
nicklas |
divWidth=x-xp+1; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + (xc+xp) + "px;top:" + (yc+yp-penWidth+1) + "px;height:" + penWidth + "px;width:" + divWidth + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + (xc-xp-divWidth+1) + "px;top:" + (yc+yp-penWidth+1) + "px;height:" + penWidth + "px;width:" + divWidth + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + (xc+xp) + "px;top:" + (yc-yp) + "px;height:" + penWidth + "px;width:" + divWidth + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + (xc-xp-divWidth+1) + "px;top:" + (yc-yp) + "px;height:" + penWidth + "px;width:" + divWidth + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
1080 |
} |
5350 |
25 May 10 |
nicklas |
1081 |
} |
5350 |
25 May 10 |
nicklas |
1082 |
|
5350 |
25 May 10 |
nicklas |
yp=y; |
5350 |
25 May 10 |
nicklas |
xp=x; |
5350 |
25 May 10 |
nicklas |
1085 |
|
5350 |
25 May 10 |
nicklas |
while(y!=0) |
5350 |
25 May 10 |
nicklas |
1087 |
{ |
5350 |
25 May 10 |
nicklas |
y--; |
5350 |
25 May 10 |
nicklas |
if((b2*(x+0.5)*(x+0.5) + a2*y*y - a2*b2)<=0) |
5350 |
25 May 10 |
nicklas |
x++; |
5350 |
25 May 10 |
nicklas |
1091 |
|
5350 |
25 May 10 |
nicklas |
if(x!=xp) |
5350 |
25 May 10 |
nicklas |
1093 |
{ |
5350 |
25 May 10 |
nicklas |
divHeight=yp-y; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + (xc+xp-penWidth+1) + "px;top:" + (yc+yp-divHeight+1) + "px;width:" + penWidth + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + (xc+xp-penWidth+1) + "px;top:" + (yc-yp) + "px;width:" + penWidth + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + (xc-xp) + "px;top:" + (yc+yp-divHeight+1) + "px;width:" + penWidth + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + (xc-xp) + "px;top:" + (yc-yp) + "px;width:" + penWidth + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
1099 |
|
5350 |
25 May 10 |
nicklas |
xp=x; |
5350 |
25 May 10 |
nicklas |
yp=y; |
5350 |
25 May 10 |
nicklas |
1102 |
} |
5350 |
25 May 10 |
nicklas |
1103 |
|
5350 |
25 May 10 |
nicklas |
if(y==0) |
5350 |
25 May 10 |
nicklas |
1105 |
{ |
5350 |
25 May 10 |
nicklas |
divHeight=yp-y+1; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + (xc+xp-penWidth+1) + "px;top:" + (yc+yp-divHeight+1) + "px;width:" + penWidth + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + (xc+xp-penWidth+1) + "px;top:" + (yc-yp) + "px;width:" + penWidth + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + (xc-xp) + "px;top:" + (yc+yp-divHeight+1) + "px;width:" + penWidth + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + (xc-xp) + "px;top:" + (yc-yp) + "px;width:" + penWidth + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
1111 |
|
5350 |
25 May 10 |
nicklas |
xp=x; |
5350 |
25 May 10 |
nicklas |
yp=y; |
5350 |
25 May 10 |
nicklas |
1114 |
} |
5350 |
25 May 10 |
nicklas |
1115 |
|
5350 |
25 May 10 |
nicklas |
1116 |
} |
5350 |
25 May 10 |
nicklas |
1117 |
|
5350 |
25 May 10 |
nicklas |
ellipseDiv.innerHTML=iHtml.join(""); |
5350 |
25 May 10 |
nicklas |
return ellipseDiv; |
5350 |
25 May 10 |
nicklas |
1120 |
} |
5350 |
25 May 10 |
nicklas |
1121 |
|
5350 |
25 May 10 |
nicklas |
//Draw ellipse with specified center, width and height. |
5350 |
25 May 10 |
nicklas |
//Mid point algorithm is used for basic drawing. |
5350 |
25 May 10 |
nicklas |
function drawEllipse(pen,center,width,height) |
5350 |
25 May 10 |
nicklas |
1125 |
{ |
5350 |
25 May 10 |
nicklas |
//Check arguments for null values |
5350 |
25 May 10 |
nicklas |
if(!pen || !center || !width || !height) |
5350 |
25 May 10 |
nicklas |
return false; |
5350 |
25 May 10 |
nicklas |
1129 |
|
5350 |
25 May 10 |
nicklas |
width*=scale; |
5350 |
25 May 10 |
nicklas |
height*=scale; |
5350 |
25 May 10 |
nicklas |
1132 |
|
5350 |
25 May 10 |
nicklas |
var ellipseDiv=canvasDiv.appendChild(document.createElement("div")); |
5350 |
25 May 10 |
nicklas |
var iHtml=new Array(); |
5350 |
25 May 10 |
nicklas |
1135 |
|
7419 |
03 Nov 17 |
nicklas |
var phCenter=logicalToPhysicalPoint(center); |
5350 |
25 May 10 |
nicklas |
1137 |
|
5350 |
25 May 10 |
nicklas |
var penWidth=parseInt(pen.width); |
5350 |
25 May 10 |
nicklas |
if(penWidth<=1) |
5350 |
25 May 10 |
nicklas |
1140 |
{ |
5350 |
25 May 10 |
nicklas |
return drawEllipseSingle(pen,phCenter,width,height); |
5350 |
25 May 10 |
nicklas |
1142 |
} |
5350 |
25 May 10 |
nicklas |
1143 |
|
5350 |
25 May 10 |
nicklas |
var hexColor=pen.color.getHex(); |
5350 |
25 May 10 |
nicklas |
1145 |
|
5350 |
25 May 10 |
nicklas |
var a=Math.round(width/2); |
5350 |
25 May 10 |
nicklas |
var b=Math.round(height/2); |
5350 |
25 May 10 |
nicklas |
var xc=phCenter.x; |
5350 |
25 May 10 |
nicklas |
var yc=phCenter.y; |
5350 |
25 May 10 |
nicklas |
1150 |
|
5350 |
25 May 10 |
nicklas |
//For inner ellipse |
5350 |
25 May 10 |
nicklas |
var ai=a-penWidth + 1; |
5350 |
25 May 10 |
nicklas |
var bi=b-penWidth + 1; |
5350 |
25 May 10 |
nicklas |
1154 |
|
5350 |
25 May 10 |
nicklas |
//For drawing ellipse having width more than 1px, inner ellipse is required to be considered |
5350 |
25 May 10 |
nicklas |
var res=getInnerEllipse(phCenter,ai*2,bi*2) |
5350 |
25 May 10 |
nicklas |
1157 |
|
5350 |
25 May 10 |
nicklas |
var xArray=res[0]; |
5350 |
25 May 10 |
nicklas |
var xArrayI=res[1]; |
5350 |
25 May 10 |
nicklas |
1160 |
|
5350 |
25 May 10 |
nicklas |
var yi=bi; |
5350 |
25 May 10 |
nicklas |
var ai2=ai*ai; |
5350 |
25 May 10 |
nicklas |
var bi2=bi*bi; |
5350 |
25 May 10 |
nicklas |
1164 |
|
5350 |
25 May 10 |
nicklas |
var x=0; |
5350 |
25 May 10 |
nicklas |
var y=b; |
5350 |
25 May 10 |
nicklas |
var a2=a*a; |
5350 |
25 May 10 |
nicklas |
var b2=b*b; |
5350 |
25 May 10 |
nicklas |
1169 |
|
5350 |
25 May 10 |
nicklas |
var xp,yp; |
5350 |
25 May 10 |
nicklas |
1171 |
|
5350 |
25 May 10 |
nicklas |
xp=1; |
5350 |
25 May 10 |
nicklas |
yp=y; |
5350 |
25 May 10 |
nicklas |
var ypi=yi; |
5350 |
25 May 10 |
nicklas |
1175 |
|
5350 |
25 May 10 |
nicklas |
var xT; |
5350 |
25 May 10 |
nicklas |
var divWidth; |
5350 |
25 May 10 |
nicklas |
var divHeight=1; |
5350 |
25 May 10 |
nicklas |
1179 |
|
5350 |
25 May 10 |
nicklas |
while(b2*x < a2*y) |
5350 |
25 May 10 |
nicklas |
1181 |
{ |
5350 |
25 May 10 |
nicklas |
x++; |
5350 |
25 May 10 |
nicklas |
if((b2*x*x + a2*(y-0.5)*(y-0.5) - a2*b2) >=0) |
5350 |
25 May 10 |
nicklas |
y--; |
5350 |
25 May 10 |
nicklas |
1185 |
|
5350 |
25 May 10 |
nicklas |
if(y+1<bi) |
5350 |
25 May 10 |
nicklas |
1187 |
{ |
5350 |
25 May 10 |
nicklas |
if(y!=yp) |
5350 |
25 May 10 |
nicklas |
1189 |
{ |
5350 |
25 May 10 |
nicklas |
xT=xc-x+1; |
5350 |
25 May 10 |
nicklas |
divWidth=(x-1)+1-xArray[yp]; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + xT + "px;top:" + (yc-yp) + "px;width:" + divWidth + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + xT + "px;top:" + (yc+yp) + "px;width:" + divWidth + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
1194 |
|
5350 |
25 May 10 |
nicklas |
xT=xT+2*(x-1)+1-divWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + xT + "px;top:" + (yc-yp) + "px;width:" + divWidth + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + xT + "px;top:" + (yc+yp) + "px;width:" + divWidth + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
1198 |
|
5350 |
25 May 10 |
nicklas |
yp=y; |
5350 |
25 May 10 |
nicklas |
xp=x; |
5350 |
25 May 10 |
nicklas |
1201 |
} |
5350 |
25 May 10 |
nicklas |
//Last step in loop |
5350 |
25 May 10 |
nicklas |
if(b2*x >= a2*y) |
5350 |
25 May 10 |
nicklas |
1204 |
{ |
5350 |
25 May 10 |
nicklas |
xT=xc-x; |
5350 |
25 May 10 |
nicklas |
divWidth=x+1-xArray[yp]; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + xT + "px;top:" + (yc-y) + "px;width:" + divWidth + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + xT + "px;top:" + (yc+y) + "px;width:" + divWidth + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
1209 |
|
5350 |
25 May 10 |
nicklas |
xT=xT+2*x+1-divWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + xT + "px;top:" + (yc-y) + "px;width:" + divWidth + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + xT + "px;top:" + (yc+y) + "px;width:" + divWidth + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
1213 |
} |
5350 |
25 May 10 |
nicklas |
1214 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
1216 |
{ |
5350 |
25 May 10 |
nicklas |
if(x==1 && y!=yp) //Topmost and bottom most points, to be tested |
5350 |
25 May 10 |
nicklas |
1218 |
{ |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;width:1px;height:1px;left:" + xc + "px;top:" + (yc+yp-1) + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;width:1px;height:1px;left:" + xc + "px;top:" + (yc-yp) + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
1221 |
} |
5350 |
25 May 10 |
nicklas |
if(y!=yp) |
5350 |
25 May 10 |
nicklas |
1223 |
{ |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + (xc-x+1) + "px;top:" + (yc-yp) + "px;width:" + (2*(x-1)+1) + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + (xc-x+1) + "px;top:" + (yc+yp) + "px;width:" + (2*(x-1)+1) + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
yp=y; |
5350 |
25 May 10 |
nicklas |
1227 |
} |
5350 |
25 May 10 |
nicklas |
1228 |
|
5350 |
25 May 10 |
nicklas |
//Last step in loop |
5350 |
25 May 10 |
nicklas |
if(y==bi || y==0) |
5350 |
25 May 10 |
nicklas |
1231 |
{ |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + (xc-x) + "px;top:" + (yc-y) + "px;width:" + (2*x+1) + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + (xc-x) + "px;top:" + (yc+y) + "px;width:" + (2*x+1) + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
1234 |
} |
5350 |
25 May 10 |
nicklas |
1235 |
} |
5350 |
25 May 10 |
nicklas |
1236 |
} |
5350 |
25 May 10 |
nicklas |
1237 |
|
5350 |
25 May 10 |
nicklas |
xp=x; |
5350 |
25 May 10 |
nicklas |
yp=y; |
5350 |
25 May 10 |
nicklas |
divHeight=1; |
5350 |
25 May 10 |
nicklas |
var xpi=xArray[y]; |
5350 |
25 May 10 |
nicklas |
1242 |
|
5350 |
25 May 10 |
nicklas |
while(y!=0) |
5350 |
25 May 10 |
nicklas |
1244 |
{ |
5350 |
25 May 10 |
nicklas |
y--; |
5350 |
25 May 10 |
nicklas |
if((b2*(x+0.5)*(x+0.5) + a2*y*y - a2*b2)<=0) |
5350 |
25 May 10 |
nicklas |
x++; |
5350 |
25 May 10 |
nicklas |
1248 |
|
5350 |
25 May 10 |
nicklas |
if(y+1<bi) |
5350 |
25 May 10 |
nicklas |
1250 |
{ |
5350 |
25 May 10 |
nicklas |
if(x!=xp || xArray[y]!=xpi) |
5350 |
25 May 10 |
nicklas |
1252 |
{ |
5350 |
25 May 10 |
nicklas |
divHeight=yp-y; |
5350 |
25 May 10 |
nicklas |
1254 |
|
5350 |
25 May 10 |
nicklas |
xT=xc-xp; |
5350 |
25 May 10 |
nicklas |
divWidth=xp+1-xArray[y+1]; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + xT + "px;top:" + (yc-yp) + "px;width:" + divWidth + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + xT + "px;top:" + (yc+y+1) + "px;width:" + divWidth + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
1259 |
|
5350 |
25 May 10 |
nicklas |
xT=xT+2*xp+1-divWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + xT + "px;top:" + (yc-yp) + "px;width:" + divWidth + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + xT + "px;top:" + (yc+y+1) + "px;width:" + divWidth + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
1263 |
|
5350 |
25 May 10 |
nicklas |
xp=x; |
5350 |
25 May 10 |
nicklas |
yp=y; |
5350 |
25 May 10 |
nicklas |
xpi=xArray[y]; |
5350 |
25 May 10 |
nicklas |
1267 |
} |
5350 |
25 May 10 |
nicklas |
1268 |
|
5350 |
25 May 10 |
nicklas |
//Last step in loop |
5350 |
25 May 10 |
nicklas |
if(y==0) |
5350 |
25 May 10 |
nicklas |
1271 |
{ |
5350 |
25 May 10 |
nicklas |
divHeight=yp-y+1; |
5350 |
25 May 10 |
nicklas |
1273 |
|
5350 |
25 May 10 |
nicklas |
xT=xc-x; |
5350 |
25 May 10 |
nicklas |
divWidth=x+1-xArray[y]; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + xT + "px;top:" + (yc-yp) + "px;width:" + divWidth + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + xT + "px;top:" + (yc+y) + "px;width:" + divWidth + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
1278 |
|
5350 |
25 May 10 |
nicklas |
xT=xT+2*x+1-divWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + xT + "px;top:" + (yc-yp) + "px;width:" + divWidth + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + xT + "px;top:" + (yc+y) + "px;width:" + divWidth + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
1282 |
|
5350 |
25 May 10 |
nicklas |
xp=x; |
5350 |
25 May 10 |
nicklas |
yp=y; |
5350 |
25 May 10 |
nicklas |
xpi=xArray[y]; |
5350 |
25 May 10 |
nicklas |
1286 |
} |
5350 |
25 May 10 |
nicklas |
1287 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
1289 |
{ |
5350 |
25 May 10 |
nicklas |
if(x!=xp) |
5350 |
25 May 10 |
nicklas |
1291 |
{ |
5350 |
25 May 10 |
nicklas |
divHeight=yp-y; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + (xc-xp) + "px;top:" + (yc-yp) + "px;width:" + (2*xp+1) + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + (xc-xp) + "px;top:" + (yc+y+1) + "px;width:" + (2*xp+1) + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
1295 |
|
5350 |
25 May 10 |
nicklas |
xp=x; |
5350 |
25 May 10 |
nicklas |
yp=y; |
5350 |
25 May 10 |
nicklas |
xpi=xArray[y]; |
5350 |
25 May 10 |
nicklas |
1299 |
} |
5350 |
25 May 10 |
nicklas |
1300 |
|
5350 |
25 May 10 |
nicklas |
//Last step in loop |
5350 |
25 May 10 |
nicklas |
if(y==bi || y==0) |
5350 |
25 May 10 |
nicklas |
1303 |
{ |
5350 |
25 May 10 |
nicklas |
divHeight=yp-y+1; |
5350 |
25 May 10 |
nicklas |
1305 |
|
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + (xc-x) + "px;top:" + (yc-yp) + "px;width:" + (2*x+1) + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + (xc-x) + "px;top:" + (yc+y) + "px;width:" + (2*x+1) + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
1308 |
|
5350 |
25 May 10 |
nicklas |
xp=x; |
5350 |
25 May 10 |
nicklas |
yp=y; |
5350 |
25 May 10 |
nicklas |
xpi=xArray[y]; |
5350 |
25 May 10 |
nicklas |
1312 |
} |
5350 |
25 May 10 |
nicklas |
1313 |
} |
5350 |
25 May 10 |
nicklas |
1314 |
} |
5350 |
25 May 10 |
nicklas |
1315 |
|
5350 |
25 May 10 |
nicklas |
ellipseDiv.innerHTML=iHtml.join(""); |
5350 |
25 May 10 |
nicklas |
return ellipseDiv; |
5350 |
25 May 10 |
nicklas |
1318 |
} |
5350 |
25 May 10 |
nicklas |
1319 |
|
5350 |
25 May 10 |
nicklas |
//For ellipse having width more than 1 px, get the coordinates for inner ellipse. |
5350 |
25 May 10 |
nicklas |
function getInnerEllipse(center,w,h) |
5350 |
25 May 10 |
nicklas |
1322 |
{ |
5350 |
25 May 10 |
nicklas |
var a=Math.round(w/2); |
5350 |
25 May 10 |
nicklas |
var b=Math.round(h/2); |
5350 |
25 May 10 |
nicklas |
var xc=center.x; |
5350 |
25 May 10 |
nicklas |
var yc=center.y; |
5350 |
25 May 10 |
nicklas |
1327 |
|
7419 |
03 Nov 17 |
nicklas |
var xArray=new Array(); |
7419 |
03 Nov 17 |
nicklas |
var xArrayI=new Array(); |
5350 |
25 May 10 |
nicklas |
1330 |
|
5350 |
25 May 10 |
nicklas |
var x=0; |
5350 |
25 May 10 |
nicklas |
var y=b; |
5350 |
25 May 10 |
nicklas |
var a2=a*a; |
5350 |
25 May 10 |
nicklas |
var b2=b*b; |
5350 |
25 May 10 |
nicklas |
1335 |
|
5350 |
25 May 10 |
nicklas |
xArray[y]=x; |
5350 |
25 May 10 |
nicklas |
xArrayI[y]=x; |
5350 |
25 May 10 |
nicklas |
1338 |
|
5350 |
25 May 10 |
nicklas |
var divWidth; |
5350 |
25 May 10 |
nicklas |
var divHeight; |
5350 |
25 May 10 |
nicklas |
1341 |
|
5350 |
25 May 10 |
nicklas |
//Upper and Lower portions of the ellipse |
5350 |
25 May 10 |
nicklas |
while(b2*x < a2*y) |
5350 |
25 May 10 |
nicklas |
1344 |
{ |
5350 |
25 May 10 |
nicklas |
x++; |
5350 |
25 May 10 |
nicklas |
if((b2*x*x + a2*(y-0.5)*(y-0.5) - a2*b2) >=0) |
5350 |
25 May 10 |
nicklas |
y--; |
5350 |
25 May 10 |
nicklas |
if(!xArray[y]) |
5350 |
25 May 10 |
nicklas |
xArray[y]=x; |
5350 |
25 May 10 |
nicklas |
1350 |
|
5350 |
25 May 10 |
nicklas |
xArrayI[y]=x; |
5350 |
25 May 10 |
nicklas |
1352 |
} |
5350 |
25 May 10 |
nicklas |
1353 |
|
5350 |
25 May 10 |
nicklas |
//Left and Right portions of the ellipse |
5350 |
25 May 10 |
nicklas |
while(y!=0) |
5350 |
25 May 10 |
nicklas |
1356 |
{ |
5350 |
25 May 10 |
nicklas |
y--; |
5350 |
25 May 10 |
nicklas |
if((b2*(x+0.5)*(x+0.5) + a2*y*y - a2*b2)<=0) |
5350 |
25 May 10 |
nicklas |
x++; |
5350 |
25 May 10 |
nicklas |
1360 |
|
5350 |
25 May 10 |
nicklas |
xArray[y]=x; |
5350 |
25 May 10 |
nicklas |
xArrayI[y]=x; |
5350 |
25 May 10 |
nicklas |
1363 |
} |
5350 |
25 May 10 |
nicklas |
return new Array(xArray,xArrayI); |
5350 |
25 May 10 |
nicklas |
1365 |
} |
5350 |
25 May 10 |
nicklas |
1366 |
|
5350 |
25 May 10 |
nicklas |
//Draw circle with specified center and radius. |
5350 |
25 May 10 |
nicklas |
//Uses drawEllipse method only. |
5350 |
25 May 10 |
nicklas |
function drawCircle(pen,center,radius) |
5350 |
25 May 10 |
nicklas |
1370 |
{ |
5350 |
25 May 10 |
nicklas |
//Check arguments for null values |
5350 |
25 May 10 |
nicklas |
if(!pen || !center || !radius) |
5350 |
25 May 10 |
nicklas |
return false; |
5350 |
25 May 10 |
nicklas |
1374 |
|
5350 |
25 May 10 |
nicklas |
return drawEllipse(pen,center,2*radius,2*radius); |
5350 |
25 May 10 |
nicklas |
1376 |
} |
5350 |
25 May 10 |
nicklas |
1377 |
|
5350 |
25 May 10 |
nicklas |
//Draw circle filled with the specified color alongwith specified center and radius. |
5350 |
25 May 10 |
nicklas |
//Uses drawEllipse method only. |
5350 |
25 May 10 |
nicklas |
function fillCircle(color,center,radius) |
5350 |
25 May 10 |
nicklas |
1381 |
{ |
5350 |
25 May 10 |
nicklas |
//Check arguments for null values |
5350 |
25 May 10 |
nicklas |
if(!color || !center || !radius) |
5350 |
25 May 10 |
nicklas |
return false; |
5350 |
25 May 10 |
nicklas |
1385 |
|
5350 |
25 May 10 |
nicklas |
return fillEllipse(color,center,2*radius,2*radius); |
5350 |
25 May 10 |
nicklas |
1387 |
} |
5350 |
25 May 10 |
nicklas |
1388 |
|
5350 |
25 May 10 |
nicklas |
//Draw ellipse filled with specified color and other parameters, center, width and height. |
5350 |
25 May 10 |
nicklas |
//Mid point algorithm is used for basic ellipse drawing. |
5350 |
25 May 10 |
nicklas |
function fillEllipse(color,center,width,height) |
5350 |
25 May 10 |
nicklas |
1392 |
{ |
5350 |
25 May 10 |
nicklas |
//Check arguments for null values |
5350 |
25 May 10 |
nicklas |
if(!color || !center || !width || !height) |
5350 |
25 May 10 |
nicklas |
return false; |
5350 |
25 May 10 |
nicklas |
1396 |
|
5350 |
25 May 10 |
nicklas |
width*=scale; |
5350 |
25 May 10 |
nicklas |
height*=scale; |
5350 |
25 May 10 |
nicklas |
1399 |
|
5350 |
25 May 10 |
nicklas |
var ellipseDiv=canvasDiv.appendChild(document.createElement("div")); |
5350 |
25 May 10 |
nicklas |
var iHtml=new Array(); |
5350 |
25 May 10 |
nicklas |
1402 |
|
7419 |
03 Nov 17 |
nicklas |
var phCenter=logicalToPhysicalPoint(center); |
5350 |
25 May 10 |
nicklas |
1404 |
|
5350 |
25 May 10 |
nicklas |
var a=Math.round(width/2); |
5350 |
25 May 10 |
nicklas |
var b=Math.round(height/2); |
5350 |
25 May 10 |
nicklas |
var xc=phCenter.x; |
5350 |
25 May 10 |
nicklas |
var yc=phCenter.y; |
5350 |
25 May 10 |
nicklas |
var hexColor=color.getHex(); |
5350 |
25 May 10 |
nicklas |
1410 |
|
5350 |
25 May 10 |
nicklas |
var x=0; |
5350 |
25 May 10 |
nicklas |
var y=b; |
5350 |
25 May 10 |
nicklas |
var a2=a*a; |
5350 |
25 May 10 |
nicklas |
var b2=b*b; |
5350 |
25 May 10 |
nicklas |
1415 |
|
5350 |
25 May 10 |
nicklas |
var xp,yp; |
5350 |
25 May 10 |
nicklas |
1417 |
|
5350 |
25 May 10 |
nicklas |
xp=1; |
5350 |
25 May 10 |
nicklas |
yp=y; |
5350 |
25 May 10 |
nicklas |
1420 |
|
5350 |
25 May 10 |
nicklas |
//Upper and Lower portion of the ellipse |
5350 |
25 May 10 |
nicklas |
while(b2*x < a2*y) |
5350 |
25 May 10 |
nicklas |
1423 |
{ |
5350 |
25 May 10 |
nicklas |
x++; |
5350 |
25 May 10 |
nicklas |
if((b2*x*x + a2*(y-0.5)*(y-0.5) - a2*b2) >=0) |
5350 |
25 May 10 |
nicklas |
y--; |
5350 |
25 May 10 |
nicklas |
1427 |
|
5350 |
25 May 10 |
nicklas |
if(x==1 && y!=yp) //Topmost and bottom most points, to be tested |
5350 |
25 May 10 |
nicklas |
1429 |
{ |
5350 |
25 May 10 |
nicklas |
1430 |
|
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;width:1px;height:1px;left:" + xc + "px;top:" + (yc+yp-1) + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;width:1px;height:1px;left:" + xc + "px;top:" + (yc-yp) + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
1433 |
|
5350 |
25 May 10 |
nicklas |
1434 |
} |
5350 |
25 May 10 |
nicklas |
if(y!=yp) |
5350 |
25 May 10 |
nicklas |
1436 |
{ |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;height:1px;left:" + (xc-x+1) + "px;top:" + (yc-yp) + "px;width:" + (2*x-1) + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;height:1px;left:" + (xc-x+1) + "px;top:" + (yc+yp) + "px;width:" + (2*x-1) + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
1439 |
|
5350 |
25 May 10 |
nicklas |
yp=y; |
5350 |
25 May 10 |
nicklas |
xp=x; |
5350 |
25 May 10 |
nicklas |
1442 |
} |
5350 |
25 May 10 |
nicklas |
1443 |
|
5350 |
25 May 10 |
nicklas |
1444 |
|
5350 |
25 May 10 |
nicklas |
//Last step in loop |
5350 |
25 May 10 |
nicklas |
if(b2*x >= a2*y) |
5350 |
25 May 10 |
nicklas |
1447 |
{ |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;height:1px;left:" + (xc-x) + "px;top:" + (yc-yp) + "px;width:" + (2*x+1) + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;height:1px;left:" + (xc-x) + "px;top:" + (yc+yp) + "px;width:" + (2*x+1) + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
1450 |
} |
5350 |
25 May 10 |
nicklas |
1451 |
} |
5350 |
25 May 10 |
nicklas |
1452 |
|
5350 |
25 May 10 |
nicklas |
xp=x; |
5350 |
25 May 10 |
nicklas |
yp=y; |
5350 |
25 May 10 |
nicklas |
var divHeight=1; |
5350 |
25 May 10 |
nicklas |
1456 |
|
5350 |
25 May 10 |
nicklas |
//Left and Right portion of the ellipse |
5350 |
25 May 10 |
nicklas |
while(y!=0) |
5350 |
25 May 10 |
nicklas |
1459 |
{ |
5350 |
25 May 10 |
nicklas |
y--; |
5350 |
25 May 10 |
nicklas |
if((b2*(x+0.5)*(x+0.5) + a2*y*y - a2*b2)<=0) |
5350 |
25 May 10 |
nicklas |
x++; |
5350 |
25 May 10 |
nicklas |
1463 |
|
5350 |
25 May 10 |
nicklas |
if(x!=xp) |
5350 |
25 May 10 |
nicklas |
1465 |
{ |
5350 |
25 May 10 |
nicklas |
divHeight=yp-y; |
5350 |
25 May 10 |
nicklas |
1467 |
|
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + (xc-xp) + "px;top:" + (yc-yp) + "px;width:" + (2*xp+1) + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + (xc-xp) + "px;top:" + (yc+y+1) + "px;width:" + (2*xp+1) + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
1470 |
|
5350 |
25 May 10 |
nicklas |
xp=x; |
5350 |
25 May 10 |
nicklas |
yp=y; |
5350 |
25 May 10 |
nicklas |
1473 |
} |
5350 |
25 May 10 |
nicklas |
1474 |
|
5350 |
25 May 10 |
nicklas |
//Last step in loop |
5350 |
25 May 10 |
nicklas |
if(y==0) |
5350 |
25 May 10 |
nicklas |
1477 |
{ |
5350 |
25 May 10 |
nicklas |
divHeight=yp-y+1; |
5350 |
25 May 10 |
nicklas |
1479 |
|
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + (xc-xp) + "px;top:" + (yc-yp) + "px;width:" + (2*x+1) + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + (xc-xp) + "px;top:" + (yc+y) + "px;width:" + (2*x+1) + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
1482 |
} |
5350 |
25 May 10 |
nicklas |
1483 |
} |
5350 |
25 May 10 |
nicklas |
1484 |
|
5350 |
25 May 10 |
nicklas |
ellipseDiv.innerHTML=iHtml.join(""); |
5350 |
25 May 10 |
nicklas |
return ellipseDiv; |
5350 |
25 May 10 |
nicklas |
1487 |
} |
5350 |
25 May 10 |
nicklas |
1488 |
|
5350 |
25 May 10 |
nicklas |
//Draw arc filled with specified color, center, width, height, start angle and swap angle. |
5350 |
25 May 10 |
nicklas |
function fillArc(color,center,width,height,startAngle,swapAngle) |
5350 |
25 May 10 |
nicklas |
1491 |
{ |
5350 |
25 May 10 |
nicklas |
//Check arguments for null values |
5350 |
25 May 10 |
nicklas |
if(!color || !center || !width || !height || startAngle==null || swapAngle==null) |
5350 |
25 May 10 |
nicklas |
return false; |
5350 |
25 May 10 |
nicklas |
1495 |
|
5350 |
25 May 10 |
nicklas |
width*=scale; |
5350 |
25 May 10 |
nicklas |
height*=scale; |
5350 |
25 May 10 |
nicklas |
1498 |
|
5350 |
25 May 10 |
nicklas |
if(swapAngle==0) |
5350 |
25 May 10 |
nicklas |
return; |
5350 |
25 May 10 |
nicklas |
1501 |
|
5350 |
25 May 10 |
nicklas |
var arcDiv=canvasDiv.appendChild(document.createElement("div")); |
5350 |
25 May 10 |
nicklas |
var iHtml=new Array(); |
5350 |
25 May 10 |
nicklas |
1504 |
|
7419 |
03 Nov 17 |
nicklas |
var phCenter=logicalToPhysicalPoint(center); |
5350 |
25 May 10 |
nicklas |
1506 |
|
5350 |
25 May 10 |
nicklas |
var saD; //arc start angle degrees. |
5350 |
25 May 10 |
nicklas |
if(startAngle>360) |
5350 |
25 May 10 |
nicklas |
saD=startAngle%360; |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
saD=startAngle; |
5350 |
25 May 10 |
nicklas |
1512 |
|
5350 |
25 May 10 |
nicklas |
var swD; //swap angle in degrees. |
5350 |
25 May 10 |
nicklas |
if(swapAngle>360) |
5350 |
25 May 10 |
nicklas |
swD=swapAngle%360; |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
swD=swapAngle; |
5350 |
25 May 10 |
nicklas |
1518 |
|
5350 |
25 May 10 |
nicklas |
var eaD; //arc end angle degrees. |
5350 |
25 May 10 |
nicklas |
eaD=parseFloat(saD)+parseFloat(swD); |
5350 |
25 May 10 |
nicklas |
if(eaD>360) |
5350 |
25 May 10 |
nicklas |
eaD=eaD%360; |
5350 |
25 May 10 |
nicklas |
1523 |
|
5350 |
25 May 10 |
nicklas |
//For cartecian coordinate system. |
5350 |
25 May 10 |
nicklas |
if(coordinateSystem=="cartecian") |
5350 |
25 May 10 |
nicklas |
1526 |
{ |
5350 |
25 May 10 |
nicklas |
saD=360-saD; |
5350 |
25 May 10 |
nicklas |
eaD=360-eaD; |
5350 |
25 May 10 |
nicklas |
var tempAD; |
5350 |
25 May 10 |
nicklas |
tempAD=saD; |
5350 |
25 May 10 |
nicklas |
saD=eaD; |
5350 |
25 May 10 |
nicklas |
eaD=tempAD; |
5350 |
25 May 10 |
nicklas |
1533 |
} |
5350 |
25 May 10 |
nicklas |
1534 |
|
5350 |
25 May 10 |
nicklas |
var x1,y1,x2,y2; |
5350 |
25 May 10 |
nicklas |
var saR=saD*Math.PI/180; |
5350 |
25 May 10 |
nicklas |
var swR=swD*Math.PI/180; |
5350 |
25 May 10 |
nicklas |
var eaR=eaD*Math.PI/180; |
5350 |
25 May 10 |
nicklas |
1539 |
|
5350 |
25 May 10 |
nicklas |
//For start angle |
5350 |
25 May 10 |
nicklas |
if((saD<=45 && saD>=0) || (saD>=135 && saD<=225) || (saD>=315 && saD<=360)) |
5350 |
25 May 10 |
nicklas |
1542 |
{ |
5350 |
25 May 10 |
nicklas |
y1=Math.round(phCenter.y+Math.sin(saR)*width/2); |
5350 |
25 May 10 |
nicklas |
if(saD>=90 && saD<=270) |
5350 |
25 May 10 |
nicklas |
x1=Math.round(phCenter.x-width/2); |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
x1=Math.round(phCenter.x+width/2); |
5350 |
25 May 10 |
nicklas |
1548 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
1550 |
{ |
5350 |
25 May 10 |
nicklas |
x1=Math.round(phCenter.x+Math.cos(saR)*height/2); |
5350 |
25 May 10 |
nicklas |
if(saD>=0 && saD<=180) |
5350 |
25 May 10 |
nicklas |
y1=Math.round(phCenter.y+height/2); |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
y1=Math.round(phCenter.y-height/2); |
5350 |
25 May 10 |
nicklas |
1556 |
} |
5350 |
25 May 10 |
nicklas |
1557 |
|
5350 |
25 May 10 |
nicklas |
//For end angle |
5350 |
25 May 10 |
nicklas |
if((eaD<=45 && eaD>=0) || (eaD>=135 && eaD<=225) || (eaD>=315 && eaD<=360)) |
5350 |
25 May 10 |
nicklas |
1560 |
{ |
5350 |
25 May 10 |
nicklas |
y2=Math.round(phCenter.y+Math.sin(eaR)*width/2); |
5350 |
25 May 10 |
nicklas |
if(eaD>=90 && eaD<=270) |
5350 |
25 May 10 |
nicklas |
x2=Math.round(phCenter.x-width/2); |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
x2=Math.round(phCenter.x+width/2); |
5350 |
25 May 10 |
nicklas |
1566 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
1568 |
{ |
5350 |
25 May 10 |
nicklas |
x2=Math.round(phCenter.x+Math.cos(eaR)*height/2); |
5350 |
25 May 10 |
nicklas |
if(eaD>=0 && eaD<=180) |
5350 |
25 May 10 |
nicklas |
y2=Math.round(phCenter.y+height/2); |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
y2=Math.round(phCenter.y-height/2); |
5350 |
25 May 10 |
nicklas |
1574 |
} |
5350 |
25 May 10 |
nicklas |
1575 |
|
5350 |
25 May 10 |
nicklas |
//Get the pixel arrays for the lines croping the ellipse to form an arc. |
7419 |
03 Nov 17 |
nicklas |
var xDataArraySa=getLinePixels(phCenter,new jsPoint(x1,y1)); |
7419 |
03 Nov 17 |
nicklas |
var xDataArrayEa=getLinePixels(phCenter,new jsPoint(x2,y2)); |
5350 |
25 May 10 |
nicklas |
1579 |
|
5350 |
25 May 10 |
nicklas |
var hexColor=color.getHex(); |
5350 |
25 May 10 |
nicklas |
1581 |
|
5350 |
25 May 10 |
nicklas |
var a=Math.round(width/2); |
5350 |
25 May 10 |
nicklas |
var b=Math.round(height/2); |
5350 |
25 May 10 |
nicklas |
var xc=phCenter.x; |
5350 |
25 May 10 |
nicklas |
var yc=phCenter.y; |
5350 |
25 May 10 |
nicklas |
1586 |
|
5350 |
25 May 10 |
nicklas |
var x=0; |
5350 |
25 May 10 |
nicklas |
var y=b; |
5350 |
25 May 10 |
nicklas |
var a2=a*a; |
5350 |
25 May 10 |
nicklas |
var b2=b*b; |
5350 |
25 May 10 |
nicklas |
1591 |
|
5350 |
25 May 10 |
nicklas |
var xp,yp; |
5350 |
25 May 10 |
nicklas |
var divX1,divX1pU,divX1pD,divX2,divX2pU,divX2pD,divY1,divY2,saX,eaX,saXp,eaXp,xpU,xpD,ypU,ypD; |
5350 |
25 May 10 |
nicklas |
var divWidthOrg,divWidth1,divWidth2,divWidth3,divWidth4,divWidth1p,divWidth2p,divWidth3p,divWidth4p,divHeight; |
5350 |
25 May 10 |
nicklas |
var draw1p,draw2p,draw3p,draw4p; |
5350 |
25 May 10 |
nicklas |
1596 |
|
5350 |
25 May 10 |
nicklas |
xp=1; |
5350 |
25 May 10 |
nicklas |
yp=y; |
5350 |
25 May 10 |
nicklas |
1599 |
|
5350 |
25 May 10 |
nicklas |
//Upper and lower portion of the ellipse constutuing the arc |
5350 |
25 May 10 |
nicklas |
while(b2*x < a2*y) |
5350 |
25 May 10 |
nicklas |
1602 |
{ |
5350 |
25 May 10 |
nicklas |
x++; |
5350 |
25 May 10 |
nicklas |
if((b2*x*x + a2*(y-0.5)*(y-0.5) - a2*b2) >=0) |
5350 |
25 May 10 |
nicklas |
y--; |
5350 |
25 May 10 |
nicklas |
1606 |
|
5350 |
25 May 10 |
nicklas |
if(x==1 && y!=yp) //Topmost and bottom most points, to be tested |
5350 |
25 May 10 |
nicklas |
1608 |
{ |
5350 |
25 May 10 |
nicklas |
divY1=yc+yp-1; |
5350 |
25 May 10 |
nicklas |
divY2=yc-yp; |
5350 |
25 May 10 |
nicklas |
divWidthOrg=1; |
5350 |
25 May 10 |
nicklas |
divWidth1=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
divWidth2=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
divWidth3=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
divWidth4=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
divX1=xc; |
5350 |
25 May 10 |
nicklas |
1617 |
|
5350 |
25 May 10 |
nicklas |
if(saD>=0 && saD<180 && eaD>=0 && eaD<180) |
5350 |
25 May 10 |
nicklas |
1619 |
{ |
5350 |
25 May 10 |
nicklas |
fillArcSegOut(true); |
5350 |
25 May 10 |
nicklas |
if(eaD<=saD) |
5350 |
25 May 10 |
nicklas |
fillArcSegOut(false); |
5350 |
25 May 10 |
nicklas |
1623 |
} |
5350 |
25 May 10 |
nicklas |
else if(saD>=180 && saD<360 && eaD>=180 && eaD<=360) |
5350 |
25 May 10 |
nicklas |
1625 |
{ |
5350 |
25 May 10 |
nicklas |
fillArcSegOut(false); |
5350 |
25 May 10 |
nicklas |
if(eaD<=saD) |
5350 |
25 May 10 |
nicklas |
fillArcSegOut(true); |
5350 |
25 May 10 |
nicklas |
1629 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
1631 |
{ |
5350 |
25 May 10 |
nicklas |
fillArcSegOut(true); |
5350 |
25 May 10 |
nicklas |
fillArcSegOut(false); |
5350 |
25 May 10 |
nicklas |
1634 |
} |
5350 |
25 May 10 |
nicklas |
1635 |
} |
5350 |
25 May 10 |
nicklas |
else if(y!=yp) |
5350 |
25 May 10 |
nicklas |
1637 |
{ |
5350 |
25 May 10 |
nicklas |
divY1=yc+yp; |
5350 |
25 May 10 |
nicklas |
divY2=yc-yp; |
5350 |
25 May 10 |
nicklas |
divWidthOrg=2*(x-1)+1; |
5350 |
25 May 10 |
nicklas |
divWidth1=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
divWidth2=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
divWidth3=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
divWidth4=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
divX1=xc-x+1; |
5350 |
25 May 10 |
nicklas |
1646 |
|
5350 |
25 May 10 |
nicklas |
if(saD>=0 && saD<180 && eaD>=0 && eaD<180) |
5350 |
25 May 10 |
nicklas |
1648 |
{ |
5350 |
25 May 10 |
nicklas |
fillArcSegOut(true); |
5350 |
25 May 10 |
nicklas |
if(eaD<=saD) |
5350 |
25 May 10 |
nicklas |
fillArcSegOut(false); |
5350 |
25 May 10 |
nicklas |
1652 |
} |
5350 |
25 May 10 |
nicklas |
else if(saD>=180 && saD<360 && eaD>=180 && eaD<=360) |
5350 |
25 May 10 |
nicklas |
1654 |
{ |
5350 |
25 May 10 |
nicklas |
fillArcSegOut(false); |
5350 |
25 May 10 |
nicklas |
if(eaD<=saD) |
5350 |
25 May 10 |
nicklas |
fillArcSegOut(true); |
5350 |
25 May 10 |
nicklas |
1658 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
1660 |
{ |
5350 |
25 May 10 |
nicklas |
fillArcSegOut(true); |
5350 |
25 May 10 |
nicklas |
fillArcSegOut(false); |
5350 |
25 May 10 |
nicklas |
1663 |
} |
5350 |
25 May 10 |
nicklas |
1664 |
|
5350 |
25 May 10 |
nicklas |
yp=y; |
5350 |
25 May 10 |
nicklas |
xp=x; |
5350 |
25 May 10 |
nicklas |
1667 |
} |
5350 |
25 May 10 |
nicklas |
1668 |
|
5350 |
25 May 10 |
nicklas |
1669 |
|
5350 |
25 May 10 |
nicklas |
//Last step in loop |
5350 |
25 May 10 |
nicklas |
if(b2*x >= a2*y) |
5350 |
25 May 10 |
nicklas |
1672 |
{ |
5350 |
25 May 10 |
nicklas |
divY1=yc+yp; |
5350 |
25 May 10 |
nicklas |
divY2=yc-yp; |
5350 |
25 May 10 |
nicklas |
divWidthOrg=2*x+1; |
5350 |
25 May 10 |
nicklas |
divWidth1=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
divWidth2=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
divWidth3=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
divWidth4=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
divX1=xc-x; |
5350 |
25 May 10 |
nicklas |
1681 |
|
5350 |
25 May 10 |
nicklas |
if(saD>=0 && saD<180 && eaD>=0 && eaD<180) |
5350 |
25 May 10 |
nicklas |
1683 |
{ |
5350 |
25 May 10 |
nicklas |
fillArcSegOut(true); |
5350 |
25 May 10 |
nicklas |
if(eaD<=saD) |
5350 |
25 May 10 |
nicklas |
fillArcSegOut(false); |
5350 |
25 May 10 |
nicklas |
1687 |
} |
5350 |
25 May 10 |
nicklas |
else if(saD>=180 && saD<360 && eaD>=180 && eaD<=360) |
5350 |
25 May 10 |
nicklas |
1689 |
{ |
5350 |
25 May 10 |
nicklas |
fillArcSegOut(false); |
5350 |
25 May 10 |
nicklas |
if(eaD<=saD) |
5350 |
25 May 10 |
nicklas |
fillArcSegOut(true); |
5350 |
25 May 10 |
nicklas |
1693 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
1695 |
{ |
5350 |
25 May 10 |
nicklas |
fillArcSegOut(true); |
5350 |
25 May 10 |
nicklas |
fillArcSegOut(false); |
5350 |
25 May 10 |
nicklas |
1698 |
} |
5350 |
25 May 10 |
nicklas |
1699 |
} |
5350 |
25 May 10 |
nicklas |
1700 |
|
5350 |
25 May 10 |
nicklas |
1701 |
} |
5350 |
25 May 10 |
nicklas |
1702 |
|
5350 |
25 May 10 |
nicklas |
xp=x; |
5350 |
25 May 10 |
nicklas |
yp=y; |
5350 |
25 May 10 |
nicklas |
divHeight=1; |
5350 |
25 May 10 |
nicklas |
1706 |
|
5350 |
25 May 10 |
nicklas |
//Similar code as in next while loop for first y before the loop. Only values are retrieved and no drawing. |
5350 |
25 May 10 |
nicklas |
1708 |
|
5350 |
25 May 10 |
nicklas |
divY1=yc+y; |
5350 |
25 May 10 |
nicklas |
divY2=yc-y; |
5350 |
25 May 10 |
nicklas |
divWidthOrg=2*x+1; |
5350 |
25 May 10 |
nicklas |
divWidth1=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
divWidth2=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
divWidth3=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
divWidth4=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
divX1=xc-x; |
5350 |
25 May 10 |
nicklas |
1717 |
|
5350 |
25 May 10 |
nicklas |
if(saD>=0 && saD<180 && eaD>=0 && eaD<180) |
5350 |
25 May 10 |
nicklas |
1719 |
{ |
5350 |
25 May 10 |
nicklas |
xDataArrayEa.pop(); |
5350 |
25 May 10 |
nicklas |
fillArcSegIn(true,true); |
5350 |
25 May 10 |
nicklas |
if(eaD<=saD) |
5350 |
25 May 10 |
nicklas |
fillArcSegIn(false,true); |
5350 |
25 May 10 |
nicklas |
1724 |
} |
5350 |
25 May 10 |
nicklas |
else if(saD>=180 && saD<360 && eaD>=180 && eaD<=360) |
5350 |
25 May 10 |
nicklas |
1726 |
{ |
5350 |
25 May 10 |
nicklas |
xDataArrayEa.pop(); |
5350 |
25 May 10 |
nicklas |
if(y!=0) |
5350 |
25 May 10 |
nicklas |
fillArcSegIn(false,true); |
5350 |
25 May 10 |
nicklas |
if(eaD<=saD) |
5350 |
25 May 10 |
nicklas |
fillArcSegIn(true,true); |
5350 |
25 May 10 |
nicklas |
1732 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
1734 |
{ |
5350 |
25 May 10 |
nicklas |
if(saD>=180 && saD<360) |
5350 |
25 May 10 |
nicklas |
xDataArraySa.pop(); |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
xDataArrayEa.pop(); |
5350 |
25 May 10 |
nicklas |
1739 |
|
5350 |
25 May 10 |
nicklas |
1740 |
|
5350 |
25 May 10 |
nicklas |
fillArcSegIn(true,true); |
5350 |
25 May 10 |
nicklas |
if(y!=0) |
5350 |
25 May 10 |
nicklas |
1743 |
{ |
5350 |
25 May 10 |
nicklas |
divX1=xc-x; |
5350 |
25 May 10 |
nicklas |
fillArcSegIn(false,true); |
5350 |
25 May 10 |
nicklas |
1746 |
} |
5350 |
25 May 10 |
nicklas |
1747 |
} |
5350 |
25 May 10 |
nicklas |
1748 |
|
5350 |
25 May 10 |
nicklas |
//Left and Right portion of the ellipse ellipse constutuing the arc. |
5350 |
25 May 10 |
nicklas |
while(y!=0) |
5350 |
25 May 10 |
nicklas |
1751 |
{ |
5350 |
25 May 10 |
nicklas |
y--; |
5350 |
25 May 10 |
nicklas |
if((b2*(x+0.5)*(x+0.5) + a2*y*y - a2*b2)<=0) |
5350 |
25 May 10 |
nicklas |
x++; |
5350 |
25 May 10 |
nicklas |
1755 |
|
5350 |
25 May 10 |
nicklas |
divY1=yc+y; |
5350 |
25 May 10 |
nicklas |
divY2=yc-y; |
5350 |
25 May 10 |
nicklas |
divWidthOrg=2*x+1; |
5350 |
25 May 10 |
nicklas |
divWidth1=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
divWidth2=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
divWidth3=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
divWidth4=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
divX1=xc-x; |
5350 |
25 May 10 |
nicklas |
1764 |
|
5350 |
25 May 10 |
nicklas |
if(saD>=0 && saD<180 && eaD>=0 && eaD<180) |
5350 |
25 May 10 |
nicklas |
1766 |
{ |
5350 |
25 May 10 |
nicklas |
fillArcSegIn(true); |
5350 |
25 May 10 |
nicklas |
if(eaD<=saD) |
5350 |
25 May 10 |
nicklas |
fillArcSegIn(false); |
5350 |
25 May 10 |
nicklas |
1770 |
} |
5350 |
25 May 10 |
nicklas |
else if(saD>=180 && saD<360 && eaD>=180 && eaD<=360) |
5350 |
25 May 10 |
nicklas |
1772 |
{ |
5350 |
25 May 10 |
nicklas |
if(y!=0) |
5350 |
25 May 10 |
nicklas |
fillArcSegIn(false); |
5350 |
25 May 10 |
nicklas |
if(eaD<=saD) |
5350 |
25 May 10 |
nicklas |
fillArcSegIn(true); |
5350 |
25 May 10 |
nicklas |
1777 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
1779 |
{ |
5350 |
25 May 10 |
nicklas |
fillArcSegIn(true); |
5350 |
25 May 10 |
nicklas |
if(y!=0) |
5350 |
25 May 10 |
nicklas |
1782 |
{ |
5350 |
25 May 10 |
nicklas |
divX1=xc-x; |
5350 |
25 May 10 |
nicklas |
fillArcSegIn(false); |
5350 |
25 May 10 |
nicklas |
1785 |
} |
5350 |
25 May 10 |
nicklas |
1786 |
} |
5350 |
25 May 10 |
nicklas |
1787 |
} |
5350 |
25 May 10 |
nicklas |
1788 |
|
5350 |
25 May 10 |
nicklas |
arcDiv.innerHTML=iHtml.join(""); |
5350 |
25 May 10 |
nicklas |
return arcDiv; |
5350 |
25 May 10 |
nicklas |
1791 |
|
5350 |
25 May 10 |
nicklas |
//Internal function: Arc segment for left and right portion of the ellipse constutuing the arc. |
5350 |
25 May 10 |
nicklas |
function fillArcSegIn(isUpperHalf,valueOnly) |
5350 |
25 May 10 |
nicklas |
1794 |
{ |
5350 |
25 May 10 |
nicklas |
var divY; |
5350 |
25 May 10 |
nicklas |
var xDataArray1,xDataArray1; |
5350 |
25 May 10 |
nicklas |
var divWidthFirst=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
var divWidthSecond=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
var drawFirst=false; |
5350 |
25 May 10 |
nicklas |
var drawSecond=false; |
5350 |
25 May 10 |
nicklas |
1801 |
|
7419 |
03 Nov 17 |
nicklas |
var xDataArray1, xDataArray2; |
7419 |
03 Nov 17 |
nicklas |
var saDvar, eaDvar; |
5350 |
25 May 10 |
nicklas |
if(isUpperHalf) |
5350 |
25 May 10 |
nicklas |
1805 |
{ |
5350 |
25 May 10 |
nicklas |
var draw1=false; //upper half (in all comments upper & lower are in context of cartecian system) |
5350 |
25 May 10 |
nicklas |
var draw3=false; //upper half second |
5350 |
25 May 10 |
nicklas |
divY=divY1; |
5350 |
25 May 10 |
nicklas |
xDataArray1=xDataArraySa; |
5350 |
25 May 10 |
nicklas |
xDataArray2=xDataArrayEa; |
5350 |
25 May 10 |
nicklas |
saDvar=saD; |
5350 |
25 May 10 |
nicklas |
eaDvar=eaD; |
5350 |
25 May 10 |
nicklas |
1813 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
1815 |
{ |
5350 |
25 May 10 |
nicklas |
var draw2=false; //lower half |
5350 |
25 May 10 |
nicklas |
var draw4=false; //lower half second |
5350 |
25 May 10 |
nicklas |
divY=divY2; |
5350 |
25 May 10 |
nicklas |
xDataArray2=xDataArraySa; |
5350 |
25 May 10 |
nicklas |
xDataArray1=xDataArrayEa; |
5350 |
25 May 10 |
nicklas |
saDvar=360-eaD; |
5350 |
25 May 10 |
nicklas |
eaDvar=360-saD; |
5350 |
25 May 10 |
nicklas |
1823 |
} |
5350 |
25 May 10 |
nicklas |
if(eaDvar>saDvar) |
5350 |
25 May 10 |
nicklas |
1825 |
{ |
5350 |
25 May 10 |
nicklas |
if(xDataArray2[divY] && divX1+divWidthOrg>=xDataArray2[divY].xMin && divX1<=xDataArray2[divY].xMin) |
5350 |
25 May 10 |
nicklas |
1827 |
{ |
5350 |
25 May 10 |
nicklas |
eaX=xDataArray2[divY].xMin; |
5350 |
25 May 10 |
nicklas |
if(xDataArray1[divY] && divX1+divWidthOrg>=xDataArray1[divY].xMax+1 && divX1<=xDataArray1[divY].xMax+1) |
5350 |
25 May 10 |
nicklas |
1830 |
{ |
5350 |
25 May 10 |
nicklas |
saX=xDataArray1[divY].xMax+1; |
5350 |
25 May 10 |
nicklas |
divWidthFirst=saX-eaX; |
5350 |
25 May 10 |
nicklas |
1833 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
1835 |
{ |
5350 |
25 May 10 |
nicklas |
divWidthFirst=divX1+divWidthOrg-eaX; |
5350 |
25 May 10 |
nicklas |
1837 |
} |
5350 |
25 May 10 |
nicklas |
divX1=eaX; |
5350 |
25 May 10 |
nicklas |
drawFirst=true; |
5350 |
25 May 10 |
nicklas |
1840 |
} |
5350 |
25 May 10 |
nicklas |
else if(xDataArray1[divY] && divX1+divWidthOrg>=xDataArray1[divY].xMax+1 && divX1<=xDataArray1[divY].xMax+1) |
5350 |
25 May 10 |
nicklas |
1842 |
{ |
5350 |
25 May 10 |
nicklas |
saX=xDataArray1[divY].xMax+1; |
5350 |
25 May 10 |
nicklas |
divWidthFirst=saX-divX1; |
5350 |
25 May 10 |
nicklas |
drawFirst=true; |
5350 |
25 May 10 |
nicklas |
1846 |
} |
5350 |
25 May 10 |
nicklas |
else if(eaDvar>90 && saDvar<90) |
5350 |
25 May 10 |
nicklas |
1848 |
{ |
5350 |
25 May 10 |
nicklas |
drawFirst=true; |
5350 |
25 May 10 |
nicklas |
1850 |
} |
5350 |
25 May 10 |
nicklas |
1851 |
} |
5350 |
25 May 10 |
nicklas |
else //saDvar>=eaDvar |
5350 |
25 May 10 |
nicklas |
1853 |
{ |
5350 |
25 May 10 |
nicklas |
if(xDataArray1[divY] && divX1+divWidthOrg>=xDataArray1[divY].xMax+1 && divX1<=xDataArray1[divY].xMax+1) |
5350 |
25 May 10 |
nicklas |
1855 |
{ |
5350 |
25 May 10 |
nicklas |
saX=xDataArray1[divY].xMax+1; |
5350 |
25 May 10 |
nicklas |
divWidthFirst=saX-divX1; |
5350 |
25 May 10 |
nicklas |
drawFirst=true; |
5350 |
25 May 10 |
nicklas |
1859 |
} |
5350 |
25 May 10 |
nicklas |
else if(eaDvar<90 && saDvar<90) |
5350 |
25 May 10 |
nicklas |
1861 |
{ |
5350 |
25 May 10 |
nicklas |
drawFirst=true; |
5350 |
25 May 10 |
nicklas |
1863 |
} |
5350 |
25 May 10 |
nicklas |
1864 |
|
5350 |
25 May 10 |
nicklas |
if(xDataArray2[divY] && divX1+divWidthOrg>=xDataArray2[divY].xMin && divX1<=xDataArray2[divY].xMin) |
5350 |
25 May 10 |
nicklas |
1866 |
{ |
5350 |
25 May 10 |
nicklas |
divX2=xDataArray2[divY].xMin; |
5350 |
25 May 10 |
nicklas |
divWidthSecond=divWidthOrg-xDataArray2[divY].xMin+divX1; |
5350 |
25 May 10 |
nicklas |
drawSecond=true; |
5350 |
25 May 10 |
nicklas |
1870 |
} |
5350 |
25 May 10 |
nicklas |
else if(eaDvar>90 && saDvar>90) |
5350 |
25 May 10 |
nicklas |
1872 |
{ |
5350 |
25 May 10 |
nicklas |
divX2=divX1; |
5350 |
25 May 10 |
nicklas |
divWidthSecond=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
drawSecond=true; |
5350 |
25 May 10 |
nicklas |
1876 |
} |
5350 |
25 May 10 |
nicklas |
1877 |
} |
5350 |
25 May 10 |
nicklas |
1878 |
|
5350 |
25 May 10 |
nicklas |
if(isUpperHalf) |
5350 |
25 May 10 |
nicklas |
1880 |
{ |
5350 |
25 May 10 |
nicklas |
if(drawFirst) |
5350 |
25 May 10 |
nicklas |
draw1=true; |
5350 |
25 May 10 |
nicklas |
1883 |
|
5350 |
25 May 10 |
nicklas |
if(drawSecond) |
5350 |
25 May 10 |
nicklas |
draw3=true; |
5350 |
25 May 10 |
nicklas |
1886 |
|
5350 |
25 May 10 |
nicklas |
divWidth1=divWidthFirst; |
5350 |
25 May 10 |
nicklas |
divWidth3=divWidthSecond; |
5350 |
25 May 10 |
nicklas |
1889 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
1891 |
{ |
5350 |
25 May 10 |
nicklas |
if(drawFirst) |
5350 |
25 May 10 |
nicklas |
draw2=true; |
5350 |
25 May 10 |
nicklas |
1894 |
|
5350 |
25 May 10 |
nicklas |
if(drawSecond) |
5350 |
25 May 10 |
nicklas |
draw4=true; |
5350 |
25 May 10 |
nicklas |
1897 |
|
5350 |
25 May 10 |
nicklas |
divWidth2=divWidthFirst; |
5350 |
25 May 10 |
nicklas |
divWidth4=divWidthSecond; |
5350 |
25 May 10 |
nicklas |
1900 |
} |
5350 |
25 May 10 |
nicklas |
1901 |
|
5350 |
25 May 10 |
nicklas |
if(saD>=0 && saD<180 && eaD>=0 && eaD<180 && saD>eaD) |
5350 |
25 May 10 |
nicklas |
1903 |
{ |
5350 |
25 May 10 |
nicklas |
draw2=true; |
5350 |
25 May 10 |
nicklas |
1905 |
} |
5350 |
25 May 10 |
nicklas |
else if(saD>=180 && saD<360 && eaD>=180 && eaD<360 && saD>eaD) |
5350 |
25 May 10 |
nicklas |
1907 |
{ |
5350 |
25 May 10 |
nicklas |
draw1=true; |
5350 |
25 May 10 |
nicklas |
1909 |
} |
5350 |
25 May 10 |
nicklas |
1910 |
|
5350 |
25 May 10 |
nicklas |
if(!divX2) |
5350 |
25 May 10 |
nicklas |
divX2=""; |
5350 |
25 May 10 |
nicklas |
if(!divX1) |
5350 |
25 May 10 |
nicklas |
divX1=""; |
5350 |
25 May 10 |
nicklas |
1915 |
|
5350 |
25 May 10 |
nicklas |
if(!valueOnly) |
5350 |
25 May 10 |
nicklas |
1917 |
{ |
5350 |
25 May 10 |
nicklas |
if(isUpperHalf) |
5350 |
25 May 10 |
nicklas |
1919 |
{ |
5350 |
25 May 10 |
nicklas |
if(x!=xpU || divX1pU!=divX1 || divX2pU!=divX2 || divWidth1!=divWidth1p || divWidth3!=divWidth3p) |
5350 |
25 May 10 |
nicklas |
1921 |
{ |
5350 |
25 May 10 |
nicklas |
divHeight=ypU-y; |
5350 |
25 May 10 |
nicklas |
if(draw3p) |
5350 |
25 May 10 |
nicklas |
1924 |
{ |
5350 |
25 May 10 |
nicklas |
if(divX2pU!=null) |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + divX2pU + "px;top:" + (divY1+1) + "px;width:" + divWidth3p + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
1927 |
} |
5350 |
25 May 10 |
nicklas |
if(draw1p) |
5350 |
25 May 10 |
nicklas |
1929 |
{ |
5350 |
25 May 10 |
nicklas |
if(divX1pU!=null) |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + divX1pU + "px;top:" + (divY1+1) + "px;width:" + divWidth1p + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
1932 |
} |
5350 |
25 May 10 |
nicklas |
1933 |
|
5350 |
25 May 10 |
nicklas |
if(draw1p||draw3p) |
5350 |
25 May 10 |
nicklas |
1935 |
{ |
5350 |
25 May 10 |
nicklas |
divX1pU=divX1; |
5350 |
25 May 10 |
nicklas |
1937 |
|
5350 |
25 May 10 |
nicklas |
draw1p=draw1; |
5350 |
25 May 10 |
nicklas |
draw3p=draw3; |
5350 |
25 May 10 |
nicklas |
xpU=x; |
5350 |
25 May 10 |
nicklas |
ypU=y; |
5350 |
25 May 10 |
nicklas |
1942 |
|
5350 |
25 May 10 |
nicklas |
divWidth1p=divWidth1; |
5350 |
25 May 10 |
nicklas |
divWidth3p=divWidth3; |
5350 |
25 May 10 |
nicklas |
divX2pU=divX2; |
5350 |
25 May 10 |
nicklas |
1946 |
} |
5350 |
25 May 10 |
nicklas |
1947 |
} |
5350 |
25 May 10 |
nicklas |
1948 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
1950 |
{ |
5350 |
25 May 10 |
nicklas |
if(x!=xpD || divX1pD!=divX1 || divX2pD!=divX2 || divWidth2!=divWidth2p || divWidth4!=divWidth4p) |
5350 |
25 May 10 |
nicklas |
1952 |
{ |
5350 |
25 May 10 |
nicklas |
divHeight=ypD-y; |
5350 |
25 May 10 |
nicklas |
if(draw4p) |
5350 |
25 May 10 |
nicklas |
1955 |
{ |
5350 |
25 May 10 |
nicklas |
if(divX2pD!=null) |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + divX2pD + "px;top:" + (divY2-divHeight) + "px;width:" + divWidth4p + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
1958 |
} |
5350 |
25 May 10 |
nicklas |
if(draw2p) |
5350 |
25 May 10 |
nicklas |
1960 |
{ |
5350 |
25 May 10 |
nicklas |
if(divX1pD!=null) |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + divX1pD + "px;top:" + (divY2-divHeight) + "px;width:" + divWidth2p + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
1963 |
} |
5350 |
25 May 10 |
nicklas |
if(draw2p||draw4p) |
5350 |
25 May 10 |
nicklas |
1965 |
{ |
5350 |
25 May 10 |
nicklas |
divX1pD=divX1; |
5350 |
25 May 10 |
nicklas |
1967 |
|
5350 |
25 May 10 |
nicklas |
draw2p=draw2; |
5350 |
25 May 10 |
nicklas |
draw4p=draw4; |
5350 |
25 May 10 |
nicklas |
1970 |
|
5350 |
25 May 10 |
nicklas |
xpD=x; |
5350 |
25 May 10 |
nicklas |
ypD=y; |
5350 |
25 May 10 |
nicklas |
1973 |
|
5350 |
25 May 10 |
nicklas |
divWidth2p=divWidth2; |
5350 |
25 May 10 |
nicklas |
divWidth4p=divWidth4; |
5350 |
25 May 10 |
nicklas |
divX2pD=divX2; |
5350 |
25 May 10 |
nicklas |
1977 |
} |
5350 |
25 May 10 |
nicklas |
1978 |
} |
5350 |
25 May 10 |
nicklas |
1979 |
} |
5350 |
25 May 10 |
nicklas |
1980 |
} |
5350 |
25 May 10 |
nicklas |
1981 |
|
5350 |
25 May 10 |
nicklas |
//To get only values; used for first y value before loop. |
5350 |
25 May 10 |
nicklas |
if(valueOnly) |
5350 |
25 May 10 |
nicklas |
1984 |
{ |
5350 |
25 May 10 |
nicklas |
if(isUpperHalf) |
5350 |
25 May 10 |
nicklas |
1986 |
{ |
5350 |
25 May 10 |
nicklas |
draw1p=draw1; |
5350 |
25 May 10 |
nicklas |
draw3p=draw3; |
5350 |
25 May 10 |
nicklas |
1989 |
|
5350 |
25 May 10 |
nicklas |
if(draw1p) |
5350 |
25 May 10 |
nicklas |
divX1pU=divX1; |
5350 |
25 May 10 |
nicklas |
1992 |
|
5350 |
25 May 10 |
nicklas |
if(draw3p) |
5350 |
25 May 10 |
nicklas |
divX2pU=divX2; |
5350 |
25 May 10 |
nicklas |
1995 |
|
5350 |
25 May 10 |
nicklas |
if(draw1p||draw3p) |
5350 |
25 May 10 |
nicklas |
1997 |
{ |
5350 |
25 May 10 |
nicklas |
ypU=y; |
5350 |
25 May 10 |
nicklas |
xpU=x; |
5350 |
25 May 10 |
nicklas |
2000 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
2002 |
{ |
5350 |
25 May 10 |
nicklas |
ypU=0; |
5350 |
25 May 10 |
nicklas |
xpU=0; |
5350 |
25 May 10 |
nicklas |
2005 |
} |
5350 |
25 May 10 |
nicklas |
2006 |
|
5350 |
25 May 10 |
nicklas |
divWidth1p=divWidth1; |
5350 |
25 May 10 |
nicklas |
divWidth3p=divWidth3; |
5350 |
25 May 10 |
nicklas |
2009 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
2011 |
{ |
5350 |
25 May 10 |
nicklas |
draw2p=draw2; |
5350 |
25 May 10 |
nicklas |
draw4p=draw4; |
5350 |
25 May 10 |
nicklas |
2014 |
|
5350 |
25 May 10 |
nicklas |
if(draw2p) |
5350 |
25 May 10 |
nicklas |
divX1pD=divX1; |
5350 |
25 May 10 |
nicklas |
2017 |
|
5350 |
25 May 10 |
nicklas |
if(draw4p) |
5350 |
25 May 10 |
nicklas |
divX2pD=divX2; |
5350 |
25 May 10 |
nicklas |
2020 |
|
5350 |
25 May 10 |
nicklas |
if(draw2p||draw4p) |
5350 |
25 May 10 |
nicklas |
2022 |
{ |
5350 |
25 May 10 |
nicklas |
ypD=y; |
5350 |
25 May 10 |
nicklas |
xpD=x; |
5350 |
25 May 10 |
nicklas |
2025 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
2027 |
{ |
5350 |
25 May 10 |
nicklas |
ypD=0; |
5350 |
25 May 10 |
nicklas |
xpD=0; |
5350 |
25 May 10 |
nicklas |
2030 |
} |
5350 |
25 May 10 |
nicklas |
2031 |
|
5350 |
25 May 10 |
nicklas |
divWidth2p=divWidth2; |
5350 |
25 May 10 |
nicklas |
divWidth4p=divWidth4; |
5350 |
25 May 10 |
nicklas |
2034 |
} |
5350 |
25 May 10 |
nicklas |
2035 |
} |
5350 |
25 May 10 |
nicklas |
2036 |
|
5350 |
25 May 10 |
nicklas |
if(!isUpperHalf) |
5350 |
25 May 10 |
nicklas |
2038 |
{ |
5350 |
25 May 10 |
nicklas |
draw2p=draw2; |
5350 |
25 May 10 |
nicklas |
draw4p=draw4; |
5350 |
25 May 10 |
nicklas |
2041 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
2043 |
{ |
5350 |
25 May 10 |
nicklas |
draw1p=draw1; |
5350 |
25 May 10 |
nicklas |
draw3p=draw3; |
5350 |
25 May 10 |
nicklas |
2046 |
} |
5350 |
25 May 10 |
nicklas |
2047 |
|
5350 |
25 May 10 |
nicklas |
if(y==1 && !isUpperHalf) |
5350 |
25 May 10 |
nicklas |
2049 |
{ |
5350 |
25 May 10 |
nicklas |
divHeight=ypD-y+1; |
5350 |
25 May 10 |
nicklas |
if(draw4) |
5350 |
25 May 10 |
nicklas |
2052 |
{ |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + divX2 + "px;top:" + (divY2+1-divHeight) + "px;width:" + divWidth4 + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
2054 |
} |
5350 |
25 May 10 |
nicklas |
if(draw2) |
5350 |
25 May 10 |
nicklas |
2056 |
{ |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + divX1 + "px;top:" + (divY2+1-divHeight) + "px;width:" + divWidth2 + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
2058 |
} |
5350 |
25 May 10 |
nicklas |
2059 |
} |
5350 |
25 May 10 |
nicklas |
if(y==0 && isUpperHalf) |
5350 |
25 May 10 |
nicklas |
2061 |
{ |
5350 |
25 May 10 |
nicklas |
divHeight=ypU-y+1; |
5350 |
25 May 10 |
nicklas |
if(draw3) |
5350 |
25 May 10 |
nicklas |
2064 |
{ |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + divX2 + "px;top:" + (divY1) + "px;width:" + divWidth3 + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
2066 |
} |
5350 |
25 May 10 |
nicklas |
if(draw1) |
5350 |
25 May 10 |
nicklas |
2068 |
{ |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + divX1 + "px;top:" + (divY1) + "px;width:" + divWidth1 + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
2070 |
} |
5350 |
25 May 10 |
nicklas |
2071 |
} |
5350 |
25 May 10 |
nicklas |
2072 |
} |
5350 |
25 May 10 |
nicklas |
2073 |
|
5350 |
25 May 10 |
nicklas |
//Internal function: Arc segment for upper and lower portion of the ellipse constutuing the arc. |
5350 |
25 May 10 |
nicklas |
function fillArcSegOut(isUpperHalf) |
5350 |
25 May 10 |
nicklas |
2076 |
{ |
5350 |
25 May 10 |
nicklas |
var divY; |
5350 |
25 May 10 |
nicklas |
var xDataArray1,xDataArray1; |
5350 |
25 May 10 |
nicklas |
var divWidthFirst=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
var divWidthSecond=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
var drawFirst=false; |
5350 |
25 May 10 |
nicklas |
var drawSecond=false; |
7419 |
03 Nov 17 |
nicklas |
var xDataArray1, xDataArray2; |
7419 |
03 Nov 17 |
nicklas |
var saDvar, eaDvar; |
5350 |
25 May 10 |
nicklas |
if(isUpperHalf) |
5350 |
25 May 10 |
nicklas |
2086 |
{ |
5350 |
25 May 10 |
nicklas |
var draw1=false; //upper half |
5350 |
25 May 10 |
nicklas |
var draw3=false; //upper half second |
5350 |
25 May 10 |
nicklas |
divY=divY1; |
5350 |
25 May 10 |
nicklas |
xDataArray1=xDataArraySa; |
5350 |
25 May 10 |
nicklas |
xDataArray2=xDataArrayEa; |
5350 |
25 May 10 |
nicklas |
saDvar=saD; |
5350 |
25 May 10 |
nicklas |
eaDvar=eaD; |
5350 |
25 May 10 |
nicklas |
2094 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
2096 |
{ |
5350 |
25 May 10 |
nicklas |
var draw2=false; //lower half |
5350 |
25 May 10 |
nicklas |
var draw4=false; //lower half second |
5350 |
25 May 10 |
nicklas |
divY=divY2; |
5350 |
25 May 10 |
nicklas |
xDataArray2=xDataArraySa; |
5350 |
25 May 10 |
nicklas |
xDataArray1=xDataArrayEa; |
5350 |
25 May 10 |
nicklas |
saDvar=360-eaD; |
5350 |
25 May 10 |
nicklas |
eaDvar=360-saD; |
5350 |
25 May 10 |
nicklas |
2104 |
} |
5350 |
25 May 10 |
nicklas |
if(eaDvar>saDvar) |
5350 |
25 May 10 |
nicklas |
2106 |
{ |
5350 |
25 May 10 |
nicklas |
if(xDataArray2[divY]!=null && divX1+divWidthOrg>=xDataArray2[divY].xMin && divX1<=xDataArray2[divY].xMin) |
5350 |
25 May 10 |
nicklas |
2108 |
{ |
5350 |
25 May 10 |
nicklas |
eaX=xDataArray2[divY].xMin; |
5350 |
25 May 10 |
nicklas |
if(xDataArray1[divY]!=null && divX1+divWidthOrg>=xDataArray1[divY].xMax+1 && divX1<=xDataArray1[divY].xMax+1) |
5350 |
25 May 10 |
nicklas |
2111 |
{ |
5350 |
25 May 10 |
nicklas |
saX=xDataArray1[divY].xMax+1; |
5350 |
25 May 10 |
nicklas |
divWidthFirst=saX-eaX; |
5350 |
25 May 10 |
nicklas |
2114 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
2116 |
{ |
5350 |
25 May 10 |
nicklas |
divWidthFirst=divX1+divWidthOrg-eaX; |
5350 |
25 May 10 |
nicklas |
2118 |
} |
5350 |
25 May 10 |
nicklas |
divX1=eaX; |
5350 |
25 May 10 |
nicklas |
drawFirst=true; |
5350 |
25 May 10 |
nicklas |
2121 |
} |
5350 |
25 May 10 |
nicklas |
else if(xDataArray1[divY]!=null && divX1+divWidthOrg>=xDataArray1[divY].xMax+1 && divX1<=xDataArray1[divY].xMax+1) |
5350 |
25 May 10 |
nicklas |
2123 |
{ |
5350 |
25 May 10 |
nicklas |
saX=xDataArray1[divY].xMax+1; |
5350 |
25 May 10 |
nicklas |
divWidthFirst=saX-divX1; |
5350 |
25 May 10 |
nicklas |
drawFirst=true; |
5350 |
25 May 10 |
nicklas |
2127 |
} |
5350 |
25 May 10 |
nicklas |
else if(eaDvar>90 && saDvar<90) |
5350 |
25 May 10 |
nicklas |
2129 |
{ |
5350 |
25 May 10 |
nicklas |
drawFirst=true; |
5350 |
25 May 10 |
nicklas |
2131 |
} |
5350 |
25 May 10 |
nicklas |
2132 |
} |
5350 |
25 May 10 |
nicklas |
else //saDvar>eaDvar |
5350 |
25 May 10 |
nicklas |
2134 |
{ |
5350 |
25 May 10 |
nicklas |
if(xDataArray1[divY]!=null && divX1+divWidthOrg>=xDataArray1[divY].xMax+1 && divX1<=xDataArray1[divY].xMax+1) |
5350 |
25 May 10 |
nicklas |
2136 |
{ |
5350 |
25 May 10 |
nicklas |
saX=xDataArray1[divY].xMax+1; |
5350 |
25 May 10 |
nicklas |
divWidthFirst=saX-divX1; |
5350 |
25 May 10 |
nicklas |
drawFirst=true; |
5350 |
25 May 10 |
nicklas |
2140 |
} |
5350 |
25 May 10 |
nicklas |
else if(eaDvar<90 && saDvar<90) |
5350 |
25 May 10 |
nicklas |
2142 |
{ |
5350 |
25 May 10 |
nicklas |
drawFirst=true; |
5350 |
25 May 10 |
nicklas |
2144 |
} |
5350 |
25 May 10 |
nicklas |
2145 |
|
5350 |
25 May 10 |
nicklas |
if(xDataArray2[divY]!=null && divX1+divWidthOrg>=xDataArray2[divY].xMin && divX1<=xDataArray2[divY].xMin) |
5350 |
25 May 10 |
nicklas |
2147 |
{ |
5350 |
25 May 10 |
nicklas |
divX2=xDataArray2[divY].xMin; |
5350 |
25 May 10 |
nicklas |
divWidthSecond=divWidthOrg-xDataArray2[divY].xMin+divX1; |
5350 |
25 May 10 |
nicklas |
drawSecond=true; |
5350 |
25 May 10 |
nicklas |
2151 |
} |
5350 |
25 May 10 |
nicklas |
else if(eaDvar>90 && saDvar>90) |
5350 |
25 May 10 |
nicklas |
2153 |
{ |
5350 |
25 May 10 |
nicklas |
divX2=divX1; |
5350 |
25 May 10 |
nicklas |
divWidthSecond=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
drawSecond=true; |
5350 |
25 May 10 |
nicklas |
2157 |
} |
5350 |
25 May 10 |
nicklas |
2158 |
} |
5350 |
25 May 10 |
nicklas |
2159 |
|
5350 |
25 May 10 |
nicklas |
if(isUpperHalf) |
5350 |
25 May 10 |
nicklas |
2161 |
{ |
5350 |
25 May 10 |
nicklas |
if(drawFirst) |
5350 |
25 May 10 |
nicklas |
draw1=true; |
5350 |
25 May 10 |
nicklas |
2164 |
|
5350 |
25 May 10 |
nicklas |
if(drawSecond) |
5350 |
25 May 10 |
nicklas |
draw3=true; |
5350 |
25 May 10 |
nicklas |
2167 |
|
5350 |
25 May 10 |
nicklas |
divWidth1=divWidthFirst; |
5350 |
25 May 10 |
nicklas |
divWidth3=divWidthSecond; |
5350 |
25 May 10 |
nicklas |
2170 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
2172 |
{ |
5350 |
25 May 10 |
nicklas |
if(drawFirst) |
5350 |
25 May 10 |
nicklas |
draw2=true; |
5350 |
25 May 10 |
nicklas |
2175 |
|
5350 |
25 May 10 |
nicklas |
if(drawSecond) |
5350 |
25 May 10 |
nicklas |
draw4=true; |
5350 |
25 May 10 |
nicklas |
2178 |
|
5350 |
25 May 10 |
nicklas |
divWidth2=divWidthFirst; |
5350 |
25 May 10 |
nicklas |
divWidth4=divWidthSecond; |
5350 |
25 May 10 |
nicklas |
2181 |
} |
5350 |
25 May 10 |
nicklas |
2182 |
|
5350 |
25 May 10 |
nicklas |
if(saD>=0 && saD<180 && eaD>=0 && eaD<180 && saD>eaD) |
5350 |
25 May 10 |
nicklas |
2184 |
{ |
5350 |
25 May 10 |
nicklas |
draw2=true; |
5350 |
25 May 10 |
nicklas |
2186 |
} |
5350 |
25 May 10 |
nicklas |
else if(saD>=180 && saD<360 && eaD>=180 && eaD<360 && saD>eaD) |
5350 |
25 May 10 |
nicklas |
2188 |
{ |
5350 |
25 May 10 |
nicklas |
draw1=true; |
5350 |
25 May 10 |
nicklas |
2190 |
} |
5350 |
25 May 10 |
nicklas |
2191 |
|
5350 |
25 May 10 |
nicklas |
if(divX2==null) |
5350 |
25 May 10 |
nicklas |
divX2="X"; |
5350 |
25 May 10 |
nicklas |
if(divX1==null) |
5350 |
25 May 10 |
nicklas |
divX1="X"; |
5350 |
25 May 10 |
nicklas |
2196 |
|
5350 |
25 May 10 |
nicklas |
if(isUpperHalf) |
5350 |
25 May 10 |
nicklas |
2198 |
{ |
5350 |
25 May 10 |
nicklas |
divHeight=1; |
5350 |
25 May 10 |
nicklas |
if(draw3) |
5350 |
25 May 10 |
nicklas |
2201 |
{ |
5350 |
25 May 10 |
nicklas |
if(divX2!="X") |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + divX2 + "px;top:" + divY1 + "px;width:" + divWidth3 + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
2204 |
} |
5350 |
25 May 10 |
nicklas |
if(draw1) |
5350 |
25 May 10 |
nicklas |
2206 |
{ |
5350 |
25 May 10 |
nicklas |
if(divX1!="X") |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + divX1 + "px;top:" + divY1 + "px;width:" + divWidth1 + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
2209 |
} |
5350 |
25 May 10 |
nicklas |
2210 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
2212 |
{ |
5350 |
25 May 10 |
nicklas |
divHeight=1; |
5350 |
25 May 10 |
nicklas |
if(draw4) |
5350 |
25 May 10 |
nicklas |
2215 |
{ |
5350 |
25 May 10 |
nicklas |
if(divX2!="X") |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + divX2 + "px;top:" + (divY2+1-divHeight) + "px;width:" + divWidth4 + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
2218 |
} |
5350 |
25 May 10 |
nicklas |
if(draw2) |
5350 |
25 May 10 |
nicklas |
2220 |
{ |
5350 |
25 May 10 |
nicklas |
if(divX1!="X") |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + divX1 + "px;top:" + (divY2+1-divHeight) + "px;width:" + divWidth2 + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
2223 |
} |
5350 |
25 May 10 |
nicklas |
2224 |
} |
5350 |
25 May 10 |
nicklas |
2225 |
} |
5350 |
25 May 10 |
nicklas |
2226 |
} |
5350 |
25 May 10 |
nicklas |
2227 |
|
5350 |
25 May 10 |
nicklas |
//Draw arc with specified center, width, height, start angle and swap angle. |
5350 |
25 May 10 |
nicklas |
function drawArc(pen,center,width,height,startAngle,swapAngle) |
5350 |
25 May 10 |
nicklas |
2230 |
{ |
5350 |
25 May 10 |
nicklas |
//Check arguments for null values |
5350 |
25 May 10 |
nicklas |
if(!pen || !center || !width || !height || startAngle==null || swapAngle==null) |
5350 |
25 May 10 |
nicklas |
return false; |
5350 |
25 May 10 |
nicklas |
2234 |
|
5350 |
25 May 10 |
nicklas |
width*=scale; |
5350 |
25 May 10 |
nicklas |
height*=scale; |
5350 |
25 May 10 |
nicklas |
2237 |
|
5350 |
25 May 10 |
nicklas |
if(swapAngle==0) |
5350 |
25 May 10 |
nicklas |
return; |
5350 |
25 May 10 |
nicklas |
2240 |
|
5350 |
25 May 10 |
nicklas |
var arcDiv=canvasDiv.appendChild(document.createElement("div")); |
5350 |
25 May 10 |
nicklas |
var iHtml=new Array(); |
5350 |
25 May 10 |
nicklas |
2243 |
|
7419 |
03 Nov 17 |
nicklas |
var phCenter=logicalToPhysicalPoint(center); |
5350 |
25 May 10 |
nicklas |
2245 |
|
5350 |
25 May 10 |
nicklas |
var saD; //arc start angle degrees. |
5350 |
25 May 10 |
nicklas |
if(startAngle>360) |
5350 |
25 May 10 |
nicklas |
saD=startAngle%360; |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
saD=startAngle; |
5350 |
25 May 10 |
nicklas |
2251 |
|
5350 |
25 May 10 |
nicklas |
var swD; //swap angle in degrees. |
5350 |
25 May 10 |
nicklas |
if(swapAngle>360) |
5350 |
25 May 10 |
nicklas |
swD=swapAngle%360; |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
swD=swapAngle; |
5350 |
25 May 10 |
nicklas |
2257 |
|
5350 |
25 May 10 |
nicklas |
var eaD; //arc end angle degrees. |
5350 |
25 May 10 |
nicklas |
eaD=parseFloat(saD)+parseFloat(swD); |
5350 |
25 May 10 |
nicklas |
if(eaD>360) |
5350 |
25 May 10 |
nicklas |
eaD=eaD%360; |
5350 |
25 May 10 |
nicklas |
2262 |
|
5350 |
25 May 10 |
nicklas |
//For cartecian coordinate system. |
5350 |
25 May 10 |
nicklas |
if(coordinateSystem=="cartecian") |
5350 |
25 May 10 |
nicklas |
2265 |
{ |
5350 |
25 May 10 |
nicklas |
saD=360-saD; |
5350 |
25 May 10 |
nicklas |
eaD=360-eaD; |
5350 |
25 May 10 |
nicklas |
var tempAD; |
5350 |
25 May 10 |
nicklas |
tempAD=saD; |
5350 |
25 May 10 |
nicklas |
saD=eaD; |
5350 |
25 May 10 |
nicklas |
eaD=tempAD; |
5350 |
25 May 10 |
nicklas |
2272 |
} |
5350 |
25 May 10 |
nicklas |
2273 |
|
5350 |
25 May 10 |
nicklas |
var x1,y1,x2,y2; |
5350 |
25 May 10 |
nicklas |
var saR=saD*Math.PI/180; |
5350 |
25 May 10 |
nicklas |
var swR=swD*Math.PI/180; |
5350 |
25 May 10 |
nicklas |
var eaR=eaD*Math.PI/180; |
5350 |
25 May 10 |
nicklas |
2278 |
|
5350 |
25 May 10 |
nicklas |
//For start angle |
5350 |
25 May 10 |
nicklas |
if((saD<=45 && saD>=0) || (saD>=135 && saD<=225) || (saD>=315 && saD<=360)) |
5350 |
25 May 10 |
nicklas |
2281 |
{ |
5350 |
25 May 10 |
nicklas |
y1=Math.round(phCenter.y+Math.sin(saR)*width/2); |
5350 |
25 May 10 |
nicklas |
if(saD>=90 && saD<=270) |
5350 |
25 May 10 |
nicklas |
x1=Math.round(phCenter.x-width/2); |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
x1=Math.round(phCenter.x+width/2); |
5350 |
25 May 10 |
nicklas |
2287 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
2289 |
{ |
5350 |
25 May 10 |
nicklas |
x1=Math.round(phCenter.x+Math.cos(saR)*height/2); |
5350 |
25 May 10 |
nicklas |
if(saD>=0 && saD<=180) |
5350 |
25 May 10 |
nicklas |
y1=Math.round(phCenter.y+height/2); |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
y1=Math.round(phCenter.y-height/2); |
5350 |
25 May 10 |
nicklas |
2295 |
} |
5350 |
25 May 10 |
nicklas |
2296 |
|
5350 |
25 May 10 |
nicklas |
//For end angle |
5350 |
25 May 10 |
nicklas |
if((eaD<=45 && eaD>=0) || (eaD>=135 && eaD<=225) || (eaD>=315 && eaD<=360)) |
5350 |
25 May 10 |
nicklas |
2299 |
{ |
5350 |
25 May 10 |
nicklas |
y2=Math.round(phCenter.y+Math.sin(eaR)*width/2); |
5350 |
25 May 10 |
nicklas |
if(eaD>=90 && eaD<=270) |
5350 |
25 May 10 |
nicklas |
x2=Math.round(phCenter.x-width/2); |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
x2=Math.round(phCenter.x+width/2); |
5350 |
25 May 10 |
nicklas |
2305 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
2307 |
{ |
5350 |
25 May 10 |
nicklas |
x2=Math.round(phCenter.x+Math.cos(eaR)*height/2); |
5350 |
25 May 10 |
nicklas |
if(eaD>=0 && eaD<=180) |
5350 |
25 May 10 |
nicklas |
y2=Math.round(phCenter.y+height/2); |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
y2=Math.round(phCenter.y-height/2); |
5350 |
25 May 10 |
nicklas |
2313 |
} |
5350 |
25 May 10 |
nicklas |
2314 |
|
5350 |
25 May 10 |
nicklas |
//Get the pixel arrays for the lines croping the ellipse to form an arc. |
7419 |
03 Nov 17 |
nicklas |
var xDataArraySa=getLinePixels(phCenter,new jsPoint(x1,y1)); |
7419 |
03 Nov 17 |
nicklas |
var xDataArrayEa=getLinePixels(phCenter,new jsPoint(x2,y2)); |
5350 |
25 May 10 |
nicklas |
2318 |
|
5350 |
25 May 10 |
nicklas |
var hexColor=pen.color.getHex(); |
5350 |
25 May 10 |
nicklas |
2320 |
|
5350 |
25 May 10 |
nicklas |
var a=Math.round(width/2); |
5350 |
25 May 10 |
nicklas |
var b=Math.round(height/2); |
5350 |
25 May 10 |
nicklas |
var xc=phCenter.x; |
5350 |
25 May 10 |
nicklas |
var yc=phCenter.y; |
5350 |
25 May 10 |
nicklas |
2325 |
|
5350 |
25 May 10 |
nicklas |
var x=0; |
5350 |
25 May 10 |
nicklas |
var y=b; |
5350 |
25 May 10 |
nicklas |
var a2=a*a; |
5350 |
25 May 10 |
nicklas |
var b2=b*b; |
5350 |
25 May 10 |
nicklas |
2330 |
|
5350 |
25 May 10 |
nicklas |
var hexColor=pen.color.getHex(); |
5350 |
25 May 10 |
nicklas |
2332 |
|
5350 |
25 May 10 |
nicklas |
//For Inner Ellipse |
5350 |
25 May 10 |
nicklas |
var ai=a-parseInt(pen.width)+1; |
5350 |
25 May 10 |
nicklas |
var bi=b-parseInt(pen.width)+1; |
5350 |
25 May 10 |
nicklas |
2336 |
|
5350 |
25 May 10 |
nicklas |
var res=getInnerEllipse(phCenter,ai*2,bi*2) |
5350 |
25 May 10 |
nicklas |
var xArray=res[0]; |
5350 |
25 May 10 |
nicklas |
var xArrayI=res[1]; |
5350 |
25 May 10 |
nicklas |
xArray.pop(); |
5350 |
25 May 10 |
nicklas |
xArrayI.pop(); |
5350 |
25 May 10 |
nicklas |
2342 |
|
5350 |
25 May 10 |
nicklas |
var xp,yp; |
5350 |
25 May 10 |
nicklas |
var divX1,divX1pU,divX1pD,divX2,divX2pU,divX2pD,divY1,divY2,saX,eaX,saXp,eaXp,xpU,xpD,ypU,ypD,divX1i,divX2i,divX1pUi,divX1pDi,divX2pUi,divX2pDi; |
5350 |
25 May 10 |
nicklas |
var divWidthOrg,divWidth1,divWidth2,divWidth3,divWidth4,divWidth1p,divWidth2p,divWidth3p,divWidth4p,divHeight,divWidth1i,divWidth2i,divWidth3i,divWidth4i,divWidth1pi,divWidth2pi,divWidth3pi,divWidth4pi; |
5350 |
25 May 10 |
nicklas |
var draw1p,draw2p,draw3p,draw4p; |
5350 |
25 May 10 |
nicklas |
2347 |
|
5350 |
25 May 10 |
nicklas |
xp=1; |
5350 |
25 May 10 |
nicklas |
yp=y; |
5350 |
25 May 10 |
nicklas |
2350 |
|
5350 |
25 May 10 |
nicklas |
//Upper and lower portion of the ellipse constutuing the arc |
5350 |
25 May 10 |
nicklas |
while(b2*x < a2*y) |
5350 |
25 May 10 |
nicklas |
2353 |
{ |
5350 |
25 May 10 |
nicklas |
x++; |
5350 |
25 May 10 |
nicklas |
if((b2*x*x + a2*(y-0.5)*(y-0.5) - a2*b2) >=0) |
5350 |
25 May 10 |
nicklas |
y--; |
5350 |
25 May 10 |
nicklas |
2357 |
|
5350 |
25 May 10 |
nicklas |
if(x==1 && y!=yp) //Topmost and bottom most points, to be tested |
5350 |
25 May 10 |
nicklas |
2359 |
{ |
5350 |
25 May 10 |
nicklas |
divY1=yc+yp-1; |
5350 |
25 May 10 |
nicklas |
divY2=yc-yp; |
5350 |
25 May 10 |
nicklas |
divWidthOrg=1; |
5350 |
25 May 10 |
nicklas |
divWidth1=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
divWidth2=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
divWidth3=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
divWidth4=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
divX1=xc; |
5350 |
25 May 10 |
nicklas |
2368 |
|
5350 |
25 May 10 |
nicklas |
if(saD>=0 && saD<180 && eaD>=0 && eaD<180) |
5350 |
25 May 10 |
nicklas |
2370 |
{ |
5350 |
25 May 10 |
nicklas |
drawArcSegOut(true); |
5350 |
25 May 10 |
nicklas |
if(eaD<=saD) |
5350 |
25 May 10 |
nicklas |
drawArcSegOut(false); |
5350 |
25 May 10 |
nicklas |
2374 |
} |
5350 |
25 May 10 |
nicklas |
else if(saD>=180 && saD<360 && eaD>=180 && eaD<=360) |
5350 |
25 May 10 |
nicklas |
2376 |
{ |
5350 |
25 May 10 |
nicklas |
drawArcSegOut(false); |
5350 |
25 May 10 |
nicklas |
if(eaD<=saD) |
5350 |
25 May 10 |
nicklas |
drawArcSegOut(true); |
5350 |
25 May 10 |
nicklas |
2380 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
2382 |
{ |
5350 |
25 May 10 |
nicklas |
drawArcSegOut(true); |
5350 |
25 May 10 |
nicklas |
drawArcSegOut(false); |
5350 |
25 May 10 |
nicklas |
2385 |
} |
5350 |
25 May 10 |
nicklas |
2386 |
} |
5350 |
25 May 10 |
nicklas |
else if(y!=yp) |
5350 |
25 May 10 |
nicklas |
2388 |
{ |
5350 |
25 May 10 |
nicklas |
divY1=yc+yp; |
5350 |
25 May 10 |
nicklas |
divY2=yc-yp; |
5350 |
25 May 10 |
nicklas |
divWidthOrg=2*(x-1)+1; |
5350 |
25 May 10 |
nicklas |
divWidth1=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
divWidth2=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
divWidth3=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
divWidth4=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
divX1=xc-x+1; |
5350 |
25 May 10 |
nicklas |
2397 |
|
5350 |
25 May 10 |
nicklas |
if(saD>=0 && saD<180 && eaD>=0 && eaD<180) |
5350 |
25 May 10 |
nicklas |
2399 |
{ |
5350 |
25 May 10 |
nicklas |
drawArcSegOut(true); |
5350 |
25 May 10 |
nicklas |
if(eaD<=saD) |
5350 |
25 May 10 |
nicklas |
drawArcSegOut(false); |
5350 |
25 May 10 |
nicklas |
2403 |
} |
5350 |
25 May 10 |
nicklas |
else if(saD>=180 && saD<360 && eaD>=180 && eaD<=360) |
5350 |
25 May 10 |
nicklas |
2405 |
{ |
5350 |
25 May 10 |
nicklas |
drawArcSegOut(false); |
5350 |
25 May 10 |
nicklas |
if(eaD<=saD) |
5350 |
25 May 10 |
nicklas |
drawArcSegOut(true); |
5350 |
25 May 10 |
nicklas |
2409 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
2411 |
{ |
5350 |
25 May 10 |
nicklas |
drawArcSegOut(true); |
5350 |
25 May 10 |
nicklas |
drawArcSegOut(false); |
5350 |
25 May 10 |
nicklas |
2414 |
} |
5350 |
25 May 10 |
nicklas |
2415 |
|
5350 |
25 May 10 |
nicklas |
yp=y; |
5350 |
25 May 10 |
nicklas |
xp=x; |
5350 |
25 May 10 |
nicklas |
2418 |
} |
5350 |
25 May 10 |
nicklas |
2419 |
|
5350 |
25 May 10 |
nicklas |
2420 |
|
5350 |
25 May 10 |
nicklas |
//Last step in loop |
5350 |
25 May 10 |
nicklas |
if(b2*x >= a2*y) |
5350 |
25 May 10 |
nicklas |
2423 |
{ |
5350 |
25 May 10 |
nicklas |
divY1=yc+yp; |
5350 |
25 May 10 |
nicklas |
divY2=yc-yp; |
5350 |
25 May 10 |
nicklas |
divWidthOrg=2*x+1; |
5350 |
25 May 10 |
nicklas |
divWidth1=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
divWidth2=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
divWidth3=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
divWidth4=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
divX1=xc-x; |
5350 |
25 May 10 |
nicklas |
2432 |
|
5350 |
25 May 10 |
nicklas |
if(saD>=0 && saD<180 && eaD>=0 && eaD<180) |
5350 |
25 May 10 |
nicklas |
2434 |
{ |
5350 |
25 May 10 |
nicklas |
drawArcSegOut(true); |
5350 |
25 May 10 |
nicklas |
if(eaD<=saD) |
5350 |
25 May 10 |
nicklas |
drawArcSegOut(false); |
5350 |
25 May 10 |
nicklas |
2438 |
} |
5350 |
25 May 10 |
nicklas |
else if(saD>=180 && saD<360 && eaD>=180 && eaD<=360) |
5350 |
25 May 10 |
nicklas |
2440 |
{ |
5350 |
25 May 10 |
nicklas |
drawArcSegOut(false); |
5350 |
25 May 10 |
nicklas |
if(eaD<=saD) |
5350 |
25 May 10 |
nicklas |
drawArcSegOut(true); |
5350 |
25 May 10 |
nicklas |
2444 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
2446 |
{ |
5350 |
25 May 10 |
nicklas |
drawArcSegOut(true); |
5350 |
25 May 10 |
nicklas |
drawArcSegOut(false); |
5350 |
25 May 10 |
nicklas |
2449 |
} |
5350 |
25 May 10 |
nicklas |
2450 |
} |
5350 |
25 May 10 |
nicklas |
2451 |
} |
5350 |
25 May 10 |
nicklas |
2452 |
|
5350 |
25 May 10 |
nicklas |
xp=x; |
5350 |
25 May 10 |
nicklas |
yp=y; |
5350 |
25 May 10 |
nicklas |
divHeight=1; |
5350 |
25 May 10 |
nicklas |
2456 |
|
5350 |
25 May 10 |
nicklas |
//Similar code as in next while loop for first y before the loop. Only values are retrieved and no drawing. |
5350 |
25 May 10 |
nicklas |
2458 |
|
5350 |
25 May 10 |
nicklas |
divY1=yc+y; |
5350 |
25 May 10 |
nicklas |
divY2=yc-y; |
5350 |
25 May 10 |
nicklas |
divWidthOrg=2*x+1; |
5350 |
25 May 10 |
nicklas |
divWidth1=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
divWidth2=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
divWidth3=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
divWidth4=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
divX1=xc-x; |
5350 |
25 May 10 |
nicklas |
2467 |
|
5350 |
25 May 10 |
nicklas |
if(saD>=0 && saD<180 && eaD>=0 && eaD<180) |
5350 |
25 May 10 |
nicklas |
2469 |
{ |
5350 |
25 May 10 |
nicklas |
xDataArrayEa.pop(); |
5350 |
25 May 10 |
nicklas |
drawArcSegIn(true,true); |
5350 |
25 May 10 |
nicklas |
if(eaD<=saD) |
5350 |
25 May 10 |
nicklas |
drawArcSegIn(false,true); |
5350 |
25 May 10 |
nicklas |
2474 |
} |
5350 |
25 May 10 |
nicklas |
else if(saD>=180 && saD<360 && eaD>=180 && eaD<=360) |
5350 |
25 May 10 |
nicklas |
2476 |
{ |
5350 |
25 May 10 |
nicklas |
xDataArrayEa.pop(); |
5350 |
25 May 10 |
nicklas |
if(y!=0) |
5350 |
25 May 10 |
nicklas |
drawArcSegIn(false,true); |
5350 |
25 May 10 |
nicklas |
if(eaD<=saD) |
5350 |
25 May 10 |
nicklas |
drawArcSegIn(true,true); |
5350 |
25 May 10 |
nicklas |
2482 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
2484 |
{ |
5350 |
25 May 10 |
nicklas |
if(saD>=180 && saD<360) |
5350 |
25 May 10 |
nicklas |
xDataArraySa.pop(); |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
xDataArrayEa.pop(); |
5350 |
25 May 10 |
nicklas |
2489 |
|
5350 |
25 May 10 |
nicklas |
2490 |
|
5350 |
25 May 10 |
nicklas |
drawArcSegIn(true,true); |
5350 |
25 May 10 |
nicklas |
if(y!=0) |
5350 |
25 May 10 |
nicklas |
2493 |
{ |
5350 |
25 May 10 |
nicklas |
divX1=xc-x; |
5350 |
25 May 10 |
nicklas |
drawArcSegIn(false,true); |
5350 |
25 May 10 |
nicklas |
2496 |
} |
5350 |
25 May 10 |
nicklas |
2497 |
} |
5350 |
25 May 10 |
nicklas |
2498 |
|
5350 |
25 May 10 |
nicklas |
//Left and Right portion of the ellipse ellipse constutuing the arc. |
5350 |
25 May 10 |
nicklas |
while(y!=0) |
5350 |
25 May 10 |
nicklas |
2501 |
{ |
5350 |
25 May 10 |
nicklas |
y--; |
5350 |
25 May 10 |
nicklas |
if((b2*(x+0.5)*(x+0.5) + a2*y*y - a2*b2)<=0) |
5350 |
25 May 10 |
nicklas |
x++; |
5350 |
25 May 10 |
nicklas |
2505 |
|
5350 |
25 May 10 |
nicklas |
divY1=yc+y; |
5350 |
25 May 10 |
nicklas |
divY2=yc-y; |
5350 |
25 May 10 |
nicklas |
divWidthOrg=2*x+1; |
5350 |
25 May 10 |
nicklas |
divWidth1=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
divWidth2=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
divWidth3=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
divWidth4=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
divX1=xc-x; |
5350 |
25 May 10 |
nicklas |
2514 |
|
5350 |
25 May 10 |
nicklas |
if(saD>=0 && saD<180 && eaD>=0 && eaD<180) |
5350 |
25 May 10 |
nicklas |
2516 |
{ |
5350 |
25 May 10 |
nicklas |
drawArcSegIn(true); |
5350 |
25 May 10 |
nicklas |
if(eaD<=saD) |
5350 |
25 May 10 |
nicklas |
drawArcSegIn(false); |
5350 |
25 May 10 |
nicklas |
2520 |
} |
5350 |
25 May 10 |
nicklas |
else if(saD>=180 && saD<360 && eaD>=180 && eaD<=360) |
5350 |
25 May 10 |
nicklas |
2522 |
{ |
5350 |
25 May 10 |
nicklas |
if(y!=0) |
5350 |
25 May 10 |
nicklas |
drawArcSegIn(false); |
5350 |
25 May 10 |
nicklas |
if(eaD<=saD) |
5350 |
25 May 10 |
nicklas |
drawArcSegIn(true); |
5350 |
25 May 10 |
nicklas |
2527 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
2529 |
{ |
5350 |
25 May 10 |
nicklas |
drawArcSegIn(true); |
5350 |
25 May 10 |
nicklas |
if(y!=0) |
5350 |
25 May 10 |
nicklas |
2532 |
{ |
5350 |
25 May 10 |
nicklas |
divX1=xc-x; |
5350 |
25 May 10 |
nicklas |
drawArcSegIn(false); |
5350 |
25 May 10 |
nicklas |
2535 |
} |
5350 |
25 May 10 |
nicklas |
2536 |
} |
5350 |
25 May 10 |
nicklas |
2537 |
} |
5350 |
25 May 10 |
nicklas |
2538 |
|
5350 |
25 May 10 |
nicklas |
arcDiv.innerHTML=iHtml.join(""); |
5350 |
25 May 10 |
nicklas |
return arcDiv; |
5350 |
25 May 10 |
nicklas |
2541 |
|
5350 |
25 May 10 |
nicklas |
//Internal function: Arc segment for left and right portion of the ellipse constutuing the arc. |
5350 |
25 May 10 |
nicklas |
function drawArcSegIn(isUpperHalf,valueOnly) |
5350 |
25 May 10 |
nicklas |
2544 |
{ |
5350 |
25 May 10 |
nicklas |
var divY; |
5350 |
25 May 10 |
nicklas |
var xDataArray1,xDataArray1; |
5350 |
25 May 10 |
nicklas |
var divWidthFirst=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
var divWidthSecond=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
var drawFirst=false; |
5350 |
25 May 10 |
nicklas |
var drawSecond=false; |
5350 |
25 May 10 |
nicklas |
var xIn; |
5350 |
25 May 10 |
nicklas |
2552 |
|
7419 |
03 Nov 17 |
nicklas |
var xDataArray1, xDataArray2; |
7419 |
03 Nov 17 |
nicklas |
var saDvar, eaDvar; |
5350 |
25 May 10 |
nicklas |
if(isUpperHalf) |
5350 |
25 May 10 |
nicklas |
2556 |
{ |
5350 |
25 May 10 |
nicklas |
var draw1=false; //upper half |
5350 |
25 May 10 |
nicklas |
var draw3=false; //upper half second |
5350 |
25 May 10 |
nicklas |
divY=divY1; |
5350 |
25 May 10 |
nicklas |
xDataArray1=xDataArraySa; |
5350 |
25 May 10 |
nicklas |
xDataArray2=xDataArrayEa; |
5350 |
25 May 10 |
nicklas |
saDvar=saD; |
5350 |
25 May 10 |
nicklas |
eaDvar=eaD; |
5350 |
25 May 10 |
nicklas |
2564 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
2566 |
{ |
5350 |
25 May 10 |
nicklas |
var draw2=false; //lower half |
5350 |
25 May 10 |
nicklas |
var draw4=false; //lower half second |
5350 |
25 May 10 |
nicklas |
divY=divY2; |
5350 |
25 May 10 |
nicklas |
xDataArray2=xDataArraySa; |
5350 |
25 May 10 |
nicklas |
xDataArray1=xDataArrayEa; |
5350 |
25 May 10 |
nicklas |
saDvar=360-eaD; |
5350 |
25 May 10 |
nicklas |
eaDvar=360-saD; |
5350 |
25 May 10 |
nicklas |
2574 |
} |
5350 |
25 May 10 |
nicklas |
if(eaDvar>saDvar) |
5350 |
25 May 10 |
nicklas |
2576 |
{ |
5350 |
25 May 10 |
nicklas |
if(xDataArray2[divY]!=null && divX1+divWidthOrg>=xDataArray2[divY].xMin && divX1<=xDataArray2[divY].xMin) |
5350 |
25 May 10 |
nicklas |
2578 |
{ |
5350 |
25 May 10 |
nicklas |
eaX=xDataArray2[divY].xMin; |
5350 |
25 May 10 |
nicklas |
if(xDataArray1[divY]!=null && divX1+divWidthOrg>=xDataArray1[divY].xMax+1 && divX1<=xDataArray1[divY].xMax+1) |
5350 |
25 May 10 |
nicklas |
2581 |
{ |
5350 |
25 May 10 |
nicklas |
saX=xDataArray1[divY].xMax+1; |
5350 |
25 May 10 |
nicklas |
divWidthFirst=saX-eaX; |
5350 |
25 May 10 |
nicklas |
2584 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
2586 |
{ |
5350 |
25 May 10 |
nicklas |
divWidthFirst=divX1+divWidthOrg-eaX; |
5350 |
25 May 10 |
nicklas |
2588 |
} |
5350 |
25 May 10 |
nicklas |
divX1=eaX; |
5350 |
25 May 10 |
nicklas |
drawFirst=true; |
5350 |
25 May 10 |
nicklas |
2591 |
} |
5350 |
25 May 10 |
nicklas |
else if(xDataArray1[divY]!=null && divX1+divWidthOrg>=xDataArray1[divY].xMax+1 && divX1<=xDataArray1[divY].xMax+1) |
5350 |
25 May 10 |
nicklas |
2593 |
{ |
5350 |
25 May 10 |
nicklas |
saX=xDataArray1[divY].xMax+1; |
5350 |
25 May 10 |
nicklas |
divWidthFirst=saX-divX1; |
5350 |
25 May 10 |
nicklas |
drawFirst=true; |
5350 |
25 May 10 |
nicklas |
2597 |
} |
5350 |
25 May 10 |
nicklas |
else if(eaDvar>90 && saDvar<90) |
5350 |
25 May 10 |
nicklas |
2599 |
{ |
5350 |
25 May 10 |
nicklas |
drawFirst=true; |
5350 |
25 May 10 |
nicklas |
2601 |
} |
5350 |
25 May 10 |
nicklas |
2602 |
} |
5350 |
25 May 10 |
nicklas |
else //saDvar>eaDvar |
5350 |
25 May 10 |
nicklas |
2604 |
{ |
5350 |
25 May 10 |
nicklas |
if(xDataArray1[divY]!=null && divX1+divWidthOrg>=xDataArray1[divY].xMax+1 && divX1<=xDataArray1[divY].xMax+1) |
5350 |
25 May 10 |
nicklas |
2606 |
{ |
5350 |
25 May 10 |
nicklas |
saX=xDataArray1[divY].xMax+1; |
5350 |
25 May 10 |
nicklas |
divWidthFirst=saX-divX1; |
5350 |
25 May 10 |
nicklas |
drawFirst=true; |
5350 |
25 May 10 |
nicklas |
2610 |
} |
5350 |
25 May 10 |
nicklas |
else if(eaDvar<90 && saDvar<90) |
5350 |
25 May 10 |
nicklas |
2612 |
{ |
5350 |
25 May 10 |
nicklas |
drawFirst=true; |
5350 |
25 May 10 |
nicklas |
2614 |
} |
5350 |
25 May 10 |
nicklas |
2615 |
|
5350 |
25 May 10 |
nicklas |
if(xDataArray2[divY]!=null && divX1+divWidthOrg>=xDataArray2[divY].xMin && divX1<=xDataArray2[divY].xMin) |
5350 |
25 May 10 |
nicklas |
2617 |
{ |
5350 |
25 May 10 |
nicklas |
divX2=xDataArray2[divY].xMin; |
5350 |
25 May 10 |
nicklas |
divWidthSecond=divWidthOrg-xDataArray2[divY].xMin+divX1; |
5350 |
25 May 10 |
nicklas |
drawSecond=true; |
5350 |
25 May 10 |
nicklas |
2621 |
} |
5350 |
25 May 10 |
nicklas |
else if(eaDvar>90 && saDvar>90) |
5350 |
25 May 10 |
nicklas |
2623 |
{ |
5350 |
25 May 10 |
nicklas |
divX2=divX1; |
5350 |
25 May 10 |
nicklas |
divWidthSecond=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
drawSecond=true; |
5350 |
25 May 10 |
nicklas |
2627 |
} |
5350 |
25 May 10 |
nicklas |
2628 |
} |
5350 |
25 May 10 |
nicklas |
2629 |
|
5350 |
25 May 10 |
nicklas |
if(isUpperHalf) |
5350 |
25 May 10 |
nicklas |
2631 |
{ |
5350 |
25 May 10 |
nicklas |
if(drawFirst) |
5350 |
25 May 10 |
nicklas |
draw1=true; |
5350 |
25 May 10 |
nicklas |
2634 |
|
5350 |
25 May 10 |
nicklas |
if(drawSecond) |
5350 |
25 May 10 |
nicklas |
draw3=true; |
5350 |
25 May 10 |
nicklas |
2637 |
|
5350 |
25 May 10 |
nicklas |
divWidth1=divWidthFirst; |
5350 |
25 May 10 |
nicklas |
divWidth3=divWidthSecond; |
5350 |
25 May 10 |
nicklas |
2640 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
2642 |
{ |
5350 |
25 May 10 |
nicklas |
if(drawFirst) |
5350 |
25 May 10 |
nicklas |
draw2=true; |
5350 |
25 May 10 |
nicklas |
2645 |
|
5350 |
25 May 10 |
nicklas |
if(drawSecond) |
5350 |
25 May 10 |
nicklas |
draw4=true; |
5350 |
25 May 10 |
nicklas |
2648 |
|
5350 |
25 May 10 |
nicklas |
divWidth2=divWidthFirst; |
5350 |
25 May 10 |
nicklas |
divWidth4=divWidthSecond; |
5350 |
25 May 10 |
nicklas |
2651 |
} |
5350 |
25 May 10 |
nicklas |
2652 |
|
5350 |
25 May 10 |
nicklas |
if(saD>=0 && saD<180 && eaD>=0 && eaD<180 && saD>eaD) |
5350 |
25 May 10 |
nicklas |
2654 |
{ |
5350 |
25 May 10 |
nicklas |
draw2=true; |
5350 |
25 May 10 |
nicklas |
2656 |
} |
5350 |
25 May 10 |
nicklas |
else if(saD>=180 && saD<360 && eaD>=180 && eaD<360 && saD>eaD) |
5350 |
25 May 10 |
nicklas |
2658 |
{ |
5350 |
25 May 10 |
nicklas |
draw1=true; |
5350 |
25 May 10 |
nicklas |
2660 |
} |
5350 |
25 May 10 |
nicklas |
2661 |
|
5350 |
25 May 10 |
nicklas |
//Start: Only for drawArc (not in fillArc) |
5350 |
25 May 10 |
nicklas |
if(draw1) |
5350 |
25 May 10 |
nicklas |
2664 |
{ |
5350 |
25 May 10 |
nicklas |
if(xArray[divY1-yc]!=null && divX1!=null) |
5350 |
25 May 10 |
nicklas |
2666 |
{ |
5350 |
25 May 10 |
nicklas |
if(xc+xArray[divY1-yc]<=divX1+divWidth1) |
5350 |
25 May 10 |
nicklas |
2668 |
{ |
5350 |
25 May 10 |
nicklas |
if(divWidth1>divX1+divWidth1-xc-xArray[divY1-yc]) |
5350 |
25 May 10 |
nicklas |
2670 |
{ |
5350 |
25 May 10 |
nicklas |
divX1i=xc+xArray[divY1-yc]; |
5350 |
25 May 10 |
nicklas |
divWidth1i=divX1+divWidth1-xc-xArray[divY1-yc]; |
5350 |
25 May 10 |
nicklas |
2673 |
} |
5350 |
25 May 10 |
nicklas |
2674 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
divX1i=null; |
5350 |
25 May 10 |
nicklas |
2677 |
|
5350 |
25 May 10 |
nicklas |
if(divX1<=xc-xArray[divY1-yc]+1) |
5350 |
25 May 10 |
nicklas |
2679 |
{ |
5350 |
25 May 10 |
nicklas |
if(divWidth1>xc-xArray[divY1-yc]-divX1+1) |
5350 |
25 May 10 |
nicklas |
divWidth1=xc-xArray[divY1-yc]-divX1+1; |
5350 |
25 May 10 |
nicklas |
2682 |
} |
5350 |
25 May 10 |
nicklas |
else if(divWidth1>=divX1+divWidth1-xc-xArray[divY1-yc]+1) |
5350 |
25 May 10 |
nicklas |
divX1=null; |
5350 |
25 May 10 |
nicklas |
2685 |
} |
5350 |
25 May 10 |
nicklas |
2686 |
} |
5350 |
25 May 10 |
nicklas |
2687 |
|
5350 |
25 May 10 |
nicklas |
if(draw3) |
5350 |
25 May 10 |
nicklas |
2689 |
{ |
5350 |
25 May 10 |
nicklas |
if(xArray[divY1-yc]!=null && divX2!=null) |
5350 |
25 May 10 |
nicklas |
2691 |
{ |
5350 |
25 May 10 |
nicklas |
if(xc+xArray[divY1-yc]<=divX2+divWidth3) |
5350 |
25 May 10 |
nicklas |
2693 |
{ |
5350 |
25 May 10 |
nicklas |
if(divWidth3>divX2+divWidth3-xc-xArray[divY1-yc]) |
5350 |
25 May 10 |
nicklas |
2695 |
{ |
5350 |
25 May 10 |
nicklas |
divX2i=xc+xArray[divY1-yc]; |
5350 |
25 May 10 |
nicklas |
divWidth3i=divX2+divWidth3-xc-xArray[divY1-yc]; |
5350 |
25 May 10 |
nicklas |
2698 |
} |
5350 |
25 May 10 |
nicklas |
2699 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
divX2i=null; |
5350 |
25 May 10 |
nicklas |
2702 |
|
5350 |
25 May 10 |
nicklas |
if(divX2<=xc-xArray[divY1-yc]+1) |
5350 |
25 May 10 |
nicklas |
2704 |
{ |
5350 |
25 May 10 |
nicklas |
if(divWidth3>xc-xArray[divY1-yc]-divX2+1) |
5350 |
25 May 10 |
nicklas |
divWidth3=xc-xArray[divY1-yc]-divX2+1; |
5350 |
25 May 10 |
nicklas |
2707 |
} |
5350 |
25 May 10 |
nicklas |
else if(divWidth3>=divX2+divWidth3-xc-xArray[divY1-yc]+1) |
5350 |
25 May 10 |
nicklas |
divX2=null; |
5350 |
25 May 10 |
nicklas |
2710 |
} |
5350 |
25 May 10 |
nicklas |
2711 |
} |
5350 |
25 May 10 |
nicklas |
2712 |
|
5350 |
25 May 10 |
nicklas |
//Lower Half |
5350 |
25 May 10 |
nicklas |
if(draw2) |
5350 |
25 May 10 |
nicklas |
2715 |
{ |
5350 |
25 May 10 |
nicklas |
if(xArray[divY1-yc]!=null && divX1!=null) |
5350 |
25 May 10 |
nicklas |
2717 |
{ |
5350 |
25 May 10 |
nicklas |
if(xc+xArray[divY1-yc]<=divX1+divWidth2) |
5350 |
25 May 10 |
nicklas |
2719 |
{ |
5350 |
25 May 10 |
nicklas |
if(divWidth2>divX1+divWidth2-xc-xArray[divY1-yc]) |
5350 |
25 May 10 |
nicklas |
2721 |
{ |
5350 |
25 May 10 |
nicklas |
divX1i=xc+xArray[divY1-yc]; |
5350 |
25 May 10 |
nicklas |
divWidth2i=divX1+divWidth2-xc-xArray[divY1-yc]; |
5350 |
25 May 10 |
nicklas |
2724 |
} |
5350 |
25 May 10 |
nicklas |
2725 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
divX1i=null; |
5350 |
25 May 10 |
nicklas |
2728 |
|
5350 |
25 May 10 |
nicklas |
if(divX1<=xc-xArray[divY1-yc]+1) |
5350 |
25 May 10 |
nicklas |
2730 |
{ |
5350 |
25 May 10 |
nicklas |
if(divWidth2>xc-xArray[divY1-yc]-divX1+1) |
5350 |
25 May 10 |
nicklas |
divWidth2=xc-xArray[divY1-yc]-divX1+1; |
5350 |
25 May 10 |
nicklas |
2733 |
} |
5350 |
25 May 10 |
nicklas |
else if(divWidth2>=divX1+divWidth2-xc-xArray[divY1-yc]+1) |
5350 |
25 May 10 |
nicklas |
divX1=null; |
5350 |
25 May 10 |
nicklas |
2736 |
} |
5350 |
25 May 10 |
nicklas |
2737 |
} |
5350 |
25 May 10 |
nicklas |
2738 |
|
5350 |
25 May 10 |
nicklas |
if(draw4) |
5350 |
25 May 10 |
nicklas |
2740 |
{ |
5350 |
25 May 10 |
nicklas |
if(xArray[divY1-yc]!=null && divX2!=null) |
5350 |
25 May 10 |
nicklas |
2742 |
{ |
5350 |
25 May 10 |
nicklas |
if(xc+xArray[divY1-yc]<=divX2+divWidth4) |
5350 |
25 May 10 |
nicklas |
2744 |
{ |
5350 |
25 May 10 |
nicklas |
if(divWidth4>divX2+divWidth4-xc-xArray[divY1-yc]) |
5350 |
25 May 10 |
nicklas |
2746 |
{ |
5350 |
25 May 10 |
nicklas |
divX2i=xc+xArray[divY1-yc]; |
5350 |
25 May 10 |
nicklas |
divWidth4i=divX2+divWidth4-xc-xArray[divY1-yc]; |
5350 |
25 May 10 |
nicklas |
2749 |
} |
5350 |
25 May 10 |
nicklas |
2750 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
divX2i=null; |
5350 |
25 May 10 |
nicklas |
2753 |
|
5350 |
25 May 10 |
nicklas |
if(divX2<=xc-xArray[divY1-yc]+1) |
5350 |
25 May 10 |
nicklas |
2755 |
{ |
5350 |
25 May 10 |
nicklas |
if(divWidth4>xc-xArray[divY1-yc]-divX2+1) |
5350 |
25 May 10 |
nicklas |
divWidth4=xc-xArray[divY1-yc]-divX2+1; |
5350 |
25 May 10 |
nicklas |
2758 |
} |
5350 |
25 May 10 |
nicklas |
else if(divWidth4>=divX2+divWidth4-xc-xArray[divY1-yc]+1) |
5350 |
25 May 10 |
nicklas |
divX2=null; |
5350 |
25 May 10 |
nicklas |
2761 |
} |
5350 |
25 May 10 |
nicklas |
2762 |
} |
5350 |
25 May 10 |
nicklas |
//End: Only for drawArc (not in fillArc) |
5350 |
25 May 10 |
nicklas |
2764 |
|
5350 |
25 May 10 |
nicklas |
if(divX2==null) |
5350 |
25 May 10 |
nicklas |
divX2=""; |
5350 |
25 May 10 |
nicklas |
if(divX1==null) |
5350 |
25 May 10 |
nicklas |
divX1=""; |
5350 |
25 May 10 |
nicklas |
2769 |
|
5350 |
25 May 10 |
nicklas |
2770 |
|
5350 |
25 May 10 |
nicklas |
if(!valueOnly) |
5350 |
25 May 10 |
nicklas |
2772 |
{ |
5350 |
25 May 10 |
nicklas |
if(isUpperHalf) |
5350 |
25 May 10 |
nicklas |
2774 |
{ |
5350 |
25 May 10 |
nicklas |
if(x!=xpU || divX1pU!=divX1 || divX1pUi!=divX1i || divX2pU!=divX2 || divX2pUi!=divX2i || divWidth1!=divWidth1p || divWidth3!=divWidth3p || divWidth1i!=divWidth1pi || divWidth3i!=divWidth3pi) |
5350 |
25 May 10 |
nicklas |
2776 |
{ |
5350 |
25 May 10 |
nicklas |
divHeight=ypU-y; |
5350 |
25 May 10 |
nicklas |
if(draw3p) |
5350 |
25 May 10 |
nicklas |
2779 |
{ |
5350 |
25 May 10 |
nicklas |
if(divX2pU!=null && divX2pU!="") |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + divX2pU + "px;top:" + (divY1+1) + "px;width:" + divWidth3p + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
2782 |
|
5350 |
25 May 10 |
nicklas |
if(divX2pUi!=null && divX2pUi!="") |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + divX2pUi + "px;top:" + (divY1+1) + "px;width:" + divWidth3pi + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
2785 |
} |
5350 |
25 May 10 |
nicklas |
2786 |
|
5350 |
25 May 10 |
nicklas |
if(draw1p) |
5350 |
25 May 10 |
nicklas |
2788 |
{ |
5350 |
25 May 10 |
nicklas |
if(divX1pU!=null && divX1pU!="") |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + divX1pU + "px;top:" + (divY1+1) + "px;width:" + divWidth1p + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
2791 |
|
5350 |
25 May 10 |
nicklas |
if(divX1pUi!=null && divX1pUi!="") |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + divX1pUi + "px;top:" + (divY1+1) + "px;width:" + divWidth1pi + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
2794 |
} |
5350 |
25 May 10 |
nicklas |
2795 |
|
5350 |
25 May 10 |
nicklas |
if(draw1p||draw3p) |
5350 |
25 May 10 |
nicklas |
2797 |
{ |
5350 |
25 May 10 |
nicklas |
divX1pU=divX1; |
5350 |
25 May 10 |
nicklas |
divX1pUi=divX1i; |
5350 |
25 May 10 |
nicklas |
2800 |
|
5350 |
25 May 10 |
nicklas |
draw1p=draw1; |
5350 |
25 May 10 |
nicklas |
draw3p=draw3; |
5350 |
25 May 10 |
nicklas |
2803 |
|
5350 |
25 May 10 |
nicklas |
xpU=x; |
5350 |
25 May 10 |
nicklas |
ypU=y; |
5350 |
25 May 10 |
nicklas |
2806 |
|
5350 |
25 May 10 |
nicklas |
divWidth1p=divWidth1; |
5350 |
25 May 10 |
nicklas |
divWidth3p=divWidth3; |
5350 |
25 May 10 |
nicklas |
2809 |
|
5350 |
25 May 10 |
nicklas |
divX2pU=divX2; |
5350 |
25 May 10 |
nicklas |
divX2pUi=divX2i; |
5350 |
25 May 10 |
nicklas |
2812 |
|
5350 |
25 May 10 |
nicklas |
divWidth1pi=divWidth1i; |
5350 |
25 May 10 |
nicklas |
divWidth3pi=divWidth3i; |
5350 |
25 May 10 |
nicklas |
2815 |
} |
5350 |
25 May 10 |
nicklas |
2816 |
} |
5350 |
25 May 10 |
nicklas |
2817 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
2819 |
{ |
5350 |
25 May 10 |
nicklas |
if(x!=xpD || divX1pD!=divX1 ||divX1pDi!=divX1i || divX2pD!=divX2 || divWidth2!=divWidth2p || divWidth2i!=divWidth2pi || divWidth4!=divWidth4p || divWidth4i!=divWidth4pi) |
5350 |
25 May 10 |
nicklas |
2821 |
{ |
5350 |
25 May 10 |
nicklas |
divHeight=ypD-y; |
5350 |
25 May 10 |
nicklas |
if(draw4p) |
5350 |
25 May 10 |
nicklas |
2824 |
{ |
5350 |
25 May 10 |
nicklas |
if(divX2pD!=null && divX2pD!="") |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + divX2pD + "px;top:" + (divY2-divHeight) + "px;width:" + divWidth4p + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
2827 |
|
5350 |
25 May 10 |
nicklas |
if(divX2pDi!=null && divX2pDi!="") |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + divX2pDi + "px;top:" + (divY2-divHeight) + "px;width:" + divWidth4pi + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
2830 |
} |
5350 |
25 May 10 |
nicklas |
if(draw2p) |
5350 |
25 May 10 |
nicklas |
2832 |
{ |
5350 |
25 May 10 |
nicklas |
if(divX1pD!=null && divX1pD!="") |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + divX1pD + "px;top:" + (divY2-divHeight) + "px;width:" + divWidth2p + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
2835 |
|
5350 |
25 May 10 |
nicklas |
if(divX1pDi!=null && divX1pDi!="") |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + divX1pDi + "px;top:" + (divY2-divHeight) + "px;width:" + divWidth2pi + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
2838 |
} |
5350 |
25 May 10 |
nicklas |
if(draw2p||draw4p) |
5350 |
25 May 10 |
nicklas |
2840 |
{ |
5350 |
25 May 10 |
nicklas |
divX1pD=divX1; |
5350 |
25 May 10 |
nicklas |
divX1pDi=divX1i; |
5350 |
25 May 10 |
nicklas |
2843 |
|
5350 |
25 May 10 |
nicklas |
draw2p=draw2; |
5350 |
25 May 10 |
nicklas |
draw4p=draw4; |
5350 |
25 May 10 |
nicklas |
2846 |
|
5350 |
25 May 10 |
nicklas |
xpD=x; |
5350 |
25 May 10 |
nicklas |
ypD=y; |
5350 |
25 May 10 |
nicklas |
2849 |
|
5350 |
25 May 10 |
nicklas |
divWidth2p=divWidth2; |
5350 |
25 May 10 |
nicklas |
divWidth4p=divWidth4; |
5350 |
25 May 10 |
nicklas |
2852 |
|
5350 |
25 May 10 |
nicklas |
divX2pD=divX2; |
5350 |
25 May 10 |
nicklas |
divX2pDi=divX2i; |
5350 |
25 May 10 |
nicklas |
2855 |
|
5350 |
25 May 10 |
nicklas |
divWidth2pi=divWidth2i; |
5350 |
25 May 10 |
nicklas |
divWidth4pi=divWidth4i; |
5350 |
25 May 10 |
nicklas |
2858 |
} |
5350 |
25 May 10 |
nicklas |
2859 |
} |
5350 |
25 May 10 |
nicklas |
2860 |
} |
5350 |
25 May 10 |
nicklas |
2861 |
} |
5350 |
25 May 10 |
nicklas |
2862 |
|
5350 |
25 May 10 |
nicklas |
//To get only values; used for first y value before loop. |
5350 |
25 May 10 |
nicklas |
if(valueOnly) |
5350 |
25 May 10 |
nicklas |
2865 |
{ |
5350 |
25 May 10 |
nicklas |
if(isUpperHalf) |
5350 |
25 May 10 |
nicklas |
2867 |
{ |
5350 |
25 May 10 |
nicklas |
draw1p=draw1; |
5350 |
25 May 10 |
nicklas |
draw3p=draw3; |
5350 |
25 May 10 |
nicklas |
2870 |
|
5350 |
25 May 10 |
nicklas |
if(draw1p) |
5350 |
25 May 10 |
nicklas |
2872 |
{ |
5350 |
25 May 10 |
nicklas |
divX1pU=divX1; |
5350 |
25 May 10 |
nicklas |
divX1pUi=divX1i; |
5350 |
25 May 10 |
nicklas |
2875 |
} |
5350 |
25 May 10 |
nicklas |
2876 |
|
5350 |
25 May 10 |
nicklas |
if(draw3p) |
5350 |
25 May 10 |
nicklas |
2878 |
{ |
5350 |
25 May 10 |
nicklas |
divX2pU=divX2; |
5350 |
25 May 10 |
nicklas |
divX2pUi=divX2i; |
5350 |
25 May 10 |
nicklas |
2881 |
} |
5350 |
25 May 10 |
nicklas |
2882 |
|
5350 |
25 May 10 |
nicklas |
if(draw1p||draw3p) |
5350 |
25 May 10 |
nicklas |
2884 |
{ |
5350 |
25 May 10 |
nicklas |
ypU=y; |
5350 |
25 May 10 |
nicklas |
xpU=x; |
5350 |
25 May 10 |
nicklas |
2887 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
2889 |
{ |
5350 |
25 May 10 |
nicklas |
ypU=0; |
5350 |
25 May 10 |
nicklas |
xpU=0; |
5350 |
25 May 10 |
nicklas |
2892 |
} |
5350 |
25 May 10 |
nicklas |
2893 |
|
5350 |
25 May 10 |
nicklas |
divWidth1p=divWidth1; |
5350 |
25 May 10 |
nicklas |
divWidth3p=divWidth3; |
5350 |
25 May 10 |
nicklas |
divWidth1pi=divWidth1i; |
5350 |
25 May 10 |
nicklas |
divWidth3pi=divWidth3i; |
5350 |
25 May 10 |
nicklas |
2898 |
|
5350 |
25 May 10 |
nicklas |
2899 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
2901 |
{ |
5350 |
25 May 10 |
nicklas |
draw2p=draw2; |
5350 |
25 May 10 |
nicklas |
draw4p=draw4; |
5350 |
25 May 10 |
nicklas |
2904 |
|
5350 |
25 May 10 |
nicklas |
if(draw2p) |
5350 |
25 May 10 |
nicklas |
2906 |
{ |
5350 |
25 May 10 |
nicklas |
divX1pD=divX1; |
5350 |
25 May 10 |
nicklas |
divX1pDi=divX1i; |
5350 |
25 May 10 |
nicklas |
2909 |
} |
5350 |
25 May 10 |
nicklas |
2910 |
|
5350 |
25 May 10 |
nicklas |
if(draw4p) |
5350 |
25 May 10 |
nicklas |
2912 |
{ |
5350 |
25 May 10 |
nicklas |
divX2pD=divX2; |
5350 |
25 May 10 |
nicklas |
divX2pDi=divX2i; |
5350 |
25 May 10 |
nicklas |
2915 |
} |
5350 |
25 May 10 |
nicklas |
2916 |
|
5350 |
25 May 10 |
nicklas |
if(draw2p||draw4p) |
5350 |
25 May 10 |
nicklas |
2918 |
{ |
5350 |
25 May 10 |
nicklas |
ypD=y; |
5350 |
25 May 10 |
nicklas |
xpD=x; |
5350 |
25 May 10 |
nicklas |
2921 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
2923 |
{ |
5350 |
25 May 10 |
nicklas |
ypD=0; |
5350 |
25 May 10 |
nicklas |
xpD=0; |
5350 |
25 May 10 |
nicklas |
2926 |
} |
5350 |
25 May 10 |
nicklas |
2927 |
|
5350 |
25 May 10 |
nicklas |
divWidth2p=divWidth2; |
5350 |
25 May 10 |
nicklas |
divWidth4p=divWidth4; |
5350 |
25 May 10 |
nicklas |
divWidth2pi=divWidth2i; |
5350 |
25 May 10 |
nicklas |
divWidth4pi=divWidth4i; |
5350 |
25 May 10 |
nicklas |
2932 |
} |
5350 |
25 May 10 |
nicklas |
2933 |
} |
5350 |
25 May 10 |
nicklas |
2934 |
|
5350 |
25 May 10 |
nicklas |
if(!isUpperHalf) |
5350 |
25 May 10 |
nicklas |
2936 |
{ |
5350 |
25 May 10 |
nicklas |
draw2p=draw2; |
5350 |
25 May 10 |
nicklas |
draw4p=draw4; |
5350 |
25 May 10 |
nicklas |
2939 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
2941 |
{ |
5350 |
25 May 10 |
nicklas |
draw1p=draw1; |
5350 |
25 May 10 |
nicklas |
draw3p=draw3; |
5350 |
25 May 10 |
nicklas |
2944 |
} |
5350 |
25 May 10 |
nicklas |
2945 |
|
5350 |
25 May 10 |
nicklas |
if(y==1 && !isUpperHalf) |
5350 |
25 May 10 |
nicklas |
2947 |
{ |
5350 |
25 May 10 |
nicklas |
divHeight=ypD-y+1; |
5350 |
25 May 10 |
nicklas |
if(draw4) |
5350 |
25 May 10 |
nicklas |
2950 |
{ |
5350 |
25 May 10 |
nicklas |
if(divX2!="") |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + divX2 + "px;top:" + (divY2+1-divHeight) + "px;width:" + divWidth4 + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
2953 |
|
5350 |
25 May 10 |
nicklas |
if(divX2i!=null) |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + divX2i + "px;top:" + (divY2+1-divHeight) + "px;width:" + divWidth4i + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
2956 |
} |
5350 |
25 May 10 |
nicklas |
if(draw2) |
5350 |
25 May 10 |
nicklas |
2958 |
{ |
5350 |
25 May 10 |
nicklas |
if(divX1!="") |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + divX1 + "px;top:" + (divY2+1-divHeight) + "px;width:" + divWidth2 + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
2961 |
|
5350 |
25 May 10 |
nicklas |
if(divX1i!=null) |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + divX1i + "px;top:" + (divY2+1-divHeight) + "px;width:" + divWidth2i + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
2964 |
} |
5350 |
25 May 10 |
nicklas |
2965 |
} |
5350 |
25 May 10 |
nicklas |
2966 |
|
5350 |
25 May 10 |
nicklas |
if(y==0 && isUpperHalf) |
5350 |
25 May 10 |
nicklas |
2968 |
{ |
5350 |
25 May 10 |
nicklas |
divHeight=ypU-y+1; |
5350 |
25 May 10 |
nicklas |
if(draw3) |
5350 |
25 May 10 |
nicklas |
2971 |
{ |
5350 |
25 May 10 |
nicklas |
if(divX2!="") |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + divX2 + "px;top:" + divY1 + "px;width:" + divWidth3 + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
2974 |
|
5350 |
25 May 10 |
nicklas |
if(divX2i!=null) |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + divX2i + "px;top:" + divY1 + "px;width:" + divWidth3i + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
2977 |
} |
5350 |
25 May 10 |
nicklas |
2978 |
|
5350 |
25 May 10 |
nicklas |
if(draw1) |
5350 |
25 May 10 |
nicklas |
2980 |
{ |
5350 |
25 May 10 |
nicklas |
if(divX1!="") |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + divX1 + "px;top:" + divY1 + "px;width:" + divWidth1 + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
2983 |
|
5350 |
25 May 10 |
nicklas |
if(divX1i!=null) |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + divX1i + "px;top:" + divY1 + "px;width:" + divWidth1i + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
2986 |
} |
5350 |
25 May 10 |
nicklas |
2987 |
} |
5350 |
25 May 10 |
nicklas |
2988 |
} |
5350 |
25 May 10 |
nicklas |
2989 |
|
5350 |
25 May 10 |
nicklas |
//Internal function: Arc segment for upper and lower portion of the ellipse constutuing the arc. |
5350 |
25 May 10 |
nicklas |
function drawArcSegOut(isUpperHalf) |
5350 |
25 May 10 |
nicklas |
2992 |
{ |
5350 |
25 May 10 |
nicklas |
var divY; |
5350 |
25 May 10 |
nicklas |
var xDataArray1,xDataArray1; |
5350 |
25 May 10 |
nicklas |
var divWidthFirst=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
var divWidthSecond=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
var drawFirst=false; |
5350 |
25 May 10 |
nicklas |
var drawSecond=false; |
5350 |
25 May 10 |
nicklas |
2999 |
|
7419 |
03 Nov 17 |
nicklas |
var xDataArray1, xDataArray2; |
7419 |
03 Nov 17 |
nicklas |
var saDvar, eaDvar; |
5350 |
25 May 10 |
nicklas |
if(isUpperHalf) |
5350 |
25 May 10 |
nicklas |
3003 |
{ |
5350 |
25 May 10 |
nicklas |
var draw1=false; //upper half |
5350 |
25 May 10 |
nicklas |
var draw3=false; //upper half second |
5350 |
25 May 10 |
nicklas |
divY=divY1; |
5350 |
25 May 10 |
nicklas |
xDataArray1=xDataArraySa; |
5350 |
25 May 10 |
nicklas |
xDataArray2=xDataArrayEa; |
5350 |
25 May 10 |
nicklas |
saDvar=saD; |
5350 |
25 May 10 |
nicklas |
eaDvar=eaD; |
5350 |
25 May 10 |
nicklas |
3011 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
3013 |
{ |
5350 |
25 May 10 |
nicklas |
var draw2=false; //lower half |
5350 |
25 May 10 |
nicklas |
var draw4=false; //lower half second |
5350 |
25 May 10 |
nicklas |
divY=divY2; |
5350 |
25 May 10 |
nicklas |
xDataArray2=xDataArraySa; |
5350 |
25 May 10 |
nicklas |
xDataArray1=xDataArrayEa; |
5350 |
25 May 10 |
nicklas |
saDvar=360-eaD; |
5350 |
25 May 10 |
nicklas |
eaDvar=360-saD; |
5350 |
25 May 10 |
nicklas |
3021 |
} |
5350 |
25 May 10 |
nicklas |
if(eaDvar>saDvar) |
5350 |
25 May 10 |
nicklas |
3023 |
{ |
5350 |
25 May 10 |
nicklas |
if(xDataArray2[divY]!=null && divX1+divWidthOrg>=xDataArray2[divY].xMin && divX1<=xDataArray2[divY].xMin) |
5350 |
25 May 10 |
nicklas |
3025 |
{ |
5350 |
25 May 10 |
nicklas |
eaX=xDataArray2[divY].xMin; |
5350 |
25 May 10 |
nicklas |
if(xDataArray1[divY] && divX1+divWidthOrg>=xDataArray1[divY].xMax+1 && divX1<=xDataArray1[divY].xMax+1) |
5350 |
25 May 10 |
nicklas |
3028 |
{ |
5350 |
25 May 10 |
nicklas |
saX=xDataArray1[divY].xMax+1; |
5350 |
25 May 10 |
nicklas |
divWidthFirst=saX-eaX; |
5350 |
25 May 10 |
nicklas |
3031 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
3033 |
{ |
5350 |
25 May 10 |
nicklas |
divWidthFirst=divX1+divWidthOrg-eaX; |
5350 |
25 May 10 |
nicklas |
3035 |
} |
5350 |
25 May 10 |
nicklas |
divX1=eaX; |
5350 |
25 May 10 |
nicklas |
drawFirst=true; |
5350 |
25 May 10 |
nicklas |
3038 |
} |
5350 |
25 May 10 |
nicklas |
else if(xDataArray1[divY]!=null && divX1+divWidthOrg>=xDataArray1[divY].xMax+1 && divX1<=xDataArray1[divY].xMax+1) |
5350 |
25 May 10 |
nicklas |
3040 |
{ |
5350 |
25 May 10 |
nicklas |
saX=xDataArray1[divY].xMax+1; |
5350 |
25 May 10 |
nicklas |
divWidthFirst=saX-divX1; |
5350 |
25 May 10 |
nicklas |
drawFirst=true; |
5350 |
25 May 10 |
nicklas |
3044 |
} |
5350 |
25 May 10 |
nicklas |
else if(eaDvar>90 && saDvar<90) |
5350 |
25 May 10 |
nicklas |
3046 |
{ |
5350 |
25 May 10 |
nicklas |
drawFirst=true; |
5350 |
25 May 10 |
nicklas |
3048 |
} |
5350 |
25 May 10 |
nicklas |
3049 |
} |
5350 |
25 May 10 |
nicklas |
else //saDvar>eaDvar |
5350 |
25 May 10 |
nicklas |
3051 |
{ |
5350 |
25 May 10 |
nicklas |
if(xDataArray1[divY]!=null && divX1+divWidthOrg>=xDataArray1[divY].xMax+1 && divX1<=xDataArray1[divY].xMax+1) |
5350 |
25 May 10 |
nicklas |
3053 |
{ |
5350 |
25 May 10 |
nicklas |
saX=xDataArray1[divY].xMax+1; |
5350 |
25 May 10 |
nicklas |
divWidthFirst=saX-divX1; |
5350 |
25 May 10 |
nicklas |
drawFirst=true; |
5350 |
25 May 10 |
nicklas |
3057 |
} |
5350 |
25 May 10 |
nicklas |
else if(eaDvar<90 && saDvar<90) |
5350 |
25 May 10 |
nicklas |
3059 |
{ |
5350 |
25 May 10 |
nicklas |
drawFirst=true; |
5350 |
25 May 10 |
nicklas |
3061 |
} |
5350 |
25 May 10 |
nicklas |
3062 |
|
5350 |
25 May 10 |
nicklas |
if(xDataArray2[divY]!=null && divX1+divWidthOrg>=xDataArray2[divY].xMin && divX1<=xDataArray2[divY].xMin) |
5350 |
25 May 10 |
nicklas |
3064 |
{ |
5350 |
25 May 10 |
nicklas |
divX2=xDataArray2[divY].xMin; |
5350 |
25 May 10 |
nicklas |
divWidthSecond=divWidthOrg-xDataArray2[divY].xMin+divX1; |
5350 |
25 May 10 |
nicklas |
drawSecond=true; |
5350 |
25 May 10 |
nicklas |
3068 |
} |
5350 |
25 May 10 |
nicklas |
else if(eaDvar>90 && saDvar>90) |
5350 |
25 May 10 |
nicklas |
3070 |
{ |
5350 |
25 May 10 |
nicklas |
divX2=divX1; |
5350 |
25 May 10 |
nicklas |
divWidthSecond=divWidthOrg; |
5350 |
25 May 10 |
nicklas |
drawSecond=true; |
5350 |
25 May 10 |
nicklas |
3074 |
} |
5350 |
25 May 10 |
nicklas |
3075 |
} |
5350 |
25 May 10 |
nicklas |
3076 |
|
5350 |
25 May 10 |
nicklas |
if(isUpperHalf) |
5350 |
25 May 10 |
nicklas |
3078 |
{ |
5350 |
25 May 10 |
nicklas |
if(drawFirst) |
5350 |
25 May 10 |
nicklas |
draw1=true; |
5350 |
25 May 10 |
nicklas |
3081 |
|
5350 |
25 May 10 |
nicklas |
if(drawSecond) |
5350 |
25 May 10 |
nicklas |
draw3=true; |
5350 |
25 May 10 |
nicklas |
3084 |
|
5350 |
25 May 10 |
nicklas |
divWidth1=divWidthFirst; |
5350 |
25 May 10 |
nicklas |
divWidth3=divWidthSecond; |
5350 |
25 May 10 |
nicklas |
3087 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
3089 |
{ |
5350 |
25 May 10 |
nicklas |
if(drawFirst) |
5350 |
25 May 10 |
nicklas |
draw2=true; |
5350 |
25 May 10 |
nicklas |
3092 |
|
5350 |
25 May 10 |
nicklas |
if(drawSecond) |
5350 |
25 May 10 |
nicklas |
draw4=true; |
5350 |
25 May 10 |
nicklas |
3095 |
|
5350 |
25 May 10 |
nicklas |
divWidth2=divWidthFirst; |
5350 |
25 May 10 |
nicklas |
divWidth4=divWidthSecond; |
5350 |
25 May 10 |
nicklas |
3098 |
} |
5350 |
25 May 10 |
nicklas |
3099 |
|
5350 |
25 May 10 |
nicklas |
if(saD>=0 && saD<180 && eaD>=0 && eaD<180 && saD>eaD) |
5350 |
25 May 10 |
nicklas |
3101 |
{ |
5350 |
25 May 10 |
nicklas |
draw2=true; |
5350 |
25 May 10 |
nicklas |
3103 |
} |
5350 |
25 May 10 |
nicklas |
else if(saD>=180 && saD<360 && eaD>=180 && eaD<360 && saD>eaD) |
5350 |
25 May 10 |
nicklas |
3105 |
{ |
5350 |
25 May 10 |
nicklas |
draw1=true; |
5350 |
25 May 10 |
nicklas |
3107 |
} |
5350 |
25 May 10 |
nicklas |
3108 |
|
5350 |
25 May 10 |
nicklas |
//Start: Only for drawArc (not in fillArc) |
5350 |
25 May 10 |
nicklas |
if(draw1) |
5350 |
25 May 10 |
nicklas |
3111 |
{ |
5350 |
25 May 10 |
nicklas |
3112 |
|
5350 |
25 May 10 |
nicklas |
if(xArray[divY1-yc] && divX1!=null) |
5350 |
25 May 10 |
nicklas |
3114 |
{ |
5350 |
25 May 10 |
nicklas |
if(xc+xArray[divY1-yc]<=divX1+divWidth1) |
5350 |
25 May 10 |
nicklas |
3116 |
{ |
5350 |
25 May 10 |
nicklas |
if(divWidth1>divX1+divWidth1-xc-xArray[divY1-yc]) |
5350 |
25 May 10 |
nicklas |
3118 |
{ |
5350 |
25 May 10 |
nicklas |
divX1i=xc+xArray[divY1-yc]; |
5350 |
25 May 10 |
nicklas |
divWidth1i=divX1+divWidth1-xc-xArray[divY1-yc]; |
5350 |
25 May 10 |
nicklas |
3121 |
} |
5350 |
25 May 10 |
nicklas |
3122 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
divX1i="X"; |
5350 |
25 May 10 |
nicklas |
3125 |
|
5350 |
25 May 10 |
nicklas |
if(divX1<xc-xArray[divY1-yc]+1) |
5350 |
25 May 10 |
nicklas |
3127 |
{ |
5350 |
25 May 10 |
nicklas |
if(divWidth1>xc-xArray[divY1-yc]-divX1+1) |
5350 |
25 May 10 |
nicklas |
divWidth1=xc-xArray[divY1-yc]-divX1+1; |
5350 |
25 May 10 |
nicklas |
3130 |
} |
5350 |
25 May 10 |
nicklas |
else if(divWidth1>=divX1+divWidth1-xc-xArray[divY1-yc]+1) |
5350 |
25 May 10 |
nicklas |
divX1="X"; |
5350 |
25 May 10 |
nicklas |
3133 |
} |
5350 |
25 May 10 |
nicklas |
3134 |
|
5350 |
25 May 10 |
nicklas |
3135 |
} |
5350 |
25 May 10 |
nicklas |
3136 |
|
5350 |
25 May 10 |
nicklas |
if(draw3) |
5350 |
25 May 10 |
nicklas |
3138 |
{ |
5350 |
25 May 10 |
nicklas |
if(xArray[divY1-yc] && divX2!=null) |
5350 |
25 May 10 |
nicklas |
3140 |
{ |
5350 |
25 May 10 |
nicklas |
if(xc+xArray[divY1-yc]<=divX2+divWidth3) |
5350 |
25 May 10 |
nicklas |
3142 |
{ |
5350 |
25 May 10 |
nicklas |
if(divWidth3>divX2+divWidth3-xc-xArray[divY1-yc]) |
5350 |
25 May 10 |
nicklas |
3144 |
{ |
5350 |
25 May 10 |
nicklas |
divX2i=xc+xArray[divY1-yc]; |
5350 |
25 May 10 |
nicklas |
divWidth3i=divX2+divWidth3-xc-xArray[divY1-yc]; |
5350 |
25 May 10 |
nicklas |
3147 |
} |
5350 |
25 May 10 |
nicklas |
3148 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
divX2i="X"; |
5350 |
25 May 10 |
nicklas |
3151 |
|
5350 |
25 May 10 |
nicklas |
if(divX2<=xc-xArray[divY1-yc]+1) |
5350 |
25 May 10 |
nicklas |
3153 |
{ |
5350 |
25 May 10 |
nicklas |
if(divWidth3>xc-xArray[divY1-yc]-divX2+1) |
5350 |
25 May 10 |
nicklas |
divWidth3=xc-xArray[divY1-yc]-divX2+1; |
5350 |
25 May 10 |
nicklas |
3156 |
} |
5350 |
25 May 10 |
nicklas |
else if(divWidth3>=divX2+divWidth3-xc-xArray[divY1-yc]+1) |
5350 |
25 May 10 |
nicklas |
divX2="X"; |
5350 |
25 May 10 |
nicklas |
3159 |
} |
5350 |
25 May 10 |
nicklas |
3160 |
} |
5350 |
25 May 10 |
nicklas |
3161 |
|
5350 |
25 May 10 |
nicklas |
//Lower Half |
5350 |
25 May 10 |
nicklas |
if(draw2) |
5350 |
25 May 10 |
nicklas |
3164 |
{ |
5350 |
25 May 10 |
nicklas |
if(xArray[divY1-yc] && divX1!=null) |
5350 |
25 May 10 |
nicklas |
3166 |
{ |
5350 |
25 May 10 |
nicklas |
if(xc+xArray[divY1-yc]<=divX1+divWidth2) |
5350 |
25 May 10 |
nicklas |
3168 |
{ |
5350 |
25 May 10 |
nicklas |
if(divWidth2>divX1+divWidth2-xc-xArrayI[divY1-yc]) |
5350 |
25 May 10 |
nicklas |
3170 |
{ |
5350 |
25 May 10 |
nicklas |
divX1i=xc+xArray[divY1-yc]; |
5350 |
25 May 10 |
nicklas |
divWidth2i=divX1+divWidth2-xc-xArray[divY1-yc]; |
5350 |
25 May 10 |
nicklas |
3173 |
} |
5350 |
25 May 10 |
nicklas |
3174 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
divX1i="X"; |
5350 |
25 May 10 |
nicklas |
3177 |
|
5350 |
25 May 10 |
nicklas |
if(divX1<=xc-xArray[divY1-yc]+1) |
5350 |
25 May 10 |
nicklas |
3179 |
{ |
5350 |
25 May 10 |
nicklas |
if(divWidth2>xc-xArray[divY1-yc]-divX1+1) |
5350 |
25 May 10 |
nicklas |
divWidth2=xc-xArray[divY1-yc]-divX1+1; |
5350 |
25 May 10 |
nicklas |
3182 |
} |
5350 |
25 May 10 |
nicklas |
else if(divWidth2>=divX1+divWidth2-xc-xArray[divY1-yc]+1) |
5350 |
25 May 10 |
nicklas |
divX1="X"; |
5350 |
25 May 10 |
nicklas |
3185 |
} |
5350 |
25 May 10 |
nicklas |
3186 |
} |
5350 |
25 May 10 |
nicklas |
3187 |
|
5350 |
25 May 10 |
nicklas |
if(draw4) |
5350 |
25 May 10 |
nicklas |
3189 |
{ |
5350 |
25 May 10 |
nicklas |
if(xArrayI[divY1-yc] && divX2!=null) |
5350 |
25 May 10 |
nicklas |
3191 |
{ |
5350 |
25 May 10 |
nicklas |
if(xc+xArray[divY1-yc]<=divX2+divWidth4) |
5350 |
25 May 10 |
nicklas |
3193 |
{ |
5350 |
25 May 10 |
nicklas |
if(divWidth4>divX2+divWidth4-xc-xArray[divY1-yc]) |
5350 |
25 May 10 |
nicklas |
3195 |
{ |
5350 |
25 May 10 |
nicklas |
divX2i=xc+xArray[divY1-yc]; |
5350 |
25 May 10 |
nicklas |
divWidth4i=divX2+divWidth4-xc-xArray[divY1-yc]; |
5350 |
25 May 10 |
nicklas |
3198 |
} |
5350 |
25 May 10 |
nicklas |
3199 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
divX2i="X"; |
5350 |
25 May 10 |
nicklas |
3202 |
|
5350 |
25 May 10 |
nicklas |
if(divX2<=xc-xArray[divY1-yc]+1) |
5350 |
25 May 10 |
nicklas |
3204 |
{ |
5350 |
25 May 10 |
nicklas |
if(divWidth4>xc-xArray[divY1-yc]-divX2+1) |
5350 |
25 May 10 |
nicklas |
divWidth4=xc-xArray[divY1-yc]-divX2+1; |
5350 |
25 May 10 |
nicklas |
3207 |
} |
5350 |
25 May 10 |
nicklas |
else if(divWidth4>=divX2+divWidth4-xc-xArray[divY1-yc]+1) |
5350 |
25 May 10 |
nicklas |
divX2="X"; |
5350 |
25 May 10 |
nicklas |
3210 |
} |
5350 |
25 May 10 |
nicklas |
3211 |
} |
5350 |
25 May 10 |
nicklas |
//End: Only for drawArc (not in fillArc) |
5350 |
25 May 10 |
nicklas |
3213 |
|
5350 |
25 May 10 |
nicklas |
if(divX2==null) |
5350 |
25 May 10 |
nicklas |
divX2="X"; |
5350 |
25 May 10 |
nicklas |
if(divX1==null) |
5350 |
25 May 10 |
nicklas |
divX1="X"; |
5350 |
25 May 10 |
nicklas |
3218 |
|
5350 |
25 May 10 |
nicklas |
if(divX2i==null) |
5350 |
25 May 10 |
nicklas |
divX2i="X"; |
5350 |
25 May 10 |
nicklas |
if(divX1i==null) |
5350 |
25 May 10 |
nicklas |
divX1i="X"; |
5350 |
25 May 10 |
nicklas |
3223 |
|
5350 |
25 May 10 |
nicklas |
if(isUpperHalf) |
5350 |
25 May 10 |
nicklas |
3225 |
{ |
5350 |
25 May 10 |
nicklas |
divHeight=1; |
5350 |
25 May 10 |
nicklas |
if(draw3) |
5350 |
25 May 10 |
nicklas |
3228 |
{ |
5350 |
25 May 10 |
nicklas |
if(divX2!="X") |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + divX2 + "px;top:" + divY1 + "px;width:" + divWidth3 + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
3231 |
|
5350 |
25 May 10 |
nicklas |
if(divX2i!="X") |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + divX2i + "px;top:" + divY1 + "px;width:" + divWidth3i + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
3234 |
} |
5350 |
25 May 10 |
nicklas |
3235 |
|
5350 |
25 May 10 |
nicklas |
if(draw1) |
5350 |
25 May 10 |
nicklas |
3237 |
{ |
5350 |
25 May 10 |
nicklas |
if(divX1!="X") |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + divX1 + "px;top:" + divY1 + "px;width:" + divWidth1 + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
3240 |
|
5350 |
25 May 10 |
nicklas |
if(divX1i!="X") |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + divX1i + "px;top:" + divY1 + "px;width:" + divWidth1i + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
3243 |
} |
5350 |
25 May 10 |
nicklas |
3244 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
3246 |
{ |
5350 |
25 May 10 |
nicklas |
divHeight=1; |
5350 |
25 May 10 |
nicklas |
if(draw4) |
5350 |
25 May 10 |
nicklas |
3249 |
{ |
5350 |
25 May 10 |
nicklas |
if(divX2!="X") |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + divX2 + "px;top:" + (divY2+1-divHeight) + "px;width:" + divWidth4 + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
3252 |
|
5350 |
25 May 10 |
nicklas |
if(divX2i!="X") |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + divX2i + "px;top:" + (divY2+1-divHeight) + "px;width:" + divWidth4i + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
3255 |
} |
5350 |
25 May 10 |
nicklas |
if(draw2) |
5350 |
25 May 10 |
nicklas |
3257 |
{ |
5350 |
25 May 10 |
nicklas |
if(divX1!="X") |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + divX1 + "px;top:" + (divY2+1-divHeight) + "px;width:" + divWidth2 + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
3260 |
|
5350 |
25 May 10 |
nicklas |
if(divX1i!="X") |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" + divX1i + "px;top:" + (divY2+1-divHeight) + "px;width:" + divWidth2i + "px;height:" + divHeight + "px;background-color:" + hexColor + "\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
3263 |
} |
5350 |
25 May 10 |
nicklas |
3264 |
} |
5350 |
25 May 10 |
nicklas |
3265 |
} |
5350 |
25 May 10 |
nicklas |
3266 |
} |
5350 |
25 May 10 |
nicklas |
3267 |
|
5350 |
25 May 10 |
nicklas |
//Draw polyline connecting to the specified points. |
5350 |
25 May 10 |
nicklas |
function drawPolyline(pen,points) |
5350 |
25 May 10 |
nicklas |
3270 |
{ |
5350 |
25 May 10 |
nicklas |
//Check arguments for null values |
5350 |
25 May 10 |
nicklas |
if(!pen || !points) |
5350 |
25 May 10 |
nicklas |
return false; |
5350 |
25 May 10 |
nicklas |
3274 |
|
5350 |
25 May 10 |
nicklas |
var polylineDiv=canvasDiv.appendChild(document.createElement("div")); |
5350 |
25 May 10 |
nicklas |
3276 |
|
5350 |
25 May 10 |
nicklas |
for(var i=1;i<points.length;i++) |
5350 |
25 May 10 |
nicklas |
3278 |
{ |
5350 |
25 May 10 |
nicklas |
polylineDiv.appendChild(this.drawLine(pen,points[i-1],points[i])); |
5350 |
25 May 10 |
nicklas |
3280 |
} |
5350 |
25 May 10 |
nicklas |
3281 |
|
5350 |
25 May 10 |
nicklas |
return polylineDiv; |
5350 |
25 May 10 |
nicklas |
3283 |
} |
5350 |
25 May 10 |
nicklas |
3284 |
|
5350 |
25 May 10 |
nicklas |
//Draw polygon connecting to the specified points. |
5350 |
25 May 10 |
nicklas |
function drawPolygon(pen,points) |
5350 |
25 May 10 |
nicklas |
3287 |
{ |
5350 |
25 May 10 |
nicklas |
//Check arguments for null values |
5350 |
25 May 10 |
nicklas |
if(!pen || !points) |
5350 |
25 May 10 |
nicklas |
return false; |
5350 |
25 May 10 |
nicklas |
3291 |
|
5350 |
25 May 10 |
nicklas |
var polylineDiv=canvasDiv.appendChild(document.createElement("div")); |
5350 |
25 May 10 |
nicklas |
3293 |
|
5350 |
25 May 10 |
nicklas |
var i; |
5350 |
25 May 10 |
nicklas |
for(i=1;i<points.length;i++) |
5350 |
25 May 10 |
nicklas |
3296 |
{ |
5350 |
25 May 10 |
nicklas |
polylineDiv.appendChild(this.drawLine(pen,points[i-1],points[i])); |
5350 |
25 May 10 |
nicklas |
3298 |
} |
5350 |
25 May 10 |
nicklas |
polylineDiv.appendChild(this.drawLine(pen,points[i-1],points[0])); |
5350 |
25 May 10 |
nicklas |
3300 |
} |
5350 |
25 May 10 |
nicklas |
3301 |
|
5350 |
25 May 10 |
nicklas |
//Draw polygon filled with specified color and connecting to the specified points. |
5350 |
25 May 10 |
nicklas |
function fillPolygon(color,points) |
5350 |
25 May 10 |
nicklas |
3304 |
{ |
5350 |
25 May 10 |
nicklas |
//Check arguments for null values |
5350 |
25 May 10 |
nicklas |
if(!color || !points) |
5350 |
25 May 10 |
nicklas |
return false; |
5350 |
25 May 10 |
nicklas |
3308 |
|
5350 |
25 May 10 |
nicklas |
var phPoints=new Array(); |
5350 |
25 May 10 |
nicklas |
var i; |
5350 |
25 May 10 |
nicklas |
3311 |
|
5350 |
25 May 10 |
nicklas |
for(i=0;i<points.length;i++) |
5350 |
25 May 10 |
nicklas |
3313 |
{ |
5350 |
25 May 10 |
nicklas |
phPoints[i]=logicalToPhysicalPoint(points[i]); |
5350 |
25 May 10 |
nicklas |
3315 |
} |
5350 |
25 May 10 |
nicklas |
3316 |
|
5350 |
25 May 10 |
nicklas |
var polygonDiv=canvasDiv.appendChild(document.createElement("div")); |
5350 |
25 May 10 |
nicklas |
var iHtml=new Array(); |
5350 |
25 May 10 |
nicklas |
3319 |
|
5350 |
25 May 10 |
nicklas |
var hexColor=color.getHex(); |
5350 |
25 May 10 |
nicklas |
3321 |
|
5350 |
25 May 10 |
nicklas |
var xDataArrays=new Array(); |
5350 |
25 May 10 |
nicklas |
var yMin=phPoints[0].y; |
5350 |
25 May 10 |
nicklas |
var yMax=phPoints[0].y; |
5350 |
25 May 10 |
nicklas |
3325 |
|
5350 |
25 May 10 |
nicklas |
var newPoints=new Array(); |
5350 |
25 May 10 |
nicklas |
var l,m,n; |
5350 |
25 May 10 |
nicklas |
var pointsCount; |
5350 |
25 May 10 |
nicklas |
3329 |
|
5350 |
25 May 10 |
nicklas |
pointsCount=phPoints.length; |
5350 |
25 May 10 |
nicklas |
3331 |
|
5350 |
25 May 10 |
nicklas |
//Remove duplicate consecutive points |
5350 |
25 May 10 |
nicklas |
for(i=0;i<phPoints.length;i++) |
5350 |
25 May 10 |
nicklas |
3334 |
{ |
5350 |
25 May 10 |
nicklas |
if(i!=0) |
5350 |
25 May 10 |
nicklas |
m=i-1; |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
m=pointsCount-1; |
5350 |
25 May 10 |
nicklas |
3339 |
|
5350 |
25 May 10 |
nicklas |
if(!(phPoints[m].x==phPoints[i].x && phPoints[m].y==phPoints[i].y)) |
5350 |
25 May 10 |
nicklas |
3341 |
{ |
5350 |
25 May 10 |
nicklas |
newPoints[newPoints.length]=phPoints[i]; |
5350 |
25 May 10 |
nicklas |
3343 |
} |
5350 |
25 May 10 |
nicklas |
3344 |
} |
5350 |
25 May 10 |
nicklas |
phPoints=newPoints; |
5350 |
25 May 10 |
nicklas |
newPoints=new Array(); |
5350 |
25 May 10 |
nicklas |
3347 |
|
5350 |
25 May 10 |
nicklas |
pointsCount=phPoints.length; |
5350 |
25 May 10 |
nicklas |
3349 |
|
5350 |
25 May 10 |
nicklas |
//For consecutive horizontal points |
5350 |
25 May 10 |
nicklas |
for(i=0;i<phPoints.length;i++) |
5350 |
25 May 10 |
nicklas |
3352 |
{ |
5350 |
25 May 10 |
nicklas |
if(i!=0) |
5350 |
25 May 10 |
nicklas |
m=i-1; |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
m=pointsCount-1; |
5350 |
25 May 10 |
nicklas |
3357 |
|
5350 |
25 May 10 |
nicklas |
if(i!=pointsCount-1) |
5350 |
25 May 10 |
nicklas |
n=i+1; |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
n=0; |
5350 |
25 May 10 |
nicklas |
3362 |
|
5350 |
25 May 10 |
nicklas |
if(!(phPoints[i].y==phPoints[n].y && phPoints[i].y==phPoints[m].y)) |
5350 |
25 May 10 |
nicklas |
3364 |
{ |
5350 |
25 May 10 |
nicklas |
newPoints[newPoints.length]=phPoints[i]; |
5350 |
25 May 10 |
nicklas |
3366 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
3368 |
{ |
5350 |
25 May 10 |
nicklas |
//For consecutive horizontal points, just draw horizontal lines |
5350 |
25 May 10 |
nicklas |
if(phPoints[m].x<=phPoints[i].x) |
5350 |
25 May 10 |
nicklas |
3371 |
{ |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;height:1px;overflow:hidden;left:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=phPoints[m].x; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;top:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=phPoints[i].y; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;width:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=phPoints[i].x-phPoints[m].x; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;background-color:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=hexColor; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
3381 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
3383 |
{ |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;height:1px;overflow:hidden;left:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=phPoints[i].x; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;top:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=phPoints[i].y; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;width:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=phPoints[m].x-phPoints[i].x; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;background-color:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=hexColor; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
3393 |
} |
5350 |
25 May 10 |
nicklas |
3394 |
} |
5350 |
25 May 10 |
nicklas |
3395 |
} |
5350 |
25 May 10 |
nicklas |
phPoints=newPoints; |
5350 |
25 May 10 |
nicklas |
3397 |
|
5350 |
25 May 10 |
nicklas |
for(i=1;i<phPoints.length;i++) |
5350 |
25 May 10 |
nicklas |
3399 |
{ |
5350 |
25 May 10 |
nicklas |
if(yMin>phPoints[i-1].y) |
5350 |
25 May 10 |
nicklas |
3401 |
{ |
5350 |
25 May 10 |
nicklas |
yMin=phPoints[i-1].y; |
5350 |
25 May 10 |
nicklas |
3403 |
} |
5350 |
25 May 10 |
nicklas |
if(yMax<phPoints[i-1].y) |
5350 |
25 May 10 |
nicklas |
3405 |
{ |
5350 |
25 May 10 |
nicklas |
yMax=phPoints[i-1].y; |
5350 |
25 May 10 |
nicklas |
3407 |
} |
5350 |
25 May 10 |
nicklas |
3408 |
|
5350 |
25 May 10 |
nicklas |
//Get the pixel arrays for the lines connecting polygon vertices. |
5350 |
25 May 10 |
nicklas |
xDataArrays[i-1]=getLinePixels(phPoints[i-1],phPoints[i]); |
5350 |
25 May 10 |
nicklas |
3411 |
|
5350 |
25 May 10 |
nicklas |
//For verices, keep only one point and not two overlapping points |
5350 |
25 May 10 |
nicklas |
if(i<phPoints.length-1) |
5350 |
25 May 10 |
nicklas |
3414 |
{ |
5350 |
25 May 10 |
nicklas |
if((phPoints[i-1].y<phPoints[i].y && phPoints[i].y<phPoints[i+1].y) || (phPoints[i-1].y>phPoints[i].y && phPoints[i].y>phPoints[i+1].y)) |
5350 |
25 May 10 |
nicklas |
3416 |
{ |
5350 |
25 May 10 |
nicklas |
xDataArrays[i-1][phPoints[i].y]=null; |
5350 |
25 May 10 |
nicklas |
3418 |
} |
5350 |
25 May 10 |
nicklas |
3419 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
3421 |
{ |
5350 |
25 May 10 |
nicklas |
if((phPoints[i-1].y<phPoints[i].y && phPoints[i].y<phPoints[0].y) || (phPoints[i-1].y>phPoints[i].y && phPoints[i].y>phPoints[0].y)) |
5350 |
25 May 10 |
nicklas |
3423 |
{ |
5350 |
25 May 10 |
nicklas |
xDataArrays[i-1][phPoints[i].y]=null; |
5350 |
25 May 10 |
nicklas |
3425 |
} |
5350 |
25 May 10 |
nicklas |
3426 |
} |
5350 |
25 May 10 |
nicklas |
3427 |
} |
5350 |
25 May 10 |
nicklas |
3428 |
|
5350 |
25 May 10 |
nicklas |
if(yMin>phPoints[i-1].y) |
5350 |
25 May 10 |
nicklas |
3430 |
{ |
5350 |
25 May 10 |
nicklas |
yMin=phPoints[i-1].y; |
5350 |
25 May 10 |
nicklas |
3432 |
} |
5350 |
25 May 10 |
nicklas |
if(yMax<phPoints[i-1].y) |
5350 |
25 May 10 |
nicklas |
3434 |
{ |
5350 |
25 May 10 |
nicklas |
yMax=phPoints[i-1].y; |
5350 |
25 May 10 |
nicklas |
3436 |
} |
5350 |
25 May 10 |
nicklas |
3437 |
|
5350 |
25 May 10 |
nicklas |
xDataArrays[i-1]=getLinePixels(phPoints[i-1],phPoints[0]); |
5350 |
25 May 10 |
nicklas |
if((phPoints[i-1].y<phPoints[0].y && phPoints[0].y<phPoints[1].y) || (phPoints[i-1].y>phPoints[0].y && phPoints[0].y>phPoints[1].y)) |
5350 |
25 May 10 |
nicklas |
3440 |
{ |
5350 |
25 May 10 |
nicklas |
xDataArrays[i-1][phPoints[0].y]=null; |
5350 |
25 May 10 |
nicklas |
3442 |
} |
5350 |
25 May 10 |
nicklas |
3443 |
|
5350 |
25 May 10 |
nicklas |
var y; |
5350 |
25 May 10 |
nicklas |
var divStyle=""; |
5350 |
25 May 10 |
nicklas |
var j; |
5350 |
25 May 10 |
nicklas |
pointsCount=phPoints.length; |
5350 |
25 May 10 |
nicklas |
var xDataArray; |
5350 |
25 May 10 |
nicklas |
var xMin,xMax; |
5350 |
25 May 10 |
nicklas |
var curX,curY,curWidth; |
5350 |
25 May 10 |
nicklas |
3451 |
|
5350 |
25 May 10 |
nicklas |
for(y=yMin;y<=yMax;y++) |
5350 |
25 May 10 |
nicklas |
3453 |
{ |
5350 |
25 May 10 |
nicklas |
j=0; |
5350 |
25 May 10 |
nicklas |
var allXDataArray=new Array(); |
5350 |
25 May 10 |
nicklas |
3456 |
|
5350 |
25 May 10 |
nicklas |
for(i=0;i<pointsCount;i++) |
5350 |
25 May 10 |
nicklas |
3458 |
{ |
5350 |
25 May 10 |
nicklas |
xDataArray=xDataArrays[i]; |
5350 |
25 May 10 |
nicklas |
if(i!=0) |
5350 |
25 May 10 |
nicklas |
m=i-1; |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
m=pointsCount-1; |
5350 |
25 May 10 |
nicklas |
3464 |
|
5350 |
25 May 10 |
nicklas |
if(i!=1 && i!=0) |
5350 |
25 May 10 |
nicklas |
l=i-2; |
5350 |
25 May 10 |
nicklas |
else if(i==0) |
5350 |
25 May 10 |
nicklas |
l=pointsCount-2; |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
l=pointsCount-1; |
5350 |
25 May 10 |
nicklas |
3471 |
|
5350 |
25 May 10 |
nicklas |
if(i!=pointsCount-1) |
5350 |
25 May 10 |
nicklas |
n=i+1; |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
n=0; |
5350 |
25 May 10 |
nicklas |
3476 |
|
5350 |
25 May 10 |
nicklas |
if((y==phPoints[i].y && y==phPoints[m].y && y<phPoints[l].y && y<phPoints[n].y && xDataArray[y]) || (y==phPoints[i].y && y==phPoints[m].y && y>phPoints[l].y && y>phPoints[n].y && xDataArray[y])) |
5350 |
25 May 10 |
nicklas |
3478 |
{ |
5350 |
25 May 10 |
nicklas |
allXDataArray[j]= xDataArray[y]; |
5350 |
25 May 10 |
nicklas |
j++; |
5350 |
25 May 10 |
nicklas |
3481 |
} |
5350 |
25 May 10 |
nicklas |
if(xDataArray[y]) |
5350 |
25 May 10 |
nicklas |
3483 |
{ |
5350 |
25 May 10 |
nicklas |
allXDataArray[j]= xDataArray[y]; |
5350 |
25 May 10 |
nicklas |
j++; |
5350 |
25 May 10 |
nicklas |
3486 |
} |
5350 |
25 May 10 |
nicklas |
3487 |
} |
5350 |
25 May 10 |
nicklas |
3488 |
|
5350 |
25 May 10 |
nicklas |
//Sorting based on xMin, uses sortXDataArray function |
5350 |
25 May 10 |
nicklas |
allXDataArray.sort(sortXDataArray); |
5350 |
25 May 10 |
nicklas |
3491 |
|
5350 |
25 May 10 |
nicklas |
curY=y; |
5350 |
25 May 10 |
nicklas |
for(i=0;i<allXDataArray.length;i+=2) |
5350 |
25 May 10 |
nicklas |
3494 |
{ |
5350 |
25 May 10 |
nicklas |
if(allXDataArray[i+1]) |
5350 |
25 May 10 |
nicklas |
3496 |
{ |
5350 |
25 May 10 |
nicklas |
curX=allXDataArray[i].xMin; |
5350 |
25 May 10 |
nicklas |
if(allXDataArray[i+1].xMax>allXDataArray[i].xMax) |
5350 |
25 May 10 |
nicklas |
curWidth=allXDataArray[i+1].xMax-allXDataArray[i].xMin+1; |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
curWidth=allXDataArray[i].xMax-allXDataArray[i].xMin+1; |
5350 |
25 May 10 |
nicklas |
3502 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
3504 |
{ |
5350 |
25 May 10 |
nicklas |
curX=allXDataArray[allXDataArray.length-1].xMin; |
5350 |
25 May 10 |
nicklas |
curWidth=allXDataArray[allXDataArray.length-1].xMax-allXDataArray[allXDataArray.length-1].xMin+1; |
5350 |
25 May 10 |
nicklas |
3507 |
} |
5350 |
25 May 10 |
nicklas |
3508 |
|
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;height:1px;overflow:hidden;left:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=curX; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;top:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=curY; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;width:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=curWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;background-color:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=hexColor; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
3518 |
} |
5350 |
25 May 10 |
nicklas |
3519 |
} |
5350 |
25 May 10 |
nicklas |
3520 |
|
5350 |
25 May 10 |
nicklas |
polygonDiv.innerHTML=iHtml.join(""); |
5350 |
25 May 10 |
nicklas |
return polygonDiv; |
5350 |
25 May 10 |
nicklas |
3523 |
|
5350 |
25 May 10 |
nicklas |
//Internal function: sorting based on xMin |
5350 |
25 May 10 |
nicklas |
function sortXDataArray(a,b) |
5350 |
25 May 10 |
nicklas |
3526 |
{ |
5350 |
25 May 10 |
nicklas |
return a.xMin - b.xMin; |
5350 |
25 May 10 |
nicklas |
3528 |
} |
5350 |
25 May 10 |
nicklas |
3529 |
} |
5350 |
25 May 10 |
nicklas |
3530 |
|
5350 |
25 May 10 |
nicklas |
//Draw cubic bezier curve with specified 4 points |
5350 |
25 May 10 |
nicklas |
function drawBezier(pen,points) |
5350 |
25 May 10 |
nicklas |
3533 |
{ |
5350 |
25 May 10 |
nicklas |
//Check arguments for null values |
5350 |
25 May 10 |
nicklas |
if(!pen || !points) |
5350 |
25 May 10 |
nicklas |
return false; |
5350 |
25 May 10 |
nicklas |
3537 |
|
5350 |
25 May 10 |
nicklas |
var phPoints=new Array(); |
5350 |
25 May 10 |
nicklas |
var i; |
5350 |
25 May 10 |
nicklas |
for(i=0;i<points.length;i++) |
5350 |
25 May 10 |
nicklas |
3541 |
{ |
5350 |
25 May 10 |
nicklas |
phPoints[i]=logicalToPhysicalPoint(points[i]); |
5350 |
25 May 10 |
nicklas |
3543 |
} |
5350 |
25 May 10 |
nicklas |
3544 |
|
5350 |
25 May 10 |
nicklas |
//If no of points more than 4, take only first four points. |
5350 |
25 May 10 |
nicklas |
if(phPoints.length>4) |
5350 |
25 May 10 |
nicklas |
3547 |
{ |
5350 |
25 May 10 |
nicklas |
phPoints=new Array(phPoints[0],phPoints[1],phPoints[2],phPoints[3]); |
5350 |
25 May 10 |
nicklas |
3549 |
} |
5350 |
25 May 10 |
nicklas |
else if(phPoints.length<4) |
5350 |
25 May 10 |
nicklas |
3551 |
{ |
5350 |
25 May 10 |
nicklas |
return false; |
5350 |
25 May 10 |
nicklas |
3553 |
} |
5350 |
25 May 10 |
nicklas |
3554 |
|
5350 |
25 May 10 |
nicklas |
var bezierDiv=canvasDiv.appendChild(document.createElement("div")); |
5350 |
25 May 10 |
nicklas |
var iHtml=new Array(); |
5350 |
25 May 10 |
nicklas |
3557 |
|
5350 |
25 May 10 |
nicklas |
var xMin=phPoints[0].x; |
5350 |
25 May 10 |
nicklas |
var xMax=phPoints[0].x; |
5350 |
25 May 10 |
nicklas |
3560 |
|
5350 |
25 May 10 |
nicklas |
for(i=1;i<phPoints.length;i++) |
5350 |
25 May 10 |
nicklas |
3562 |
{ |
5350 |
25 May 10 |
nicklas |
if(xMin>phPoints[i-1].x) |
5350 |
25 May 10 |
nicklas |
3564 |
{ |
5350 |
25 May 10 |
nicklas |
xMin=phPoints[i-1].x; |
5350 |
25 May 10 |
nicklas |
3566 |
} |
5350 |
25 May 10 |
nicklas |
if(xMax<phPoints[i-1].x) |
5350 |
25 May 10 |
nicklas |
3568 |
{ |
5350 |
25 May 10 |
nicklas |
xMax=phPoints[i-1].x; |
5350 |
25 May 10 |
nicklas |
3570 |
} |
5350 |
25 May 10 |
nicklas |
3571 |
} |
5350 |
25 May 10 |
nicklas |
3572 |
|
5350 |
25 May 10 |
nicklas |
var p1x,p2x,p3x,p4x,p1y,p2y,p3y,p4y; |
5350 |
25 May 10 |
nicklas |
p1x=phPoints[0].x; |
5350 |
25 May 10 |
nicklas |
p1y=phPoints[0].y; |
5350 |
25 May 10 |
nicklas |
3576 |
|
5350 |
25 May 10 |
nicklas |
p2x=phPoints[1].x; |
5350 |
25 May 10 |
nicklas |
p2y=phPoints[1].y; |
5350 |
25 May 10 |
nicklas |
3579 |
|
5350 |
25 May 10 |
nicklas |
p3x=phPoints[2].x; |
5350 |
25 May 10 |
nicklas |
p3y=phPoints[2].y; |
5350 |
25 May 10 |
nicklas |
3582 |
|
5350 |
25 May 10 |
nicklas |
p4x=phPoints[3].x; |
5350 |
25 May 10 |
nicklas |
p4y=phPoints[3].y; |
5350 |
25 May 10 |
nicklas |
3585 |
|
5350 |
25 May 10 |
nicklas |
var x,y,xB,t; |
5350 |
25 May 10 |
nicklas |
3587 |
|
5350 |
25 May 10 |
nicklas |
var xl=p1x-1; |
5350 |
25 May 10 |
nicklas |
var yl=p1y-1; |
5350 |
25 May 10 |
nicklas |
var xp,yp; |
5350 |
25 May 10 |
nicklas |
t=0; |
5350 |
25 May 10 |
nicklas |
var f=1; |
5350 |
25 May 10 |
nicklas |
var penWidth=parseInt(pen.width); |
5350 |
25 May 10 |
nicklas |
var hexColor=pen.color.getHex(); |
5350 |
25 May 10 |
nicklas |
var divWidth=penWidth; |
5350 |
25 May 10 |
nicklas |
var divHeight=penWidth; |
5350 |
25 May 10 |
nicklas |
xp=p1x; |
5350 |
25 May 10 |
nicklas |
yp=p1y; |
5350 |
25 May 10 |
nicklas |
var yStart=false; |
5350 |
25 May 10 |
nicklas |
var xStart=false; |
5350 |
25 May 10 |
nicklas |
var k=1.1; |
5350 |
25 May 10 |
nicklas |
//Array to hold all points on the bezier curve |
5350 |
25 May 10 |
nicklas |
var curvePoints=new Array(); |
5350 |
25 May 10 |
nicklas |
3604 |
|
5350 |
25 May 10 |
nicklas |
var y1,y2,x1,x2; |
5350 |
25 May 10 |
nicklas |
y1=yp; |
5350 |
25 May 10 |
nicklas |
y2=yp; |
5350 |
25 May 10 |
nicklas |
x1=xp; |
5350 |
25 May 10 |
nicklas |
x2=xp; |
5350 |
25 May 10 |
nicklas |
3610 |
|
5350 |
25 May 10 |
nicklas |
while(t<=1) |
5350 |
25 May 10 |
nicklas |
3612 |
{ |
5350 |
25 May 10 |
nicklas |
x=0; |
5350 |
25 May 10 |
nicklas |
y=0; |
5350 |
25 May 10 |
nicklas |
x=(1-t)*(1-t)*(1-t)*p1x + 3*(1-t)*(1-t)*t*p2x + 3*(1-t)*t*t*p3x + t*t*t*p4x; |
5350 |
25 May 10 |
nicklas |
y=(1-t)*(1-t)*(1-t)*p1y + 3*(1-t)*(1-t)*t*p2y + 3*(1-t)*t*t*p3y + t*t*t*p4y; |
5350 |
25 May 10 |
nicklas |
x=Math.round(x); |
5350 |
25 May 10 |
nicklas |
y=Math.round(y); |
5350 |
25 May 10 |
nicklas |
3619 |
|
5350 |
25 May 10 |
nicklas |
if(x!=xl || y!=yl) |
5350 |
25 May 10 |
nicklas |
3621 |
{ |
5350 |
25 May 10 |
nicklas |
if(x-xl>1 || y-yl>1 || xl-x>1 || yl-y>1) |
5350 |
25 May 10 |
nicklas |
3623 |
{ |
5350 |
25 May 10 |
nicklas |
t-=f; |
5350 |
25 May 10 |
nicklas |
f=f/k; |
5350 |
25 May 10 |
nicklas |
3626 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
3628 |
{ |
5350 |
25 May 10 |
nicklas |
curvePoints[curvePoints.length]=new jsPoint(x,y); |
5350 |
25 May 10 |
nicklas |
xl=x; |
5350 |
25 May 10 |
nicklas |
yl=y; |
5350 |
25 May 10 |
nicklas |
3632 |
} |
5350 |
25 May 10 |
nicklas |
3633 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
3635 |
{ |
5350 |
25 May 10 |
nicklas |
t-=f; |
5350 |
25 May 10 |
nicklas |
f=f*k; |
5350 |
25 May 10 |
nicklas |
3638 |
} |
5350 |
25 May 10 |
nicklas |
t+=f; |
5350 |
25 May 10 |
nicklas |
3640 |
} |
5350 |
25 May 10 |
nicklas |
3641 |
|
5350 |
25 May 10 |
nicklas |
var isEliminated=new Array(); |
5350 |
25 May 10 |
nicklas |
for(var i=0;i<curvePoints.length;i++) |
5350 |
25 May 10 |
nicklas |
3644 |
{ |
5350 |
25 May 10 |
nicklas |
var next=false; |
5350 |
25 May 10 |
nicklas |
x=curvePoints[i].x; |
5350 |
25 May 10 |
nicklas |
y=curvePoints[i].y; |
5350 |
25 May 10 |
nicklas |
3648 |
|
5350 |
25 May 10 |
nicklas |
//Eliminate extra points disturbing continuity/smoothness |
5350 |
25 May 10 |
nicklas |
if(i!=0 && i+1<curvePoints.length) |
5350 |
25 May 10 |
nicklas |
3651 |
{ |
5350 |
25 May 10 |
nicklas |
if(Math.abs(curvePoints[i-1].x-curvePoints[i+1].x)==1 && Math.abs(curvePoints[i-1].y-curvePoints[i+1].y)==1) |
5350 |
25 May 10 |
nicklas |
3653 |
{ |
5350 |
25 May 10 |
nicklas |
if(!isEliminated[i-1]) |
5350 |
25 May 10 |
nicklas |
3655 |
{ |
5350 |
25 May 10 |
nicklas |
next=true; |
5350 |
25 May 10 |
nicklas |
isEliminated[i]=true; |
5350 |
25 May 10 |
nicklas |
3658 |
} |
5350 |
25 May 10 |
nicklas |
3659 |
} |
5350 |
25 May 10 |
nicklas |
3660 |
} |
5350 |
25 May 10 |
nicklas |
3661 |
|
5350 |
25 May 10 |
nicklas |
//Divs optimization |
5350 |
25 May 10 |
nicklas |
if(!next) |
5350 |
25 May 10 |
nicklas |
3664 |
{ |
5350 |
25 May 10 |
nicklas |
if(y==yp && !xStart) |
5350 |
25 May 10 |
nicklas |
3666 |
{ |
5350 |
25 May 10 |
nicklas |
yStart=true; |
5350 |
25 May 10 |
nicklas |
3668 |
} |
5350 |
25 May 10 |
nicklas |
if(x==xp && !yStart) |
5350 |
25 May 10 |
nicklas |
3670 |
{ |
5350 |
25 May 10 |
nicklas |
xStart=true; |
5350 |
25 May 10 |
nicklas |
3672 |
} |
5350 |
25 May 10 |
nicklas |
3673 |
|
5350 |
25 May 10 |
nicklas |
if(x!=xp && !yStart) |
5350 |
25 May 10 |
nicklas |
3675 |
{ |
5350 |
25 May 10 |
nicklas |
if(y2==y1) |
5350 |
25 May 10 |
nicklas |
3677 |
{ |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=xp; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;top:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=y1; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;width:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;height:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;background-color:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=hexColor; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
3689 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
3691 |
{ |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=xp; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;top:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=y1; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;width:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;height:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=y2-y1+penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;background-color:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=hexColor; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
3703 |
} |
5350 |
25 May 10 |
nicklas |
3704 |
|
5350 |
25 May 10 |
nicklas |
xp=x; |
5350 |
25 May 10 |
nicklas |
yp=y; |
5350 |
25 May 10 |
nicklas |
y1=yp; |
5350 |
25 May 10 |
nicklas |
y2=yp; |
5350 |
25 May 10 |
nicklas |
3709 |
|
5350 |
25 May 10 |
nicklas |
xStart=false; |
5350 |
25 May 10 |
nicklas |
3711 |
} |
5350 |
25 May 10 |
nicklas |
3712 |
|
5350 |
25 May 10 |
nicklas |
if(y!=yp && !xStart ) |
5350 |
25 May 10 |
nicklas |
3714 |
{ |
5350 |
25 May 10 |
nicklas |
if(x2==x1) |
5350 |
25 May 10 |
nicklas |
3716 |
{ |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=x1; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;top:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=yp; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;width:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;height:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;background-color:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=hexColor; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
3728 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
3730 |
{ |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=x1; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;top:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=yp; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;width:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=x2-x1+penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;height:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;background-color:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=hexColor; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
3742 |
} |
5350 |
25 May 10 |
nicklas |
3743 |
|
5350 |
25 May 10 |
nicklas |
xp=x; |
5350 |
25 May 10 |
nicklas |
yp=y; |
5350 |
25 May 10 |
nicklas |
x1=xp; |
5350 |
25 May 10 |
nicklas |
x2=xp; |
5350 |
25 May 10 |
nicklas |
3748 |
|
5350 |
25 May 10 |
nicklas |
yStart=false; |
5350 |
25 May 10 |
nicklas |
3750 |
} |
5350 |
25 May 10 |
nicklas |
3751 |
|
5350 |
25 May 10 |
nicklas |
if(xStart && !yStart) |
5350 |
25 May 10 |
nicklas |
3753 |
{ |
5350 |
25 May 10 |
nicklas |
if(y<=y1) |
5350 |
25 May 10 |
nicklas |
y1=y; |
5350 |
25 May 10 |
nicklas |
3756 |
|
5350 |
25 May 10 |
nicklas |
if(y>y2) |
5350 |
25 May 10 |
nicklas |
y2=y; |
5350 |
25 May 10 |
nicklas |
3759 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
3761 |
{ |
5350 |
25 May 10 |
nicklas |
y1=y; |
5350 |
25 May 10 |
nicklas |
y2=y; |
5350 |
25 May 10 |
nicklas |
3764 |
} |
5350 |
25 May 10 |
nicklas |
3765 |
|
5350 |
25 May 10 |
nicklas |
if(yStart && !xStart) |
5350 |
25 May 10 |
nicklas |
3767 |
{ |
5350 |
25 May 10 |
nicklas |
if(x<=x1) |
5350 |
25 May 10 |
nicklas |
x1=x; |
5350 |
25 May 10 |
nicklas |
3770 |
|
5350 |
25 May 10 |
nicklas |
if(x>x2) |
5350 |
25 May 10 |
nicklas |
x2=x; |
5350 |
25 May 10 |
nicklas |
3773 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
3775 |
{ |
5350 |
25 May 10 |
nicklas |
x1=x; |
5350 |
25 May 10 |
nicklas |
x2=x; |
5350 |
25 May 10 |
nicklas |
3778 |
} |
5350 |
25 May 10 |
nicklas |
3779 |
|
5350 |
25 May 10 |
nicklas |
if(i==curvePoints.length-1) //last step in the loop |
5350 |
25 May 10 |
nicklas |
3781 |
{ |
5350 |
25 May 10 |
nicklas |
if(!xStart) |
5350 |
25 May 10 |
nicklas |
3783 |
{ |
5350 |
25 May 10 |
nicklas |
if(x2==x1) |
5350 |
25 May 10 |
nicklas |
3785 |
{ |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=x1; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;top:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=yp; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;width:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;height:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;background-color:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=hexColor; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
3797 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
3799 |
{ |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=x1; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;top:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=yp; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;width:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=x2-x1+penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;height:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;background-color:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=hexColor; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
3811 |
} |
5350 |
25 May 10 |
nicklas |
3812 |
} |
5350 |
25 May 10 |
nicklas |
if(!yStart) |
5350 |
25 May 10 |
nicklas |
3814 |
{ |
5350 |
25 May 10 |
nicklas |
if(y2==y1) |
5350 |
25 May 10 |
nicklas |
3816 |
{ |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=xp; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;top:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=y1; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;width:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;height:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;background-color:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=hexColor; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
3828 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
3830 |
{ |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=xp; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;top:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=y1; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;width:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=x2-x1+penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;height:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=y2-y1+penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;background-color:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=hexColor; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
3842 |
} |
5350 |
25 May 10 |
nicklas |
3843 |
} |
5350 |
25 May 10 |
nicklas |
3844 |
} |
5350 |
25 May 10 |
nicklas |
3845 |
} |
5350 |
25 May 10 |
nicklas |
3846 |
} |
5350 |
25 May 10 |
nicklas |
3847 |
|
5350 |
25 May 10 |
nicklas |
bezierDiv.innerHTML=iHtml.join(""); |
5350 |
25 May 10 |
nicklas |
return bezierDiv; |
5350 |
25 May 10 |
nicklas |
3850 |
} |
5350 |
25 May 10 |
nicklas |
3851 |
|
5350 |
25 May 10 |
nicklas |
//Draw general (poly) bezier curve with specified points |
5350 |
25 May 10 |
nicklas |
function drawPolyBezier(pen,points) |
5350 |
25 May 10 |
nicklas |
3854 |
{ |
5350 |
25 May 10 |
nicklas |
//Check arguments for null values |
5350 |
25 May 10 |
nicklas |
if(!pen || !points) |
5350 |
25 May 10 |
nicklas |
return false; |
5350 |
25 May 10 |
nicklas |
3858 |
|
5350 |
25 May 10 |
nicklas |
if(points.length<2) |
5350 |
25 May 10 |
nicklas |
3860 |
{ |
5350 |
25 May 10 |
nicklas |
return false; |
5350 |
25 May 10 |
nicklas |
3862 |
} |
5350 |
25 May 10 |
nicklas |
3863 |
|
5350 |
25 May 10 |
nicklas |
var phPoints=new Array(); |
5350 |
25 May 10 |
nicklas |
for(var i=0;i<points.length;i++) |
5350 |
25 May 10 |
nicklas |
3866 |
{ |
5350 |
25 May 10 |
nicklas |
phPoints[i]=logicalToPhysicalPoint(points[i]); |
5350 |
25 May 10 |
nicklas |
3868 |
} |
5350 |
25 May 10 |
nicklas |
3869 |
|
5350 |
25 May 10 |
nicklas |
var bezierDiv=canvasDiv.appendChild(document.createElement("div")); |
5350 |
25 May 10 |
nicklas |
var iHtml=new Array(); |
5350 |
25 May 10 |
nicklas |
3872 |
|
5350 |
25 May 10 |
nicklas |
var cfx=new Array(); |
5350 |
25 May 10 |
nicklas |
var cfy=new Array(); |
5350 |
25 May 10 |
nicklas |
3875 |
|
5350 |
25 May 10 |
nicklas |
var n=phPoints.length-1; |
5350 |
25 May 10 |
nicklas |
for(var i=0;i<=n;i++) |
5350 |
25 May 10 |
nicklas |
3878 |
{ |
5350 |
25 May 10 |
nicklas |
cfx[i]= phPoints[i].x*fact(n)/(fact(i)*fact(n-i)); |
5350 |
25 May 10 |
nicklas |
cfy[i]= phPoints[i].y*fact(n)/(fact(i)*fact(n-i)); |
5350 |
25 May 10 |
nicklas |
3881 |
} |
5350 |
25 May 10 |
nicklas |
3882 |
|
5350 |
25 May 10 |
nicklas |
var xl=phPoints[0].x-1; |
5350 |
25 May 10 |
nicklas |
var yl=phPoints[0].y-1; |
5350 |
25 May 10 |
nicklas |
var xp,yp; |
7419 |
03 Nov 17 |
nicklas |
var t=0; |
5350 |
25 May 10 |
nicklas |
var f=1; |
5350 |
25 May 10 |
nicklas |
var penWidth=parseInt(pen.width); |
5350 |
25 May 10 |
nicklas |
var hexColor=pen.color.getHex(); |
5350 |
25 May 10 |
nicklas |
var divWidth=penWidth; |
5350 |
25 May 10 |
nicklas |
var divHeight=penWidth; |
5350 |
25 May 10 |
nicklas |
xp=phPoints[0].x; |
5350 |
25 May 10 |
nicklas |
yp=phPoints[0].y; |
5350 |
25 May 10 |
nicklas |
var yStart=false; |
5350 |
25 May 10 |
nicklas |
var xStart=false; |
5350 |
25 May 10 |
nicklas |
var divCount=0; |
5350 |
25 May 10 |
nicklas |
var res; |
5350 |
25 May 10 |
nicklas |
var fct=0; |
5350 |
25 May 10 |
nicklas |
var x; |
5350 |
25 May 10 |
nicklas |
var y; |
5350 |
25 May 10 |
nicklas |
var j; |
5350 |
25 May 10 |
nicklas |
var xd,yd; |
5350 |
25 May 10 |
nicklas |
var k=1.1; |
5350 |
25 May 10 |
nicklas |
//Array to hold all points on the bezier curve |
5350 |
25 May 10 |
nicklas |
var curvePoints=new Array(); |
5350 |
25 May 10 |
nicklas |
3906 |
|
5350 |
25 May 10 |
nicklas |
var y1,y2,x1,x2; |
5350 |
25 May 10 |
nicklas |
y1=yp; |
5350 |
25 May 10 |
nicklas |
y2=yp; |
5350 |
25 May 10 |
nicklas |
x1=xp; |
5350 |
25 May 10 |
nicklas |
x2=xp; |
5350 |
25 May 10 |
nicklas |
3912 |
|
5350 |
25 May 10 |
nicklas |
while(t<=1) |
5350 |
25 May 10 |
nicklas |
3914 |
{ |
5350 |
25 May 10 |
nicklas |
x=0; |
5350 |
25 May 10 |
nicklas |
y=0; |
5350 |
25 May 10 |
nicklas |
3917 |
|
5350 |
25 May 10 |
nicklas |
for(var i=0;i<=n;i++) |
5350 |
25 May 10 |
nicklas |
3919 |
{ |
5350 |
25 May 10 |
nicklas |
fct=Math.pow(1-t,n-i)*Math.pow(t,i); |
5350 |
25 May 10 |
nicklas |
x= x + cfx[i]*fct; |
5350 |
25 May 10 |
nicklas |
y= y + cfy[i]*fct; |
5350 |
25 May 10 |
nicklas |
3923 |
} |
5350 |
25 May 10 |
nicklas |
var xd; |
5350 |
25 May 10 |
nicklas |
var yd; |
5350 |
25 May 10 |
nicklas |
xd=x; |
5350 |
25 May 10 |
nicklas |
yd=y; |
5350 |
25 May 10 |
nicklas |
x=Math.round(x); |
5350 |
25 May 10 |
nicklas |
y=Math.round(y); |
5350 |
25 May 10 |
nicklas |
3930 |
|
5350 |
25 May 10 |
nicklas |
if(x!=xl || y!=yl) |
5350 |
25 May 10 |
nicklas |
3932 |
{ |
5350 |
25 May 10 |
nicklas |
if(x-xl >1 || y-yl>1 || xl-x>1 || yl-y>1) |
5350 |
25 May 10 |
nicklas |
3934 |
{ |
5350 |
25 May 10 |
nicklas |
t-=f; |
5350 |
25 May 10 |
nicklas |
f=f/k; |
5350 |
25 May 10 |
nicklas |
3937 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
3939 |
{ |
5350 |
25 May 10 |
nicklas |
curvePoints[curvePoints.length]=new jsPoint(x,y); |
5350 |
25 May 10 |
nicklas |
xl=x; |
5350 |
25 May 10 |
nicklas |
yl=y; |
5350 |
25 May 10 |
nicklas |
3943 |
} |
5350 |
25 May 10 |
nicklas |
3944 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
3946 |
{ |
5350 |
25 May 10 |
nicklas |
t-=f; |
5350 |
25 May 10 |
nicklas |
f=f*k; |
5350 |
25 May 10 |
nicklas |
3949 |
} |
5350 |
25 May 10 |
nicklas |
t+=f; |
5350 |
25 May 10 |
nicklas |
3951 |
} |
5350 |
25 May 10 |
nicklas |
3952 |
|
5350 |
25 May 10 |
nicklas |
var isEliminated=new Array(); |
5350 |
25 May 10 |
nicklas |
for(var i=0;i<curvePoints.length;i++) |
5350 |
25 May 10 |
nicklas |
3955 |
{ |
5350 |
25 May 10 |
nicklas |
var next=false; |
5350 |
25 May 10 |
nicklas |
x=curvePoints[i].x; |
5350 |
25 May 10 |
nicklas |
y=curvePoints[i].y; |
5350 |
25 May 10 |
nicklas |
3959 |
|
5350 |
25 May 10 |
nicklas |
//Eliminate extra points disturbing continuity/smoothness |
5350 |
25 May 10 |
nicklas |
if(i!=0 && i+1<curvePoints.length) |
5350 |
25 May 10 |
nicklas |
3962 |
{ |
5350 |
25 May 10 |
nicklas |
if(Math.abs(curvePoints[i-1].x-curvePoints[i+1].x)==1 && Math.abs(curvePoints[i-1].y-curvePoints[i+1].y)==1) |
5350 |
25 May 10 |
nicklas |
3964 |
{ |
5350 |
25 May 10 |
nicklas |
if(!isEliminated[i-1]) |
5350 |
25 May 10 |
nicklas |
3966 |
{ |
5350 |
25 May 10 |
nicklas |
next=true; |
5350 |
25 May 10 |
nicklas |
isEliminated[i]=true; |
5350 |
25 May 10 |
nicklas |
3969 |
} |
5350 |
25 May 10 |
nicklas |
3970 |
} |
5350 |
25 May 10 |
nicklas |
3971 |
} |
5350 |
25 May 10 |
nicklas |
3972 |
|
5350 |
25 May 10 |
nicklas |
//Divs optimization |
5350 |
25 May 10 |
nicklas |
if(!next) |
5350 |
25 May 10 |
nicklas |
3975 |
{ |
5350 |
25 May 10 |
nicklas |
if(y==yp && !xStart) |
5350 |
25 May 10 |
nicklas |
3977 |
{ |
5350 |
25 May 10 |
nicklas |
yStart=true; |
5350 |
25 May 10 |
nicklas |
3979 |
} |
5350 |
25 May 10 |
nicklas |
if(x==xp && !yStart) |
5350 |
25 May 10 |
nicklas |
3981 |
{ |
5350 |
25 May 10 |
nicklas |
xStart=true; |
5350 |
25 May 10 |
nicklas |
3983 |
} |
5350 |
25 May 10 |
nicklas |
3984 |
|
5350 |
25 May 10 |
nicklas |
if(x!=xp && !yStart) |
5350 |
25 May 10 |
nicklas |
3986 |
{ |
5350 |
25 May 10 |
nicklas |
if(y2==y1) |
5350 |
25 May 10 |
nicklas |
3988 |
{ |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=xp; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;top:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=y1; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;width:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;height:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;background-color:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=hexColor; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
4000 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
4002 |
{ |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=xp; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;top:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=y1; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;width:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;height:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=y2-y1+penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;background-color:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=hexColor; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
4014 |
} |
5350 |
25 May 10 |
nicklas |
4015 |
|
5350 |
25 May 10 |
nicklas |
xp=x; |
5350 |
25 May 10 |
nicklas |
yp=y; |
5350 |
25 May 10 |
nicklas |
y1=yp; |
5350 |
25 May 10 |
nicklas |
y2=yp; |
5350 |
25 May 10 |
nicklas |
4020 |
|
5350 |
25 May 10 |
nicklas |
xStart=false; |
5350 |
25 May 10 |
nicklas |
4022 |
} |
5350 |
25 May 10 |
nicklas |
4023 |
|
5350 |
25 May 10 |
nicklas |
if(y!=yp && !xStart ) |
5350 |
25 May 10 |
nicklas |
4025 |
{ |
5350 |
25 May 10 |
nicklas |
if(x2==x1) |
5350 |
25 May 10 |
nicklas |
4027 |
{ |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=x1; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;top:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=yp; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;width:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;height:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;background-color:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=hexColor; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
4039 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
4041 |
{ |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=x1; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;top:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=yp; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;width:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=x2-x1+penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;height:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;background-color:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=hexColor; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
4053 |
} |
5350 |
25 May 10 |
nicklas |
4054 |
|
5350 |
25 May 10 |
nicklas |
xp=x; |
5350 |
25 May 10 |
nicklas |
yp=y; |
5350 |
25 May 10 |
nicklas |
x1=xp; |
5350 |
25 May 10 |
nicklas |
x2=xp; |
5350 |
25 May 10 |
nicklas |
4059 |
|
5350 |
25 May 10 |
nicklas |
yStart=false; |
5350 |
25 May 10 |
nicklas |
4061 |
} |
5350 |
25 May 10 |
nicklas |
4062 |
|
5350 |
25 May 10 |
nicklas |
if(xStart && !yStart) |
5350 |
25 May 10 |
nicklas |
4064 |
{ |
5350 |
25 May 10 |
nicklas |
if(y<=y1) |
5350 |
25 May 10 |
nicklas |
y1=y; |
5350 |
25 May 10 |
nicklas |
4067 |
|
5350 |
25 May 10 |
nicklas |
if(y>y2) |
5350 |
25 May 10 |
nicklas |
y2=y; |
5350 |
25 May 10 |
nicklas |
4070 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
4072 |
{ |
5350 |
25 May 10 |
nicklas |
y1=y; |
5350 |
25 May 10 |
nicklas |
y2=y; |
5350 |
25 May 10 |
nicklas |
4075 |
} |
5350 |
25 May 10 |
nicklas |
4076 |
|
5350 |
25 May 10 |
nicklas |
if(yStart && !xStart) |
5350 |
25 May 10 |
nicklas |
4078 |
{ |
5350 |
25 May 10 |
nicklas |
if(x<=x1) |
5350 |
25 May 10 |
nicklas |
x1=x; |
5350 |
25 May 10 |
nicklas |
4081 |
|
5350 |
25 May 10 |
nicklas |
if(x>x2) |
5350 |
25 May 10 |
nicklas |
x2=x; |
5350 |
25 May 10 |
nicklas |
4084 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
4086 |
{ |
5350 |
25 May 10 |
nicklas |
x1=x; |
5350 |
25 May 10 |
nicklas |
x2=x; |
5350 |
25 May 10 |
nicklas |
4089 |
} |
5350 |
25 May 10 |
nicklas |
4090 |
|
5350 |
25 May 10 |
nicklas |
if(i==curvePoints.length-1) //last step in the loop |
5350 |
25 May 10 |
nicklas |
4092 |
{ |
5350 |
25 May 10 |
nicklas |
if(!xStart) |
5350 |
25 May 10 |
nicklas |
4094 |
{ |
5350 |
25 May 10 |
nicklas |
if(x2==x1) |
5350 |
25 May 10 |
nicklas |
4096 |
{ |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=x1; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;top:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=yp; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;width:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;height:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;background-color:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=hexColor; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
4108 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
4110 |
{ |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=x1; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;top:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=yp; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;width:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=x2-x1+penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;height:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;background-color:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=hexColor; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
4122 |
} |
5350 |
25 May 10 |
nicklas |
4123 |
} |
5350 |
25 May 10 |
nicklas |
if(!yStart) |
5350 |
25 May 10 |
nicklas |
4125 |
{ |
5350 |
25 May 10 |
nicklas |
if(y2==y1) |
5350 |
25 May 10 |
nicklas |
4127 |
{ |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=xp; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;top:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=y1; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;width:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;height:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;background-color:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=hexColor; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
4139 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
4141 |
{ |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=xp; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;top:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=y1; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;width:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=x2-x1+penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;height:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=y2-y1+penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;background-color:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=hexColor; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
4153 |
} |
5350 |
25 May 10 |
nicklas |
4154 |
} |
5350 |
25 May 10 |
nicklas |
4155 |
} |
5350 |
25 May 10 |
nicklas |
4156 |
} |
5350 |
25 May 10 |
nicklas |
4157 |
} |
5350 |
25 May 10 |
nicklas |
4158 |
|
5350 |
25 May 10 |
nicklas |
bezierDiv.innerHTML=iHtml.join(""); |
5350 |
25 May 10 |
nicklas |
return bezierDiv; |
5350 |
25 May 10 |
nicklas |
4161 |
|
5350 |
25 May 10 |
nicklas |
//Internal factorial function |
5350 |
25 May 10 |
nicklas |
function fact(n) |
5350 |
25 May 10 |
nicklas |
4164 |
{ |
5350 |
25 May 10 |
nicklas |
var res = 1; |
5350 |
25 May 10 |
nicklas |
for(var i=1;i<= n;i++) |
5350 |
25 May 10 |
nicklas |
4167 |
{ |
5350 |
25 May 10 |
nicklas |
res =res * i; |
5350 |
25 May 10 |
nicklas |
4169 |
} |
5350 |
25 May 10 |
nicklas |
return res; |
5350 |
25 May 10 |
nicklas |
4171 |
} |
5350 |
25 May 10 |
nicklas |
4172 |
} |
5350 |
25 May 10 |
nicklas |
4173 |
|
5350 |
25 May 10 |
nicklas |
//Draw closed curve passing through the give points with specified tension |
5350 |
25 May 10 |
nicklas |
//This method just calls drawCurve method with parameter isClosed=true |
5350 |
25 May 10 |
nicklas |
function drawClosedCurve(pen,points,tension) |
5350 |
25 May 10 |
nicklas |
4177 |
{ |
5350 |
25 May 10 |
nicklas |
return this.drawCurve(pen,points,tension,true); |
5350 |
25 May 10 |
nicklas |
4179 |
} |
5350 |
25 May 10 |
nicklas |
4180 |
|
5350 |
25 May 10 |
nicklas |
//Draw curve passing through the give points with specified tension |
5350 |
25 May 10 |
nicklas |
function drawCurve(pen,points,tension,isClosed) |
5350 |
25 May 10 |
nicklas |
4183 |
{ |
5350 |
25 May 10 |
nicklas |
if(!pen || !points) |
5350 |
25 May 10 |
nicklas |
return false; |
5350 |
25 May 10 |
nicklas |
4186 |
|
5350 |
25 May 10 |
nicklas |
if(!tension) |
5350 |
25 May 10 |
nicklas |
4188 |
{ |
5350 |
25 May 10 |
nicklas |
tension=0; |
5350 |
25 May 10 |
nicklas |
4190 |
} |
5350 |
25 May 10 |
nicklas |
if(!isClosed) |
5350 |
25 May 10 |
nicklas |
4192 |
{ |
5350 |
25 May 10 |
nicklas |
isClosed=false; |
5350 |
25 May 10 |
nicklas |
4194 |
} |
5350 |
25 May 10 |
nicklas |
4195 |
|
5350 |
25 May 10 |
nicklas |
var phPoints=new Array(); |
5350 |
25 May 10 |
nicklas |
for(var i=0;i<points.length;i++) |
5350 |
25 May 10 |
nicklas |
4198 |
{ |
5350 |
25 May 10 |
nicklas |
phPoints[i]=logicalToPhysicalPoint(points[i]); |
5350 |
25 May 10 |
nicklas |
4200 |
} |
5350 |
25 May 10 |
nicklas |
4201 |
|
5350 |
25 May 10 |
nicklas |
var newPoints=new Array(); |
5350 |
25 May 10 |
nicklas |
4203 |
|
5350 |
25 May 10 |
nicklas |
//Remove duplicate consecutive points (ToDo: neccessity of this step is to be confirmed) |
5350 |
25 May 10 |
nicklas |
if(!isClosed || !(phPoints[0].x==phPoints[phPoints.length-1].x && phPoints[0].y==phPoints[phPoints.length-1].y)) |
5350 |
25 May 10 |
nicklas |
4206 |
{ |
5350 |
25 May 10 |
nicklas |
newPoints[newPoints.length]=phPoints[0]; |
5350 |
25 May 10 |
nicklas |
4208 |
} |
5350 |
25 May 10 |
nicklas |
4209 |
|
5350 |
25 May 10 |
nicklas |
for(var i=1;i<phPoints.length;i++) |
5350 |
25 May 10 |
nicklas |
4211 |
{ |
5350 |
25 May 10 |
nicklas |
if(!(phPoints[i].x==phPoints[i-1].x && phPoints[i].y==phPoints[i-1].y)) |
5350 |
25 May 10 |
nicklas |
4213 |
{ |
5350 |
25 May 10 |
nicklas |
newPoints[newPoints.length]=phPoints[i]; |
5350 |
25 May 10 |
nicklas |
4215 |
} |
5350 |
25 May 10 |
nicklas |
4216 |
} |
5350 |
25 May 10 |
nicklas |
phPoints=newPoints; |
5350 |
25 May 10 |
nicklas |
4218 |
|
5350 |
25 May 10 |
nicklas |
if(phPoints.length<2) |
5350 |
25 May 10 |
nicklas |
4220 |
{ |
5350 |
25 May 10 |
nicklas |
return false; |
5350 |
25 May 10 |
nicklas |
4222 |
} |
5350 |
25 May 10 |
nicklas |
else if(phPoints.length==2) |
5350 |
25 May 10 |
nicklas |
4224 |
{ |
5350 |
25 May 10 |
nicklas |
//For 2 points just draw a line connecting them. |
5350 |
25 May 10 |
nicklas |
return this.drawLine(pen,phPoints[0],phPoints[1],"physical"); |
5350 |
25 May 10 |
nicklas |
4227 |
} |
5350 |
25 May 10 |
nicklas |
4228 |
|
5350 |
25 May 10 |
nicklas |
var curveDiv=canvasDiv.appendChild(document.createElement("div")); |
5350 |
25 May 10 |
nicklas |
var iHtml=new Array(); |
5350 |
25 May 10 |
nicklas |
//Array to hold points on the curve |
5350 |
25 May 10 |
nicklas |
var curvePoints=new Array(); |
5350 |
25 May 10 |
nicklas |
4233 |
|
5350 |
25 May 10 |
nicklas |
var n=phPoints.length-1; |
5350 |
25 May 10 |
nicklas |
//Call drawCurveSeg method in loop to get points in curvePoints |
5350 |
25 May 10 |
nicklas |
//array for segment (connecting 2 points) of the curve. |
5350 |
25 May 10 |
nicklas |
if(!isClosed) //for open curve |
5350 |
25 May 10 |
nicklas |
4238 |
{ |
5350 |
25 May 10 |
nicklas |
for(var i=0;i<=n-1;i++) |
5350 |
25 May 10 |
nicklas |
4240 |
{ |
5350 |
25 May 10 |
nicklas |
if(i==0) |
5350 |
25 May 10 |
nicklas |
4242 |
{ |
5350 |
25 May 10 |
nicklas |
drawCurveSeg(new Array(phPoints[0],phPoints[0],phPoints[1],phPoints[2]),tension,curvePoints); |
5350 |
25 May 10 |
nicklas |
4244 |
} |
5350 |
25 May 10 |
nicklas |
else if(i==n-1) |
5350 |
25 May 10 |
nicklas |
4246 |
{ |
5350 |
25 May 10 |
nicklas |
drawCurveSeg(new Array(phPoints[n-2],phPoints[n-1],phPoints[n],phPoints[n]),tension,curvePoints); |
5350 |
25 May 10 |
nicklas |
4248 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
4250 |
{ |
5350 |
25 May 10 |
nicklas |
drawCurveSeg(new Array(phPoints[i-1],phPoints[i],phPoints[i+1],phPoints[i+2]),tension,curvePoints); |
5350 |
25 May 10 |
nicklas |
4252 |
} |
5350 |
25 May 10 |
nicklas |
4253 |
} |
5350 |
25 May 10 |
nicklas |
//Actual drawing using points data in curvePoints array |
5350 |
25 May 10 |
nicklas |
drawAllCurvePoints(pen,curvePoints,iHtml); |
5350 |
25 May 10 |
nicklas |
4256 |
} |
5350 |
25 May 10 |
nicklas |
else //for closed curve |
5350 |
25 May 10 |
nicklas |
4258 |
{ |
5350 |
25 May 10 |
nicklas |
for(var i=0;i<=n-1;i++) |
5350 |
25 May 10 |
nicklas |
4260 |
{ |
5350 |
25 May 10 |
nicklas |
if(i==0) |
5350 |
25 May 10 |
nicklas |
4262 |
{ |
5350 |
25 May 10 |
nicklas |
drawCurveSeg(new Array(phPoints[n],phPoints[0],phPoints[1],phPoints[2]),tension,curvePoints); |
5350 |
25 May 10 |
nicklas |
4264 |
} |
5350 |
25 May 10 |
nicklas |
else if(i==n-1) |
5350 |
25 May 10 |
nicklas |
4266 |
{ |
5350 |
25 May 10 |
nicklas |
drawCurveSeg(new Array(phPoints[n-2],phPoints[n-1],phPoints[n],phPoints[0]),tension,curvePoints); |
5350 |
25 May 10 |
nicklas |
4268 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
4270 |
{ |
5350 |
25 May 10 |
nicklas |
drawCurveSeg(new Array(phPoints[i-1],phPoints[i],phPoints[i+1],phPoints[i+2]),tension,curvePoints); |
5350 |
25 May 10 |
nicklas |
4272 |
} |
5350 |
25 May 10 |
nicklas |
4273 |
} |
5350 |
25 May 10 |
nicklas |
drawCurveSeg(new Array(phPoints[n-1],phPoints[n],phPoints[0],phPoints[1]),tension,curvePoints); |
5350 |
25 May 10 |
nicklas |
//Actual drawing using points data in curvePoints array |
5350 |
25 May 10 |
nicklas |
drawAllCurvePoints(pen,curvePoints,iHtml); |
5350 |
25 May 10 |
nicklas |
4277 |
} |
5350 |
25 May 10 |
nicklas |
4278 |
|
5350 |
25 May 10 |
nicklas |
curveDiv.innerHTML=iHtml.join(""); |
5350 |
25 May 10 |
nicklas |
return curveDiv; |
5350 |
25 May 10 |
nicklas |
4281 |
} |
5350 |
25 May 10 |
nicklas |
4282 |
|
5350 |
25 May 10 |
nicklas |
//Private function used by drawCurve method to get curve points |
5350 |
25 May 10 |
nicklas |
//(in curvePoints array) for a single curve segment (connecting 2 points) |
5350 |
25 May 10 |
nicklas |
function drawCurveSeg(segPoints,tension,curvePoints) |
5350 |
25 May 10 |
nicklas |
4286 |
{ |
5350 |
25 May 10 |
nicklas |
var x=0; |
5350 |
25 May 10 |
nicklas |
var y=0; |
5350 |
25 May 10 |
nicklas |
var xl=segPoints[1].x-1; |
5350 |
25 May 10 |
nicklas |
var yl=segPoints[1].y-1; |
5350 |
25 May 10 |
nicklas |
4291 |
|
5350 |
25 May 10 |
nicklas |
var t=0; |
5350 |
25 May 10 |
nicklas |
var f=1; |
5350 |
25 May 10 |
nicklas |
var k=1.1; |
5350 |
25 May 10 |
nicklas |
4295 |
|
5350 |
25 May 10 |
nicklas |
var m1x=(1-tension)*(segPoints[2].x-segPoints[0].x)/2; |
5350 |
25 May 10 |
nicklas |
var m2x=(1-tension)*(segPoints[3].x-segPoints[1].x)/2; |
5350 |
25 May 10 |
nicklas |
4298 |
|
5350 |
25 May 10 |
nicklas |
var m1y=(1-tension)*(segPoints[2].y-segPoints[0].y)/2; |
5350 |
25 May 10 |
nicklas |
var m2y=(1-tension)*(segPoints[3].y-segPoints[1].y)/2; |
5350 |
25 May 10 |
nicklas |
4301 |
|
5350 |
25 May 10 |
nicklas |
while(t<=1) |
5350 |
25 May 10 |
nicklas |
4303 |
{ |
5350 |
25 May 10 |
nicklas |
x=0; |
5350 |
25 May 10 |
nicklas |
y=0; |
5350 |
25 May 10 |
nicklas |
4306 |
|
5350 |
25 May 10 |
nicklas |
x= (2*t*t*t-3*t*t+1)*segPoints[1].x + (t*t*t-2*t*t+t)*m1x + (-2*t*t*t+3*t*t)*segPoints[2].x + (t*t*t-t*t)*m2x; |
5350 |
25 May 10 |
nicklas |
y= (2*t*t*t-3*t*t+1)*segPoints[1].y + (t*t*t-2*t*t+t)*m1y + (-2*t*t*t+3*t*t)*segPoints[2].y + (t*t*t-t*t)*m2y; |
5350 |
25 May 10 |
nicklas |
4309 |
|
5350 |
25 May 10 |
nicklas |
x=Math.round(x); |
5350 |
25 May 10 |
nicklas |
y=Math.round(y); |
5350 |
25 May 10 |
nicklas |
4312 |
|
5350 |
25 May 10 |
nicklas |
if(x!=xl || y!=yl) |
5350 |
25 May 10 |
nicklas |
4314 |
{ |
5350 |
25 May 10 |
nicklas |
if(x-xl>1 || y-yl>1 || xl-x>1 || yl-y>1) |
5350 |
25 May 10 |
nicklas |
4316 |
{ |
5350 |
25 May 10 |
nicklas |
t-=f; |
5350 |
25 May 10 |
nicklas |
f=f/k; |
5350 |
25 May 10 |
nicklas |
4319 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
4321 |
{ |
5350 |
25 May 10 |
nicklas |
curvePoints[curvePoints.length]=new jsPoint(x,y); |
5350 |
25 May 10 |
nicklas |
xl=x; |
5350 |
25 May 10 |
nicklas |
yl=y; |
5350 |
25 May 10 |
nicklas |
if(t+f>1) |
5350 |
25 May 10 |
nicklas |
t=1-f; |
5350 |
25 May 10 |
nicklas |
4327 |
} |
5350 |
25 May 10 |
nicklas |
4328 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
4330 |
{ |
5350 |
25 May 10 |
nicklas |
f=f*k; |
5350 |
25 May 10 |
nicklas |
4332 |
} |
5350 |
25 May 10 |
nicklas |
t+=f; |
5350 |
25 May 10 |
nicklas |
4334 |
} |
5350 |
25 May 10 |
nicklas |
4335 |
} |
5350 |
25 May 10 |
nicklas |
4336 |
|
5350 |
25 May 10 |
nicklas |
//Private function used by drawCurve method to draw actual curve |
5350 |
25 May 10 |
nicklas |
//using and processing points data in curvePoints array |
5350 |
25 May 10 |
nicklas |
function drawAllCurvePoints(pen,curvePoints,iHtml) |
5350 |
25 May 10 |
nicklas |
4340 |
{ |
5350 |
25 May 10 |
nicklas |
var xp=curvePoints[0].x; |
5350 |
25 May 10 |
nicklas |
var yp=curvePoints[0].y; |
5350 |
25 May 10 |
nicklas |
4343 |
|
5350 |
25 May 10 |
nicklas |
var yStart=false; |
5350 |
25 May 10 |
nicklas |
var xStart=false; |
5350 |
25 May 10 |
nicklas |
4346 |
|
5350 |
25 May 10 |
nicklas |
var x1,x2,y1,y2; |
5350 |
25 May 10 |
nicklas |
x1=xp; |
5350 |
25 May 10 |
nicklas |
x2=xp; |
5350 |
25 May 10 |
nicklas |
y1=yp; |
5350 |
25 May 10 |
nicklas |
y2=yp; |
5350 |
25 May 10 |
nicklas |
4352 |
|
5350 |
25 May 10 |
nicklas |
4353 |
|
5350 |
25 May 10 |
nicklas |
var penWidth=parseInt(pen.width); |
5350 |
25 May 10 |
nicklas |
var hexColor=pen.color.getHex(); |
5350 |
25 May 10 |
nicklas |
var divWidth=penWidth; |
5350 |
25 May 10 |
nicklas |
var divHeight=penWidth; |
5350 |
25 May 10 |
nicklas |
4358 |
|
5350 |
25 May 10 |
nicklas |
var isEliminated=new Array(); |
5350 |
25 May 10 |
nicklas |
for(var i=0;i<curvePoints.length;i++) |
5350 |
25 May 10 |
nicklas |
4361 |
{ |
5350 |
25 May 10 |
nicklas |
var next=false; |
7419 |
03 Nov 17 |
nicklas |
var x=curvePoints[i].x; |
7419 |
03 Nov 17 |
nicklas |
var y=curvePoints[i].y; |
5350 |
25 May 10 |
nicklas |
4365 |
|
5350 |
25 May 10 |
nicklas |
//Eliminate extra points disturbing continuity/smoothness |
5350 |
25 May 10 |
nicklas |
if(i!=0 && i+1<curvePoints.length) |
5350 |
25 May 10 |
nicklas |
4368 |
{ |
5350 |
25 May 10 |
nicklas |
if(Math.abs(curvePoints[i-1].x-curvePoints[i+1].x)==1 && Math.abs(curvePoints[i-1].y-curvePoints[i+1].y)==1) |
5350 |
25 May 10 |
nicklas |
4370 |
{ |
5350 |
25 May 10 |
nicklas |
if(!isEliminated[i-1]) |
5350 |
25 May 10 |
nicklas |
4372 |
{ |
5350 |
25 May 10 |
nicklas |
next=true; |
5350 |
25 May 10 |
nicklas |
isEliminated[i]=true; |
5350 |
25 May 10 |
nicklas |
4375 |
} |
5350 |
25 May 10 |
nicklas |
4376 |
} |
5350 |
25 May 10 |
nicklas |
4377 |
} |
5350 |
25 May 10 |
nicklas |
4378 |
|
5350 |
25 May 10 |
nicklas |
//Divs optimization |
5350 |
25 May 10 |
nicklas |
if(!next) |
5350 |
25 May 10 |
nicklas |
4381 |
{ |
5350 |
25 May 10 |
nicklas |
if(y==yp && !xStart) |
5350 |
25 May 10 |
nicklas |
4383 |
{ |
5350 |
25 May 10 |
nicklas |
yStart=true; |
5350 |
25 May 10 |
nicklas |
4385 |
} |
5350 |
25 May 10 |
nicklas |
if(x==xp && !yStart) |
5350 |
25 May 10 |
nicklas |
4387 |
{ |
5350 |
25 May 10 |
nicklas |
xStart=true; |
5350 |
25 May 10 |
nicklas |
4389 |
} |
5350 |
25 May 10 |
nicklas |
4390 |
|
5350 |
25 May 10 |
nicklas |
if(x!=xp && !yStart) |
5350 |
25 May 10 |
nicklas |
4392 |
{ |
5350 |
25 May 10 |
nicklas |
if(y2==y1) |
5350 |
25 May 10 |
nicklas |
4394 |
{ |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:" |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=xp; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;top:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=y1; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;width:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;height:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;background-color:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=hexColor; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
4406 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
4408 |
{ |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=xp; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;top:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=y1; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;width:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;height:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=y2-y1+penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;background-color:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=hexColor; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
4420 |
} |
5350 |
25 May 10 |
nicklas |
4421 |
|
5350 |
25 May 10 |
nicklas |
xp=x; |
5350 |
25 May 10 |
nicklas |
yp=y; |
5350 |
25 May 10 |
nicklas |
y1=yp; |
5350 |
25 May 10 |
nicklas |
y2=yp; |
5350 |
25 May 10 |
nicklas |
4426 |
|
5350 |
25 May 10 |
nicklas |
xStart=false; |
5350 |
25 May 10 |
nicklas |
4428 |
} |
5350 |
25 May 10 |
nicklas |
4429 |
|
5350 |
25 May 10 |
nicklas |
if(y!=yp && !xStart ) |
5350 |
25 May 10 |
nicklas |
4431 |
{ |
5350 |
25 May 10 |
nicklas |
if(x2==x1) |
5350 |
25 May 10 |
nicklas |
4433 |
{ |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=x1; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;top:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=yp; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;width:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;height:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;background-color:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=hexColor; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
4445 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
4447 |
{ |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=x1; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;top:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=yp; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;width:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=x2-x1+penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;height:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;background-color:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=hexColor; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
4459 |
} |
5350 |
25 May 10 |
nicklas |
xp=x; |
5350 |
25 May 10 |
nicklas |
yp=y; |
5350 |
25 May 10 |
nicklas |
x1=xp; |
5350 |
25 May 10 |
nicklas |
x2=xp; |
5350 |
25 May 10 |
nicklas |
4464 |
|
5350 |
25 May 10 |
nicklas |
yStart=false; |
5350 |
25 May 10 |
nicklas |
4466 |
} |
5350 |
25 May 10 |
nicklas |
4467 |
|
5350 |
25 May 10 |
nicklas |
if(xStart && !yStart) |
5350 |
25 May 10 |
nicklas |
4469 |
{ |
5350 |
25 May 10 |
nicklas |
if(y<=y1) |
5350 |
25 May 10 |
nicklas |
y1=y; |
5350 |
25 May 10 |
nicklas |
4472 |
|
5350 |
25 May 10 |
nicklas |
if(y>y2) |
5350 |
25 May 10 |
nicklas |
y2=y; |
5350 |
25 May 10 |
nicklas |
4475 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
4477 |
{ |
5350 |
25 May 10 |
nicklas |
y1=y; |
5350 |
25 May 10 |
nicklas |
y2=y; |
5350 |
25 May 10 |
nicklas |
4480 |
} |
5350 |
25 May 10 |
nicklas |
4481 |
|
5350 |
25 May 10 |
nicklas |
if(yStart && !xStart) |
5350 |
25 May 10 |
nicklas |
4483 |
{ |
5350 |
25 May 10 |
nicklas |
if(x<=x1) |
5350 |
25 May 10 |
nicklas |
x1=x; |
5350 |
25 May 10 |
nicklas |
4486 |
|
5350 |
25 May 10 |
nicklas |
if(x>x2) |
5350 |
25 May 10 |
nicklas |
x2=x; |
5350 |
25 May 10 |
nicklas |
4489 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
4491 |
{ |
5350 |
25 May 10 |
nicklas |
x1=x; |
5350 |
25 May 10 |
nicklas |
x2=x; |
5350 |
25 May 10 |
nicklas |
4494 |
} |
5350 |
25 May 10 |
nicklas |
4495 |
|
5350 |
25 May 10 |
nicklas |
if(i==curvePoints.length-1) //last step in the loop |
5350 |
25 May 10 |
nicklas |
4497 |
{ |
5350 |
25 May 10 |
nicklas |
if(!xStart) |
5350 |
25 May 10 |
nicklas |
4499 |
{ |
5350 |
25 May 10 |
nicklas |
if(x2==x1) |
5350 |
25 May 10 |
nicklas |
4501 |
{ |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=x1; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;top:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=yp; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;width:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;height:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;background-color:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=hexColor; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
4513 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
4515 |
{ |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=x1; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;top:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=yp; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;width:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=x2-x1+penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;height:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;background-color:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=hexColor; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
4527 |
} |
5350 |
25 May 10 |
nicklas |
4528 |
} |
5350 |
25 May 10 |
nicklas |
if(!yStart) |
5350 |
25 May 10 |
nicklas |
4530 |
{ |
5350 |
25 May 10 |
nicklas |
if(y2==y1) |
5350 |
25 May 10 |
nicklas |
4532 |
{ |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=xp; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;top:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=y1; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;width:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;height:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;background-color:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=hexColor; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
4544 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
4546 |
{ |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;overflow:hidden;left:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=xp; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;top:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=y1; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;width:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=x2-x1+penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;height:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=y2-y1+penWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;background-color:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=hexColor; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
4558 |
} |
5350 |
25 May 10 |
nicklas |
4559 |
} |
5350 |
25 May 10 |
nicklas |
4560 |
} |
5350 |
25 May 10 |
nicklas |
4561 |
} |
5350 |
25 May 10 |
nicklas |
4562 |
} |
5350 |
25 May 10 |
nicklas |
4563 |
} |
5350 |
25 May 10 |
nicklas |
4564 |
|
5350 |
25 May 10 |
nicklas |
//Draw color filled closed curve passing through the specified points |
5350 |
25 May 10 |
nicklas |
//with specified tension |
5350 |
25 May 10 |
nicklas |
function fillClosedCurve(color,points,tension) |
5350 |
25 May 10 |
nicklas |
4568 |
{ |
5350 |
25 May 10 |
nicklas |
if(!color || !points) |
5350 |
25 May 10 |
nicklas |
return false; |
5350 |
25 May 10 |
nicklas |
4571 |
|
5350 |
25 May 10 |
nicklas |
if(!tension) |
5350 |
25 May 10 |
nicklas |
4573 |
{ |
5350 |
25 May 10 |
nicklas |
tension=0; |
5350 |
25 May 10 |
nicklas |
4575 |
} |
5350 |
25 May 10 |
nicklas |
4576 |
|
5350 |
25 May 10 |
nicklas |
var phPoints=new Array(); |
5350 |
25 May 10 |
nicklas |
for(var i=0;i<points.length;i++) |
5350 |
25 May 10 |
nicklas |
4579 |
{ |
5350 |
25 May 10 |
nicklas |
phPoints[i]=logicalToPhysicalPoint(points[i]); |
5350 |
25 May 10 |
nicklas |
4581 |
} |
5350 |
25 May 10 |
nicklas |
4582 |
|
5350 |
25 May 10 |
nicklas |
//Remove duplicate consecutive points (ToDo: neccessity of this step is to be confirmed) |
5350 |
25 May 10 |
nicklas |
var newPoints=new Array(); |
5350 |
25 May 10 |
nicklas |
if(!(phPoints[0].x==phPoints[phPoints.length-1].x && phPoints[0].y==phPoints[phPoints.length-1].y)) |
5350 |
25 May 10 |
nicklas |
4586 |
{ |
5350 |
25 May 10 |
nicklas |
newPoints[newPoints.length]=phPoints[0]; |
5350 |
25 May 10 |
nicklas |
4588 |
} |
5350 |
25 May 10 |
nicklas |
4589 |
|
5350 |
25 May 10 |
nicklas |
for(var i=1;i<phPoints.length;i++) |
5350 |
25 May 10 |
nicklas |
4591 |
{ |
5350 |
25 May 10 |
nicklas |
if(!(phPoints[i].x==phPoints[i-1].x && phPoints[i].y==phPoints[i-1].y)) |
5350 |
25 May 10 |
nicklas |
4593 |
{ |
5350 |
25 May 10 |
nicklas |
newPoints[newPoints.length]=phPoints[i]; |
5350 |
25 May 10 |
nicklas |
4595 |
} |
5350 |
25 May 10 |
nicklas |
4596 |
} |
5350 |
25 May 10 |
nicklas |
phPoints=newPoints; |
5350 |
25 May 10 |
nicklas |
4598 |
|
5350 |
25 May 10 |
nicklas |
if(phPoints.length<2) |
5350 |
25 May 10 |
nicklas |
4600 |
{ |
5350 |
25 May 10 |
nicklas |
return false; |
5350 |
25 May 10 |
nicklas |
4602 |
} |
5350 |
25 May 10 |
nicklas |
else if(phPoints.length==2) |
5350 |
25 May 10 |
nicklas |
4604 |
{ |
5350 |
25 May 10 |
nicklas |
//For 2 points just draw a line connecting them. |
5350 |
25 May 10 |
nicklas |
return this.drawLine(pen,phPoints[0],phPoints[1],"physical"); |
5350 |
25 May 10 |
nicklas |
4607 |
} |
5350 |
25 May 10 |
nicklas |
4608 |
|
5350 |
25 May 10 |
nicklas |
var curveDiv=canvasDiv.appendChild(document.createElement("div")); |
5350 |
25 May 10 |
nicklas |
var iHtml=new Array(); |
5350 |
25 May 10 |
nicklas |
4611 |
|
5350 |
25 May 10 |
nicklas |
var hexColor=color.getHex(); |
5350 |
25 May 10 |
nicklas |
4613 |
|
5350 |
25 May 10 |
nicklas |
var xDataArray=new Array(); |
5350 |
25 May 10 |
nicklas |
//Array to hold points on the curve |
5350 |
25 May 10 |
nicklas |
var curvePoints=new Array(); |
5350 |
25 May 10 |
nicklas |
4617 |
|
5350 |
25 May 10 |
nicklas |
var yArray=new Array(); |
5350 |
25 May 10 |
nicklas |
var yMin; |
5350 |
25 May 10 |
nicklas |
var yMax; |
5350 |
25 May 10 |
nicklas |
var n=phPoints.length-1; |
5350 |
25 May 10 |
nicklas |
var i; |
5350 |
25 May 10 |
nicklas |
4623 |
|
5350 |
25 May 10 |
nicklas |
//Call drawCurveSeg method in loop to get points in curvePoints |
5350 |
25 May 10 |
nicklas |
//array for segment (connecting 2 points) of the curve. |
5350 |
25 May 10 |
nicklas |
for(var i=0;i<=n-1;i++) |
5350 |
25 May 10 |
nicklas |
4627 |
{ |
5350 |
25 May 10 |
nicklas |
if(i==0) |
5350 |
25 May 10 |
nicklas |
4629 |
{ |
5350 |
25 May 10 |
nicklas |
getCurveSegPixels(new Array(phPoints[n],phPoints[0],phPoints[1],phPoints[2]),tension,curvePoints); |
5350 |
25 May 10 |
nicklas |
4631 |
} |
5350 |
25 May 10 |
nicklas |
else if(i==n-1) |
5350 |
25 May 10 |
nicklas |
4633 |
{ |
5350 |
25 May 10 |
nicklas |
getCurveSegPixels(new Array(phPoints[n-2],phPoints[n-1],phPoints[n],phPoints[0]),tension,curvePoints); |
5350 |
25 May 10 |
nicklas |
4635 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
4637 |
{ |
5350 |
25 May 10 |
nicklas |
getCurveSegPixels(new Array(phPoints[i-1],phPoints[i],phPoints[i+1],phPoints[i+2]),tension,curvePoints); |
5350 |
25 May 10 |
nicklas |
4639 |
} |
5350 |
25 May 10 |
nicklas |
4640 |
} |
5350 |
25 May 10 |
nicklas |
4641 |
|
5350 |
25 May 10 |
nicklas |
getCurveSegPixels(new Array(phPoints[n-1],phPoints[n],phPoints[0],phPoints[1]),tension,curvePoints); |
5350 |
25 May 10 |
nicklas |
4643 |
|
5350 |
25 May 10 |
nicklas |
//getAllCurvePointsArray function processes the points data from curvePoints |
5350 |
25 May 10 |
nicklas |
//xDataArray is also populated by the fuction |
5350 |
25 May 10 |
nicklas |
var allPointsResult=getAllCurvePointsArray(xDataArray,yArray,curvePoints); |
5350 |
25 May 10 |
nicklas |
4647 |
|
5350 |
25 May 10 |
nicklas |
yMin=allPointsResult[0]; |
5350 |
25 May 10 |
nicklas |
yMax=allPointsResult[1]; |
5350 |
25 May 10 |
nicklas |
4650 |
|
5350 |
25 May 10 |
nicklas |
var y; |
5350 |
25 May 10 |
nicklas |
var k; |
5350 |
25 May 10 |
nicklas |
var divStyle=""; |
5350 |
25 May 10 |
nicklas |
var j; |
5350 |
25 May 10 |
nicklas |
var pointsCount=phPoints.length; |
5350 |
25 May 10 |
nicklas |
var curX,curY,curWidth; |
5350 |
25 May 10 |
nicklas |
4657 |
|
5350 |
25 May 10 |
nicklas |
//Draw the actual filled curve by drawing div rectangles |
5350 |
25 May 10 |
nicklas |
for(y=yMin;y<=yMax;y++) |
5350 |
25 May 10 |
nicklas |
4660 |
{ |
5350 |
25 May 10 |
nicklas |
j=0; |
5350 |
25 May 10 |
nicklas |
var allXDataArray=xDataArray[y]; |
5350 |
25 May 10 |
nicklas |
//Sort allXDataArray based on xMin using sortXDataArray function |
5350 |
25 May 10 |
nicklas |
allXDataArray.sort(sortXDataArray); |
5350 |
25 May 10 |
nicklas |
4665 |
|
5350 |
25 May 10 |
nicklas |
curY=y; |
5350 |
25 May 10 |
nicklas |
4667 |
|
5350 |
25 May 10 |
nicklas |
for(i=0;i<allXDataArray.length;i+=2) |
5350 |
25 May 10 |
nicklas |
4669 |
{ |
5350 |
25 May 10 |
nicklas |
if(allXDataArray[i+1]) |
5350 |
25 May 10 |
nicklas |
4671 |
{ |
5350 |
25 May 10 |
nicklas |
curX=allXDataArray[i].xMin; |
5350 |
25 May 10 |
nicklas |
if(allXDataArray[i+1].xMax>allXDataArray[i].xMax) |
5350 |
25 May 10 |
nicklas |
curWidth=allXDataArray[i+1].xMax-allXDataArray[i].xMin+1; |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
curWidth=allXDataArray[i].xMax-allXDataArray[i].xMin+1; |
5350 |
25 May 10 |
nicklas |
4677 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
4679 |
{ |
5350 |
25 May 10 |
nicklas |
curX=allXDataArray[allXDataArray.length-1].xMin; |
5350 |
25 May 10 |
nicklas |
curWidth=allXDataArray[allXDataArray.length-1].xMax-allXDataArray[allXDataArray.length-1].xMin+1; |
5350 |
25 May 10 |
nicklas |
4682 |
} |
5350 |
25 May 10 |
nicklas |
4683 |
|
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="<DIV style=\"position:absolute;height:1px;overflow:hidden;left:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=curX; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;top:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=curY; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;width:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=curWidth; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="px;background-color:"; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]=hexColor; |
5350 |
25 May 10 |
nicklas |
iHtml[iHtml.length]="\"></DIV>"; |
5350 |
25 May 10 |
nicklas |
4693 |
} |
5350 |
25 May 10 |
nicklas |
4694 |
} |
5350 |
25 May 10 |
nicklas |
4695 |
|
5350 |
25 May 10 |
nicklas |
curveDiv.innerHTML=iHtml.join(""); |
5350 |
25 May 10 |
nicklas |
return curveDiv; |
5350 |
25 May 10 |
nicklas |
4698 |
|
5350 |
25 May 10 |
nicklas |
//Internal sort function for allXDataArray array |
5350 |
25 May 10 |
nicklas |
function sortXDataArray(a,b) |
5350 |
25 May 10 |
nicklas |
4701 |
{ |
5350 |
25 May 10 |
nicklas |
return a.xMin - b.xMin; |
5350 |
25 May 10 |
nicklas |
4703 |
} |
5350 |
25 May 10 |
nicklas |
4704 |
} |
5350 |
25 May 10 |
nicklas |
4705 |
|
5350 |
25 May 10 |
nicklas |
//Private function used by fillClosedCurve method to get curve points |
5350 |
25 May 10 |
nicklas |
//(in curvePoints array) for a single curve segment (connecting 2 points) |
5350 |
25 May 10 |
nicklas |
function getCurveSegPixels(segPoints,tension,curvePoints) |
5350 |
25 May 10 |
nicklas |
4709 |
{ |
5350 |
25 May 10 |
nicklas |
var x=0; |
5350 |
25 May 10 |
nicklas |
var y=0; |
5350 |
25 May 10 |
nicklas |
var xl=segPoints[1].x-1; |
5350 |
25 May 10 |
nicklas |
var yl=segPoints[1].y-1; |
5350 |
25 May 10 |
nicklas |
var t=0; |
5350 |
25 May 10 |
nicklas |
var f=1; |
5350 |
25 May 10 |
nicklas |
var k=1.1; |
5350 |
25 May 10 |
nicklas |
var penWidth=1; |
5350 |
25 May 10 |
nicklas |
var divWidth=1; |
5350 |
25 May 10 |
nicklas |
var divHeight=1; |
5350 |
25 May 10 |
nicklas |
4720 |
|
5350 |
25 May 10 |
nicklas |
var m1x=(1-tension)*(segPoints[2].x-segPoints[0].x)/2; |
5350 |
25 May 10 |
nicklas |
var m2x=(1-tension)*(segPoints[3].x-segPoints[1].x)/2; |
5350 |
25 May 10 |
nicklas |
4723 |
|
5350 |
25 May 10 |
nicklas |
var m1y=(1-tension)*(segPoints[2].y-segPoints[0].y)/2; |
5350 |
25 May 10 |
nicklas |
var m2y=(1-tension)*(segPoints[3].y-segPoints[1].y)/2; |
5350 |
25 May 10 |
nicklas |
4726 |
|
5350 |
25 May 10 |
nicklas |
while(t<=1) |
5350 |
25 May 10 |
nicklas |
4728 |
{ |
5350 |
25 May 10 |
nicklas |
x=0; |
5350 |
25 May 10 |
nicklas |
y=0; |
5350 |
25 May 10 |
nicklas |
4731 |
|
5350 |
25 May 10 |
nicklas |
x= (2*t*t*t-3*t*t+1)*segPoints[1].x + (t*t*t-2*t*t+t)*m1x + (-2*t*t*t+3*t*t)*segPoints[2].x + (t*t*t-t*t)*m2x; |
5350 |
25 May 10 |
nicklas |
y= (2*t*t*t-3*t*t+1)*segPoints[1].y + (t*t*t-2*t*t+t)*m1y + (-2*t*t*t+3*t*t)*segPoints[2].y + (t*t*t-t*t)*m2y; |
5350 |
25 May 10 |
nicklas |
4734 |
|
5350 |
25 May 10 |
nicklas |
x=Math.round(x); |
5350 |
25 May 10 |
nicklas |
y=Math.round(y); |
5350 |
25 May 10 |
nicklas |
4737 |
|
5350 |
25 May 10 |
nicklas |
if(x!=xl || y!=yl) |
5350 |
25 May 10 |
nicklas |
4739 |
{ |
5350 |
25 May 10 |
nicklas |
if(x-xl>1 || y-yl>1 || xl-x>1 || yl-y>1) |
5350 |
25 May 10 |
nicklas |
4741 |
{ |
5350 |
25 May 10 |
nicklas |
t-=f; |
5350 |
25 May 10 |
nicklas |
f=f/k; |
5350 |
25 May 10 |
nicklas |
4744 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
4746 |
{ |
5350 |
25 May 10 |
nicklas |
curvePoints[curvePoints.length]=new jsPoint(x,y); |
5350 |
25 May 10 |
nicklas |
xl=x; |
5350 |
25 May 10 |
nicklas |
yl=y; |
5350 |
25 May 10 |
nicklas |
if(t+f>1) |
5350 |
25 May 10 |
nicklas |
t=1-f; |
5350 |
25 May 10 |
nicklas |
4752 |
} |
5350 |
25 May 10 |
nicklas |
4753 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
4755 |
{ |
5350 |
25 May 10 |
nicklas |
f=f*k; |
5350 |
25 May 10 |
nicklas |
4757 |
} |
5350 |
25 May 10 |
nicklas |
t+=f; |
5350 |
25 May 10 |
nicklas |
4759 |
} |
5350 |
25 May 10 |
nicklas |
4760 |
} |
5350 |
25 May 10 |
nicklas |
4761 |
|
5350 |
25 May 10 |
nicklas |
//Private function that processes the points data from curvePoints |
5350 |
25 May 10 |
nicklas |
//xDataArray is also populated by the fuction |
5350 |
25 May 10 |
nicklas |
function getAllCurvePointsArray(xDataArray,yArray,curvePoints) |
5350 |
25 May 10 |
nicklas |
4765 |
{ |
5350 |
25 May 10 |
nicklas |
function xData() |
5350 |
25 May 10 |
nicklas |
4767 |
{ |
5350 |
25 May 10 |
nicklas |
this.xMax=0; |
5350 |
25 May 10 |
nicklas |
this.xMin=0; |
5350 |
25 May 10 |
nicklas |
this.i=0; |
5350 |
25 May 10 |
nicklas |
4771 |
} |
5350 |
25 May 10 |
nicklas |
4772 |
|
5350 |
25 May 10 |
nicklas |
var isEliminated=new Array(); |
5350 |
25 May 10 |
nicklas |
var yMin; |
5350 |
25 May 10 |
nicklas |
var yMax; |
5350 |
25 May 10 |
nicklas |
var lastY; |
5350 |
25 May 10 |
nicklas |
var firstY; |
5350 |
25 May 10 |
nicklas |
var isFirst=true; |
5350 |
25 May 10 |
nicklas |
var xDataArrayLast; |
5350 |
25 May 10 |
nicklas |
var iLast=-1; |
5350 |
25 May 10 |
nicklas |
var yTop1,yTop2; |
5350 |
25 May 10 |
nicklas |
4782 |
|
5350 |
25 May 10 |
nicklas |
for(var i=0;i<curvePoints.length;i++) |
5350 |
25 May 10 |
nicklas |
4784 |
{ |
5350 |
25 May 10 |
nicklas |
var next=false; |
7419 |
03 Nov 17 |
nicklas |
var x=curvePoints[i].x; |
7419 |
03 Nov 17 |
nicklas |
var y=curvePoints[i].y; |
5350 |
25 May 10 |
nicklas |
4788 |
|
5350 |
25 May 10 |
nicklas |
//Eliminate extra points disturbing continuity/smoothness |
5350 |
25 May 10 |
nicklas |
if(i!=0 && i+1<curvePoints.length) |
5350 |
25 May 10 |
nicklas |
4791 |
{ |
5350 |
25 May 10 |
nicklas |
if((curvePoints[i-1].x-curvePoints[i+1].x==1 || curvePoints[i+1].x-curvePoints[i-1].x==1) && (curvePoints[i-1].y-curvePoints[i+1].y==1 || curvePoints[i+1].y-curvePoints[i-1].y==1)) |
5350 |
25 May 10 |
nicklas |
4793 |
{ |
5350 |
25 May 10 |
nicklas |
if(!isEliminated[i-1]) |
5350 |
25 May 10 |
nicklas |
4795 |
{ |
5350 |
25 May 10 |
nicklas |
next=true; |
5350 |
25 May 10 |
nicklas |
isEliminated[i]=true; |
5350 |
25 May 10 |
nicklas |
4798 |
} |
5350 |
25 May 10 |
nicklas |
4799 |
} |
5350 |
25 May 10 |
nicklas |
4800 |
} |
5350 |
25 May 10 |
nicklas |
4801 |
|
5350 |
25 May 10 |
nicklas |
//Divs optimization |
5350 |
25 May 10 |
nicklas |
if(!next) |
5350 |
25 May 10 |
nicklas |
4804 |
{ |
5350 |
25 May 10 |
nicklas |
if(!firstY) |
5350 |
25 May 10 |
nicklas |
firstY=y; |
5350 |
25 May 10 |
nicklas |
4807 |
|
5350 |
25 May 10 |
nicklas |
if(!yMin) |
5350 |
25 May 10 |
nicklas |
yMin=y; |
5350 |
25 May 10 |
nicklas |
if(!yMax) |
5350 |
25 May 10 |
nicklas |
yMax=y; |
5350 |
25 May 10 |
nicklas |
4812 |
|
5350 |
25 May 10 |
nicklas |
if(y<yMin) |
5350 |
25 May 10 |
nicklas |
yMin=y; |
5350 |
25 May 10 |
nicklas |
if(y>yMax) |
5350 |
25 May 10 |
nicklas |
yMax=y; |
5350 |
25 May 10 |
nicklas |
4817 |
|
5350 |
25 May 10 |
nicklas |
if(!xDataArray[y]) |
5350 |
25 May 10 |
nicklas |
4819 |
{ |
5350 |
25 May 10 |
nicklas |
xDataArray[y]=new Array(); |
5350 |
25 May 10 |
nicklas |
xDataArray[y][0]=new xData(); |
5350 |
25 May 10 |
nicklas |
xDataArray[y][0].xMin=x; |
5350 |
25 May 10 |
nicklas |
xDataArray[y][0].xMax=x; |
5350 |
25 May 10 |
nicklas |
xDataArray[y][0].i=i; |
5350 |
25 May 10 |
nicklas |
4825 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
4827 |
{ |
5350 |
25 May 10 |
nicklas |
xDataArrayLast=xDataArray[y][xDataArray[y].length-1]; |
5350 |
25 May 10 |
nicklas |
if(i-xDataArrayLast.i==1) |
5350 |
25 May 10 |
nicklas |
4830 |
{ |
5350 |
25 May 10 |
nicklas |
if(xDataArrayLast.xMin>x) |
5350 |
25 May 10 |
nicklas |
xDataArrayLast.xMin=x; |
5350 |
25 May 10 |
nicklas |
if(xDataArrayLast.xMax<x) |
5350 |
25 May 10 |
nicklas |
xDataArrayLast.xMax=x; |
5350 |
25 May 10 |
nicklas |
4835 |
|
5350 |
25 May 10 |
nicklas |
xDataArrayLast.i=i; |
5350 |
25 May 10 |
nicklas |
4837 |
} |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
4839 |
{ |
5350 |
25 May 10 |
nicklas |
xDataArray[y][xDataArray[y].length]=new xData(); |
5350 |
25 May 10 |
nicklas |
xDataArray[y][xDataArray[y].length-1].xMin=x; |
5350 |
25 May 10 |
nicklas |
xDataArray[y][xDataArray[y].length-1].xMax=x; |
5350 |
25 May 10 |
nicklas |
xDataArray[y][xDataArray[y].length-1].i=i; |
5350 |
25 May 10 |
nicklas |
4844 |
} |
5350 |
25 May 10 |
nicklas |
4845 |
} |
5350 |
25 May 10 |
nicklas |
4846 |
|
5350 |
25 May 10 |
nicklas |
yTop1=yArray[yArray.length-1]; |
5350 |
25 May 10 |
nicklas |
yTop2=yArray[yArray.length-2]; |
5350 |
25 May 10 |
nicklas |
4849 |
|
5350 |
25 May 10 |
nicklas |
if(yTop1 && yTop2) |
5350 |
25 May 10 |
nicklas |
4851 |
{ |
5350 |
25 May 10 |
nicklas |
if((yTop1 > y && yTop2 < yTop1) || (yTop1 < y && yTop2 > yTop1)) |
5350 |
25 May 10 |
nicklas |
4853 |
{ |
5350 |
25 May 10 |
nicklas |
xDataArray[yTop1][xDataArray[yTop1].length]=xDataArray[yTop1][xDataArray[yTop1].length-1]; |
5350 |
25 May 10 |
nicklas |
4855 |
} |
5350 |
25 May 10 |
nicklas |
4856 |
} |
5350 |
25 May 10 |
nicklas |
4857 |
|
5350 |
25 May 10 |
nicklas |
if(!yArray[0]) |
5350 |
25 May 10 |
nicklas |
4859 |
{ |
5350 |
25 May 10 |
nicklas |
yArray[0]=y; |
5350 |
25 May 10 |
nicklas |
4861 |
} |
5350 |
25 May 10 |
nicklas |
else if(yArray[yArray.length-1]!=y) |
5350 |
25 May 10 |
nicklas |
4863 |
{ |
5350 |
25 May 10 |
nicklas |
yArray[yArray.length]=y; |
5350 |
25 May 10 |
nicklas |
4865 |
} |
5350 |
25 May 10 |
nicklas |
4866 |
|
5350 |
25 May 10 |
nicklas |
lastY=y; |
5350 |
25 May 10 |
nicklas |
4868 |
} |
5350 |
25 May 10 |
nicklas |
4869 |
} |
5350 |
25 May 10 |
nicklas |
4870 |
|
5350 |
25 May 10 |
nicklas |
yTop1=yArray[0]; |
5350 |
25 May 10 |
nicklas |
yTop2=yTop1; |
5350 |
25 May 10 |
nicklas |
var i=1; |
5350 |
25 May 10 |
nicklas |
while(yTop1==yTop2) |
5350 |
25 May 10 |
nicklas |
4875 |
{ |
5350 |
25 May 10 |
nicklas |
yTop2=yArray[yArray.length-i]; |
5350 |
25 May 10 |
nicklas |
i++; |
5350 |
25 May 10 |
nicklas |
4878 |
} |
5350 |
25 May 10 |
nicklas |
4879 |
|
5350 |
25 May 10 |
nicklas |
if(yTop1 && yTop2) |
5350 |
25 May 10 |
nicklas |
4881 |
{ |
5350 |
25 May 10 |
nicklas |
if((yTop1 > yArray[1] && yTop2 < yTop1) || (yTop1 < yArray[1] && yTop2 > yTop1)) |
5350 |
25 May 10 |
nicklas |
4883 |
{ |
5350 |
25 May 10 |
nicklas |
xDataArray[yTop1][xDataArray[yTop1].length]=xDataArray[yTop1][xDataArray[yTop1].length-1]; |
5350 |
25 May 10 |
nicklas |
4885 |
} |
5350 |
25 May 10 |
nicklas |
4886 |
} |
5350 |
25 May 10 |
nicklas |
4887 |
|
5350 |
25 May 10 |
nicklas |
if(firstY==lastY) |
5350 |
25 May 10 |
nicklas |
4889 |
{ |
5350 |
25 May 10 |
nicklas |
var firstXDataA=xDataArray[firstY][0]; |
5350 |
25 May 10 |
nicklas |
var lastXDataA=xDataArray[lastY][xDataArray[lastY].length-1]; |
5350 |
25 May 10 |
nicklas |
4892 |
|
5350 |
25 May 10 |
nicklas |
if(lastXDataA.xMax>firstXDataA.xMax) |
5350 |
25 May 10 |
nicklas |
xDataArray[firstY][0].xMax=lastXDataA.xMax; |
5350 |
25 May 10 |
nicklas |
4895 |
|
5350 |
25 May 10 |
nicklas |
if(lastXDataA.xMin<firstXDataA.xMin) |
5350 |
25 May 10 |
nicklas |
xDataArray[firstY][0].xMin=lastXDataA.xMin; |
5350 |
25 May 10 |
nicklas |
4898 |
|
5350 |
25 May 10 |
nicklas |
if(xDataArray[lastY].length>1) |
5350 |
25 May 10 |
nicklas |
xDataArray[lastY].pop(); |
5350 |
25 May 10 |
nicklas |
else |
5350 |
25 May 10 |
nicklas |
xDataArray.pop(); |
5350 |
25 May 10 |
nicklas |
4903 |
} |
5350 |
25 May 10 |
nicklas |
4904 |
|
5350 |
25 May 10 |
nicklas |
return new Array(yMin,yMax); |
5350 |
25 May 10 |
nicklas |
4906 |
} |
5350 |
25 May 10 |
nicklas |
4907 |
|
5350 |
25 May 10 |
nicklas |
//Draw text string at specified point with specified color,font,width & alignment |
5350 |
25 May 10 |
nicklas |
function drawText(text,point,font,color,width,align) |
5350 |
25 May 10 |
nicklas |
4910 |
{ |
5350 |
25 May 10 |
nicklas |
//Check arguments for null values |
5350 |
25 May 10 |
nicklas |
if(!text || !point) |
5350 |
25 May 10 |
nicklas |
return false; |
5350 |
25 May 10 |
nicklas |
4914 |
|
7419 |
03 Nov 17 |
nicklas |
var phPoint=logicalToPhysicalPoint(point); |
5350 |
25 May 10 |
nicklas |
4916 |
|
5350 |
25 May 10 |
nicklas |
if(width!=null) |
5350 |
25 May 10 |
nicklas |
width=Math.round(width*scale) + "px"; |
5350 |
25 May 10 |
nicklas |
4919 |
|
5350 |
25 May 10 |
nicklas |
var textDiv=canvasDiv.appendChild(document.createElement("div")); |
5350 |
25 May 10 |
nicklas |
4921 |
|
5350 |
25 May 10 |
nicklas |
textDiv.style.position="absolute"; |
5350 |
25 May 10 |
nicklas |
textDiv.style.left=phPoint.x + "px"; |
5350 |
25 May 10 |
nicklas |
textDiv.style.top=phPoint.y + "px"; |
5350 |
25 May 10 |
nicklas |
4925 |
|
5350 |
25 May 10 |
nicklas |
if(color) |
5350 |
25 May 10 |
nicklas |
textDiv.style.color=color.getHex(); |
5350 |
25 May 10 |
nicklas |
4928 |
|
5350 |
25 May 10 |
nicklas |
//set font |
5350 |
25 May 10 |
nicklas |
if(font) |
5350 |
25 May 10 |
nicklas |
4931 |
{ |
5350 |
25 May 10 |
nicklas |
if(font.family) |
5350 |
25 May 10 |
nicklas |
textDiv.style.fontFamily=font.family; |
5350 |
25 May 10 |
nicklas |
4934 |
|
5350 |
25 May 10 |
nicklas |
if(font.weight) |
5350 |
25 May 10 |
nicklas |
textDiv.style.fontWeight=font.weight; |
5350 |
25 May 10 |
nicklas |
4937 |
|
5350 |
25 May 10 |
nicklas |
if(font.size) |
5350 |
25 May 10 |
nicklas |
textDiv.style.fontSize=font.size; |
5350 |
25 May 10 |
nicklas |
4940 |
|
5350 |
25 May 10 |
nicklas |
if(font.style) |
5350 |
25 May 10 |
nicklas |
textDiv.style.fontStyle=font.style; |
5350 |
25 May 10 |
nicklas |
4943 |
|
5350 |
25 May 10 |
nicklas |
if(font.variant) |
5350 |
25 May 10 |
nicklas |
textDiv.style.fontVariant=font.variant; |
5350 |
25 May 10 |
nicklas |
4946 |
} |
5350 |
25 May 10 |
nicklas |
4947 |
|
5350 |
25 May 10 |
nicklas |
if(width) |
5350 |
25 May 10 |
nicklas |
textDiv.style.width=width; |
5350 |
25 May 10 |
nicklas |
4950 |
|
5350 |
25 May 10 |
nicklas |
if(align) |
5350 |
25 May 10 |
nicklas |
textDiv.style.textAlign=align; |
5350 |
25 May 10 |
nicklas |
4953 |
|
5350 |
25 May 10 |
nicklas |
textDiv.innerHTML=text; |
5350 |
25 May 10 |
nicklas |
4955 |
|
5350 |
25 May 10 |
nicklas |
return textDiv; |
5350 |
25 May 10 |
nicklas |
4957 |
} |
5350 |
25 May 10 |
nicklas |
4958 |
|
5350 |
25 May 10 |
nicklas |
//Draw image at specified point with specified width & height |
5350 |
25 May 10 |
nicklas |
function drawImage(url,point,width,height) |
5350 |
25 May 10 |
nicklas |
4961 |
{ |
5350 |
25 May 10 |
nicklas |
if(!url || !point) |
5350 |
25 May 10 |
nicklas |
return false; |
5350 |
25 May 10 |
nicklas |
4964 |
|
7419 |
03 Nov 17 |
nicklas |
var phPoint=logicalToPhysicalPoint(point); |
5350 |
25 May 10 |
nicklas |
4966 |
|
5350 |
25 May 10 |
nicklas |
if(width!=null) |
5350 |
25 May 10 |
nicklas |
width=Math.round(width*scale) + "px"; |
5350 |
25 May 10 |
nicklas |
4969 |
|
5350 |
25 May 10 |
nicklas |
if(height!=null) |
5350 |
25 May 10 |
nicklas |
height=Math.round(height*scale) + "px"; |
5350 |
25 May 10 |
nicklas |
4972 |
|
5350 |
25 May 10 |
nicklas |
var imgDiv=canvasDiv.appendChild(document.createElement("div")); |
5350 |
25 May 10 |
nicklas |
4974 |
|
5350 |
25 May 10 |
nicklas |
imgDiv.style.position="absolute"; |
5350 |
25 May 10 |
nicklas |
imgDiv.style.left=phPoint.x + "px"; |
5350 |
25 May 10 |
nicklas |
imgDiv.style.top=phPoint.y + "px"; |
5350 |
25 May 10 |
nicklas |
//create and set img tag/element |
5350 |
25 May 10 |
nicklas |
var img=imgDiv.appendChild(document.createElement("img")); |
5350 |
25 May 10 |
nicklas |
4980 |
|
5350 |
25 May 10 |
nicklas |
img.src=url; |
5350 |
25 May 10 |
nicklas |
4982 |
|
5350 |
25 May 10 |
nicklas |
if(width!=null) |
5350 |
25 May 10 |
nicklas |
4984 |
{ |
5350 |
25 May 10 |
nicklas |
img.style.width=width; |
5350 |
25 May 10 |
nicklas |
imgDiv.style.width=width; |
5350 |
25 May 10 |
nicklas |
4987 |
} |
5350 |
25 May 10 |
nicklas |
4988 |
|
5350 |
25 May 10 |
nicklas |
if(height!=null) |
5350 |
25 May 10 |
nicklas |
4990 |
{ |
5350 |
25 May 10 |
nicklas |
img.style.height=height; |
5350 |
25 May 10 |
nicklas |
imgDiv.style.height=height; |
5350 |
25 May 10 |
nicklas |
4993 |
} |
5350 |
25 May 10 |
nicklas |
4994 |
|
5350 |
25 May 10 |
nicklas |
return imgDiv; |
5350 |
25 May 10 |
nicklas |
4996 |
} |
5350 |
25 May 10 |
nicklas |
4997 |
|
5350 |
25 May 10 |
nicklas |
//Clear the canvas div element |
5350 |
25 May 10 |
nicklas |
function clear() |
5350 |
25 May 10 |
nicklas |
5000 |
{ |
5350 |
25 May 10 |
nicklas |
canvasDiv.innerHTML=""; |
5350 |
25 May 10 |
nicklas |
5002 |
} |
5527 |
13 Dec 10 |
nicklas |
5003 |
|
5527 |
13 Dec 10 |
nicklas |
function clearDrawing(div) |
5527 |
13 Dec 10 |
nicklas |
5005 |
{ |
5527 |
13 Dec 10 |
nicklas |
canvasDiv.removeChild(div); |
5527 |
13 Dec 10 |
nicklas |
5007 |
} |
5350 |
25 May 10 |
nicklas |
5008 |
} |