<% //*************************************************** // DiagramGenerator //*************************************************** function DiagramGenerator() { // "Public" functions... this.DrawDiagram = DrawDiagram; this.SetValues = SetValues; this.SetMaxValue = SetMaxValue; this.SetImageSize = SetImageSize; this.SetBarMarks = SetBarMarks; this.SetBarSize = SetBarSize; this.SetFont = SetFont; this.SetBarColors = SetBarColors; this.SetBgColors = SetBgColors; this.SetBgColor = SetBgColor; // "Private" functions... this.CreateBars = CreateBars; this.DrawText = DrawText; this.Draw3DBackground = Draw3DBackground; this.Draw3DRect = Draw3DRect; //********************************************************************************* // Default settings //********************************************************************************* this.text1 = "A"; this.value1A = 6; this.value1B = 7; this.text2 = "B"; this.value2A = 4; this.value2B = 6; this.text3 = "C"; this.value3A = 2.5; this.value3B = 5; this.text4 = "D"; this.value4A = 1.5; this.value4B = 4; this.marksEnabled = true; // Enable this to draw marks on the bars. // Imagesize this.imagesizeX = 430; // Width of image. this.imagesizeY = 330; // Height of image. // The background this.maxValue = 8; // Maximum value that will be displayed in the background. // The bars this.barHeightmultiplicator = 30; // This is used to stretch the bars... this.barWidth = 45; // Width of the bars. this.barDepth = 5; // Depth of the bars. this.barXSpacing = 15; // Space between bars (X). this.barYSpacing = 20; // Space between bars (Y). // The font this.fontColor = 0x000000; // Color of the font that displays the texts and numbers. this.fontName = "Tahoma"; // The font. this.fontSize = 12; // The fontsize. // The barcolors this.lineColorFront = 0x000000; // Do NOT use the same linecolor twice... this.frontColorFront = 0xdd7777; this.topColorFront = 0xff8888; this.rightColorFront = 0xcc5555; this.lineColorBack = 0x000001; // Do NOT use the same linecolor twice... this.frontColorBack = 0xcc4444; this.topColorBack = 0xee6666; this.rightColorBack = 0xbb2222; // The background colors this.lineColorBg = 0x010000; // Do NOT use the same linecolor twice... this.frontColorBg = 0xffaaaa; this.topColorBg = 0xffcccc; this.leftColorBg = 0xff8888; this.darkColorBg = 0xdd6666; // The background color of the image this.bgColor = 0xffffff; return this; //********************************************************************************* // Functions //********************************************************************************* //*************************************************** // Name: SetValues // Descr: This function sets the values and lables // of the bars. //*************************************************** function SetValues(text1, text2, text3, text4, value1A, value2A, value3A, value4A, value1B, value2B, value3B, value4B) { this.text1 = text1; this.value1A = value1A; this.value1B = value1B; this.text2 = text2; this.value2A = value2A; this.value2B = value2B; this.text3 = text3; this.value3A = value3A; this.value3B = value3B; this.text4 = text4; this.value4A = value4A; this.value4B = value4B; } //*************************************************** // Name: SetImageSize // Descr: This function sets size of the image. //*************************************************** function SetImageSize(sizeX, sizeY) { this.imagesizeX = sizeX; this.imagesizeY = sizeY; } //*************************************************** // Name: SetMaxValue // Descr: This function sets the maximum value that // will be displayed on the background. //*************************************************** function SetMaxValue(value) { this.maxValue = value; } //*************************************************** // Name: SetBarMarks // Descr: This function is used to disable the // 3D marks. //*************************************************** function SetBarMarks(value) { this.marksEnabled = value; } //*************************************************** // Name: SetBgColor // Descr: This function sets the background color. //*************************************************** function SetBgColor(value) { this.bgColor = value; } //*************************************************** // Name: SetBarSize // Descr: Sets the sizes of the bars. //*************************************************** function SetBarSize(width, depth, heightmultiplicator, xSpacing, ySpacing) { this.barHeightmultiplicator = heightmultiplicator; this.barWidth = width; this.barDepth = depth; this.barXSpacing = xSpacing; this.barYSpacing = ySpacing; } //*************************************************** // Name: SetFont // Descr: Sets the font for displaying the labels. //*************************************************** function SetFont(font, size, italic, color) { this.fontColor = color; this.fontItalic = italic; this.fontName = font; this.fontSize = size; } //*************************************************** // Name: SetBarColors // Descr: Sets the colors of the bars. "lineA" and // "lineB" should not be set to the same // value. //*************************************************** function SetBarColors(lineA, frontA, topA, rightA, lineB, frontB, topB, rightB) { this.lineColorFront = lineA; this.frontColorFront = frontA; this.topColorFront = topA; this.rightColorFront = rightA; this.lineColorBack = lineB; this.frontColorBack = frontB; this.topColorBack = topB; this.rightColorBack = rightB; } //*************************************************** // Name: SetBgColors // Descr: Sets the colors of the background. "line" // should not be set to a value that has // been used for the "lineA" value or the // "lineB" value in SetBarColors(...) //*************************************************** function SetBgColors(line, front, top, left, shadow) { this.lineColorBg = line; this.frontColorBg = front; this.topColorBg = top; this.leftColorBg = left; this.darkColorBg = shadow; } //*************************************************** // Name: DrawDiagram // Descr: This function draws the complete diagram, // and should be called after the settings // are done. //*************************************************** function DrawDiagram() { // Create the imageobject. this.Image = Server.CreateObject("W3Image.Image"); this.Image.BkColor = this.bgColor; this.Image.CreateEmptySurface(this.imagesizeX, this.imagesizeY); var backgroundXEnd = 50 + ((this.barWidth) * 4) + ((this.barXSpacing ) * 3); var backgroundYEnd = ((this.barHeightmultiplicator * this.maxValue) + 20); var backgroundPositionModifier = (this.barDepth * 2) + this.barYSpacing; // Create the diagram. this.Draw3DBackground((45 + backgroundPositionModifier), (this.imagesizeY - 40 - backgroundPositionModifier), backgroundXEnd, backgroundYEnd, (15 + backgroundPositionModifier), this.lineColorBg, this.frontColorBg, this.topColorBg, this.leftColorBg, this.darkColorBg); this.DrawText(); this.CreateBars(); this.Image.StreamImage(Response, "JPG", 24); } //*************************************************** // Name: DrawDiagram // Descr: This function puts the bars into the // diagram. //*************************************************** function CreateBars() { var rectStartX = 60 + this.barDepth + this.barYSpacing; var tempX = this.barXSpacing; var tempY = this.barYSpacing; this.barXSpacing += this.barWidth - 1; this.barYSpacing = (this.imagesizeY - 30 - this.barDepth - this.barYSpacing); this.Draw3DRect(rectStartX, this.barYSpacing, this.barWidth, (this.value1B * this.barHeightmultiplicator), this.barDepth, this.lineColorBack, this.frontColorBack, this.topColorBack, this.rightColorBack); this.Draw3DRect(60, (this.imagesizeY - 30), this.barWidth, (this.value1A * this.barHeightmultiplicator), this.barDepth, this.lineColorFront, this.frontColorFront, this.topColorFront, this.rightColorFront); this.Draw3DRect((rectStartX + this.barXSpacing), this.barYSpacing, this.barWidth, (this.value2B * this.barHeightmultiplicator), this.barDepth, this.lineColorBack, this.frontColorBack, this.topColorBack, this.rightColorBack); this.Draw3DRect((60 + this.barXSpacing), (this.imagesizeY - 30), this.barWidth, (this.value2A * this.barHeightmultiplicator), this.barDepth, this.lineColorFront, this.frontColorFront, this.topColorFront, this.rightColorFront); this.Draw3DRect((rectStartX + (this.barXSpacing * 2)), this.barYSpacing, this.barWidth, (this.value3B * this.barHeightmultiplicator), this.barDepth, this.lineColorBack, this.frontColorBack, this.topColorBack, this.rightColorBack); this.Draw3DRect((60 + (this.barXSpacing * 2)), (this.imagesizeY - 30), this.barWidth, (this.value3A * this.barHeightmultiplicator), this.barDepth, this.lineColorFront, this.frontColorFront, this.topColorFront, this.rightColorFront); this.Draw3DRect((rectStartX + (this.barXSpacing * 3)), this.barYSpacing, this.barWidth, (this.value4B * this.barHeightmultiplicator), this.barDepth, this.lineColorBack, this.frontColorBack, this.topColorBack, this.rightColorBack); this.Draw3DRect((60 + (this.barXSpacing * 3)), (this.imagesizeY - 30), this.barWidth, (this.value4A * this.barHeightmultiplicator), this.barDepth, this.lineColorFront, this.frontColorFront, this.topColorFront, this.rightColorFront); this.barXSpacing = tempX; this.barYSpacing = tempY; } //*************************************************** // Name: DrawText // Descr: This function draws the texts. //*************************************************** function DrawText() { // Set the font. var textX = 57; var fontobj = this.Image.CreateFont(this.fontName, this.fontSize, 0, 0, 0, this.fontColor, this.fontItalic, false, true); this.Image.SetFont(fontobj); // Draw the text. this.Image.DrawText(this.text1, textX, (this.imagesizeY - 20)); this.Image.DrawText(this.text2, (textX + this.barWidth + this.barXSpacing), (this.imagesizeY - 20)); this.Image.DrawText(this.text3, (textX + (this.barWidth + this.barXSpacing) * 2), (this.imagesizeY - 20)); this.Image.DrawText(this.text4, (textX + (this.barWidth + this.barXSpacing) * 3), (this.imagesizeY - 20)); } //*************************************************** // Name: Draw3DBackground // Descr: This function draws the background. //*************************************************** function Draw3DBackground(x, y, width, height, depth, lineColor, frontColor, topColor, leftColor, darkColor) { var penobj = this.Image.CreatePen("solid", 1, lineColor); brushobj = this.Image.CreateSolidBrush(frontColor); var fontobj = this.Image.CreateFont(this.fontName, this.fontSize, 0, 0, 0, this.fontColor, this.fontItalic, false, true); this.Image.SetPen(penobj); this.Image.SetBrush(brushobj); this.Image.SetFont(fontobj); // Draw the diagrambackground. this.Image.DrawRect( x, y, (x + width), (y - height)); // Make it look like 3D. this.Image.DrawLine(x, y, (x - depth), (y + depth)); this.Image.DrawLine((x - depth), (y + depth), (x + width - depth), (y + depth)); this.Image.DrawLine(x, (y - height), (x - depth), (y - height + depth)); this.Image.DrawLine((x - depth), (y - height + depth), (x - depth), (y + depth)); this.Image.DrawLine((x + width - 1), y, (x + width - depth - 1), (y + depth)); // Fill 3D-space with color. if(depth > 0) { brushobj = this.Image.CreateSolidBrush(leftColor); this.Image.SetBrush(brushobj); this.Image.FloodFill((x - (depth / 2)), (y - (height / 2)), lineColor); brushobj = this.Image.CreateSolidBrush(topColor); this.Image.SetBrush(brushobj); this.Image.FloodFill((x + (width / 2)), (y + (depth / 2)), lineColor); } var penobjLeft = this.Image.CreatePen("solid", 1, leftColor); var penobjTop = this.Image.CreatePen("solid", 1, topColor); var penobjDark = this.Image.CreatePen("solid", 1, darkColor); var penobjFront = this.Image.CreatePen("solid", 1, frontColor); // Draw linenumbers. for(var i = 1; i <= this.maxValue; i++) { this.Image.SetPen(penobjLeft); this.Image.DrawLine(x + 10, (y - (i * this.barHeightmultiplicator)), (x + width - 10), (y - (i * this.barHeightmultiplicator))); this.Image.SetPen(penobjTop); this.Image.DrawLine(x + 10, (y - (i * this.barHeightmultiplicator) + 1), (x + width - 10), (y - (i * this.barHeightmultiplicator) + 1)); this.Image.SetPen(penobjDark); this.Image.DrawLine(x - 5, (y - (i * this.barHeightmultiplicator) + 5), (x - depth + 5), (y - (i * this.barHeightmultiplicator) + depth - 5)); this.Image.SetPen(penobjFront); this.Image.DrawLine(x - 5, (y - (i * this.barHeightmultiplicator) + 1 + 5), (x - depth + 5), (y - (i * this.barHeightmultiplicator) + depth + 1 - 5)); this.Image.DrawText(i, (x + width + 6), (y - (i * this.barHeightmultiplicator) - 9)); this.Image.DrawText(i, 15, (y - (i * this.barHeightmultiplicator) - 11 + depth)); } this.Image.DrawText("2000", 310, 225); this.Image.DrawText("2001", 290, 240); } //*************************************************** // Name: Draw3DRect // Descr: This function draws a single bar. //*************************************************** function Draw3DRect(x, y, width, height, depth, lineColor, frontColor, topColor, rightColor) { if(height == 0) height = 1; // Set colors. var brushobj = this.Image.CreateSolidBrush(frontColor); this.Image.SetBrush(brushobj); var penobj = this.Image.CreatePen("solid", 1, lineColor); this.Image.SetPen(penobj); // Draw the rectangle. this.Image.DrawRect( x, y, (x + width), (y - height)); // Make it look like 3D. this.Image.DrawLine(x, y - height, (x + depth), (y - height - depth)); this.Image.DrawLine((x + depth), (y - height - depth), (x + width + depth), (y - height - depth)); this.Image.DrawLine((x + width + depth - 1), (y - height - depth), (x + width - 1), (y - height)); this.Image.DrawLine((x + width + depth), (y - height - depth), (x + width + depth), (y - depth - 1)); this.Image.DrawLine((x + width - 1), (y - 1), (x + width + depth), (y - depth - 2)); // Fill 3D-space with color. if(depth > 0) { brushobj = this.Image.CreateSolidBrush(rightColor); this.Image.SetBrush(brushobj); this.Image.FloodFill((x + width + (depth / 2)), (y - (height / 2) - (depth / 2) - 2), lineColor); brushobj = this.Image.CreateSolidBrush(topColor); this.Image.SetBrush(brushobj); this.Image.FloodFill((x + (width / 2)), (y - height - (depth / 2)), lineColor); } if(this.marksEnabled) { // Draw 3D-marks. for(var i = 1; ((i * this.barHeightmultiplicator) < height); i++) { var penobjRight = this.Image.CreatePen("solid", 1, rightColor); var penobjTop = this.Image.CreatePen("solid", 1, topColor); var penobjLine = this.Image.CreatePen("solid", 1, lineColor); this.Image.SetPen(penobjRight); this.Image.DrawLine(x, (y - (i * this.barHeightmultiplicator)), (x + width), (y - (i * this.barHeightmultiplicator))); this.Image.SetPen(penobjTop); this.Image.DrawLine(x, (y - (i * this.barHeightmultiplicator) + 1), (x + width), (y - (i * this.barHeightmultiplicator) + 1)); this.Image.SetPen(penobjLine); this.Image.DrawLine((x + width), (y - (i * this.barHeightmultiplicator)), (x + width + depth), (y - (i * this.barHeightmultiplicator) - depth)); this.Image.SetPen(penobjTop); this.Image.DrawLine((x + width), (y - (i * this.barHeightmultiplicator) + 1), (x + width + depth), (y - (i * this.barHeightmultiplicator) + 1 - depth)); } } } } %>