Commit ab5184c8 authored by Alexander.Trofimov's avatar Alexander.Trofimov Committed by Alexander.Trofimov

delete Common\Charts\libraries

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@56349 954022d7-b5bf-4e40-9824-e11837661b57
parent 28c6e7e5
"use strict";
if (typeof(window["OfficeExcel"]) == 'undefined') window["OfficeExcel"] = {};
OfficeExcel.Bar = function (chartCanvas, data)
{
this.canvas = chartCanvas;
this.context = (this.canvas && this.canvas.getContext) ? this.canvas.getContext("2d") : null;
this.canvas.__object__ = this;
this.type = 'bar';
this.max = 0;
/**
* Compatibility with older browsers
*/
OfficeExcel.CanvasBrowserCompat(this.context);
// Chart gutter
this._chartGutter = new OfficeExcel.Gutter();
// Other Props
this._otherProps = new OfficeExcel.OtherProps();
// Store the data
this.data = data;
// Used to store the coords of the bars
this.coords = [];
}
/**
* The function you call to draw the bar chart
*/
OfficeExcel.Bar.prototype.Draw = function (min,max,ymin,ymax,isSkip,isFormatCell)
{
this.max = max;
this.scale = OfficeExcel.getScale(this.max, this,min,max);
this._otherProps._background_grid_autofit_numhlines = this.scale.length;
this._otherProps._numyticks = this.scale.length;
/**
* Convert any null values to 0. Won't make any difference to the bar (as opposed to the line chart)
*/
for (var i=0; i<this.data.length; ++i) {
if (this.data[i] == null) {
this.data[i] = 0;
}
}
// Cache this in a class variable as it's used rather a lot
/**
* Stop the coords array from growing uncontrollably
*/
this.coords = [];
/**
* Work out a few things. They need to be here because they depend on things you can change before you
* call Draw() but after you instantiate the object
*/
this.grapharea = OfficeExcel.GetHeight(this) - this._chartGutter._top - this._chartGutter._bottom;
this.halfgrapharea = this.grapharea / 2;
this.halfTextHeight = this._otherProps._text_size / 2;
//Draw Area
OfficeExcel.background.DrawArea(this);
// Progressively Draw the chart
OfficeExcel.background.Draw(this);
//If it's a sketch chart variant, draw the axes first
if (this._otherProps._variant == 'sketch') {
this.DrawAxes(min,max);
this.Drawbars(isSkip,isFormatCell);
} else {
this.DrawAxes(min,max);
this.Drawbars(isSkip,isFormatCell);
}
this.DrawAboveLabels(isFormatCell);
this.DrawLabels(isFormatCell);
// Draw the key if necessary
if (this._otherProps._key.length) {
OfficeExcel.DrawKey(this, this._otherProps._key, this._otherProps._colors);
}
/**
* Is a line is defined, draw it
*/
var line = this._otherProps._line;
if (line) {
line.__bar__ = this;
line._chartGutter = this._chartGutter;
line._otherProps._hmargin = (this.canvas.width - this._chartGutter._left - this._chartGutter._right) / (line.original_data[0].length * 2);
// If a BAR custom yMax is set, use that
if (this._otherProps._ymax && !line._otherProps._ymax) {
line._otherProps._ymax = this._otherProps._ymax;
} else if (line._otherProps._ymax) {
line._otherProps._ymax = line._otherProps._ymax;
}
// The boolean is used to specify that the Line chart .Draw() method is being called by the Bar chart
line.Draw(true);
}
}
/**
* Draws the charts axes
*/
OfficeExcel.Bar.prototype.DrawAxes = function (min,max)
{
if (this._otherProps._noaxes) {
return;
}
var xaxispos = this._otherProps._xaxispos;
var yaxispos = this._otherProps._yaxispos;
this.context.beginPath();
this.context.strokeStyle = this._otherProps._axis_color;
this.context.lineWidth = 1;
// Draw the Y axis
if (this._otherProps._noyaxis == false) {
if (yaxispos == 'right') {
this.context.moveTo(AA(this, this.canvas.width - this._chartGutter._right), this._chartGutter._top);
this.context.lineTo(AA(this, this.canvas.width - this._chartGutter._right), this.canvas.height - this._chartGutter._bottom + 1);
} else {
this.context.moveTo(AA(this, this._chartGutter._left), this._chartGutter._top);
this.context.lineTo(AA(this, this._chartGutter._left), this.canvas.height - this._chartGutter._bottom + 1);
}
}
// Draw the X axis
if('auto' == this._otherProps._ylabels_count)
{
//определяем куда ставить ось
var numNull = this._otherProps._background_grid_autofit_numhlines;
if(min >= 0 && max >= 0)
{
numNull = 0;
}
else if(min <= 0 && max <= 0)
{
numNull = this._otherProps._background_grid_autofit_numhlines;
}
else
{
for (var i=0; i<this.scale.length; i++)
{
if(this.scale[i] == 0)
{
numNull = i + 1;
break;
}
}
}
var nullPosition;
if(0 == numNull)
nullPosition = 0;
else
nullPosition = (this.canvas.height - this._chartGutter._bottom - this._chartGutter._top)/(this._otherProps._background_grid_autofit_numhlines)*numNull;
if (this._otherProps._noxaxis == false)
{
this.context.moveTo(this._chartGutter._left, AA(this, this.canvas.height - this._chartGutter._bottom - nullPosition));
this.context.lineTo(this.canvas.width - this._chartGutter._right, AA(this, this.canvas.height - this._chartGutter._bottom - nullPosition));
}
this.nullPositionOX = this.canvas.height - this._chartGutter._bottom - nullPosition;
}
var numYTicks = this._otherProps._numyticks;
// Draw the Y tickmarks
if (this._otherProps._noyaxis == false) {
var yTickGap = (OfficeExcel.GetHeight(this) - this._chartGutter._top - this._chartGutter._bottom) / numYTicks;
var xpos = yaxispos == 'left' ? this._chartGutter._left : OfficeExcel.GetWidth(this) - this._chartGutter._right;
for (var y=this._chartGutter._top,isCount = 0;
xaxispos == 'center' ? y <= (OfficeExcel.GetHeight(this) - this._chartGutter._bottom) + 2 : y <= (OfficeExcel.GetHeight(this) - this._chartGutter._bottom + (xaxispos == 'top' ? 1 : 0)) + 2;
y += yTickGap,++isCount) {
if (xaxispos == 'center' && y == (OfficeExcel.GetHeight(this) / 2)) continue;
// X axis at the top
//if (xaxispos == 'top' && y == this._chartGutter._top) continue;
if(isCount == numYTicks)
y = OfficeExcel.GetHeight(this) - this._chartGutter._bottom;
this.context.moveTo(xpos, AA(this, y));
this.context.lineTo(xpos + (yaxispos == 'left' ? -3 : 3), AA(this, y));
}
/**
* If the X axis is not being shown, draw an extra tick
*/
if (this._otherProps._noxaxis) {
if (xaxispos == 'center') {
this.context.moveTo(xpos + (yaxispos == 'left' ? -3 : 3), AA(this, this.canvas.height / 2));
this.context.lineTo(xpos, AA(this, OfficeExcel.GetHeight(this) / 2));
} else if (xaxispos == 'top') {
this.context.moveTo(xpos + (yaxispos == 'left' ? -3 : 3), AA(this, this._chartGutter._top));
this.context.lineTo(xpos, AA(this, this._chartGutter._top));
} else {
this.context.moveTo(xpos + (yaxispos == 'left' ? -3 : 3), AA(this, OfficeExcel.GetHeight(this) - this._chartGutter._bottom));
this.context.lineTo(xpos, AA(this, OfficeExcel.GetHeight(this) - this._chartGutter._bottom));
}
}
}
// Draw the X tickmarks
if (!this._otherProps._noxaxis) {
if('auto' == this._otherProps._ylabels_count)
{
var x = this._chartGutter._left;
var yStart = this.nullPositionOX;
var yEnd = this.nullPositionOX + 5;
for (var j=0; j <= this._otherProps._background_grid_autofit_numvlines; j++)
{
var newX = x + ((this.canvas.width - this._chartGutter._right - this._chartGutter._left)/(this._otherProps._background_grid_autofit_numvlines))*j;
this.context.moveTo(AA(this, newX), yStart);
this.context.lineTo(AA(this, newX), yEnd);
}
}
/**
* If the Y axis is not being shown, draw an extra tick
*/
if (this._otherProps._noyaxis && this._otherProps._noxaxis == false && this._otherProps._xticks == null) {
if (xaxispos == 'center') {
this.context.moveTo(AA(this, this._chartGutter._left), (OfficeExcel.GetHeight(this) / 2) - 3);
this.context.lineTo(AA(this, this._chartGutter._left), (OfficeExcel.GetHeight(this) / 2) + 3);
} else {
this.context.moveTo(AA(this, this._chartGutter._left), this.canvas.height - this._chartGutter._bottom);
this.context.lineTo(AA(this, this._chartGutter._left), this.canvas.height - this._chartGutter._bottom + 3);
}
}
}
this.context.stroke();
}
/**
* Draws the bars
*/
OfficeExcel.Bar.prototype.Drawbars = function (isSkip,formatCell)
{
this.context.lineWidth = this._otherProps._linewidth;
this.context.strokeStyle = this._otherProps._strokecolor;
this.context.fillStyle = this._otherProps._colors[0];
var prevX = 0;
var prevY = 0;
var decimals = this._otherProps._scale_decimals;
this.min = this._otherProps._ymin;
if('auto' == this._otherProps._ylabels_count)
{
var lengSc = this.scale.length;
this.max = this.scale[lengSc -1];
this.min = this._otherProps._ymin;
this._otherProps._background_grid_autofit_numhlines = lengSc;
this._otherProps._numyticks = lengSc;
}
/**
* Draw horizontal bars here
*/
if (this._otherProps._background_hbars && this._otherProps._background_hbars.length > 0) {
OfficeExcel.DrawBars(this);
}
var variant = this._otherProps._variant;
/**
* Get the variant once, and draw the bars, be they regular, stacked or grouped
*/
// Get these variables outside of the loop
var xaxispos = this._otherProps._xaxispos;
var width = (this.canvas.width - this._chartGutter._left - this._chartGutter._right ) / this.data.length;
var orig_height = height;
var hmargin = this._otherProps._hmargin;
var strokeStyle = this._otherProps._strokecolor;
var colors = this._otherProps._colors;
var bold = this._otherProps._labels_above_bold;
var textOptions =
{
color: this._otherProps._labels_above_color,
italic: this._otherProps._labels_above_italic,
underline: this._otherProps._labels_above_underline
};
for (var i=0; i<this.data.length; ++i) {
// Work out the height
//The width is up outside the loop
if(!isSkip[i])
{
var height;
if('auto' == this._otherProps._ylabels_count)
{
if(this.min < 0 && this.max > 0)
{
height = ((OfficeExcel.array_sum(this.data[i]) < 0 ? OfficeExcel.array_sum(this.data[i]): OfficeExcel.array_sum(this.data[i])) / (this.max - this.min)) * (this.canvas.height - this._chartGutter._top - this._chartGutter._bottom);
}
else
height = ((OfficeExcel.array_sum(this.data[i]) < 0 ? OfficeExcel.array_sum(this.data[i] + this.min): OfficeExcel.array_sum(this.data[i]) - this.min) / (this.max - this.min)) * (this.canvas.height - this._chartGutter._top - this._chartGutter._bottom);
}
// Half the height if the Y axis is at the center
if (xaxispos == 'center') {
height /= 2;
}
var x = (i * width) + this._chartGutter._left;
var y;
if('auto' == this._otherProps._ylabels_count)
y = this.nullPositionOX - height;
// xaxispos is top
if (xaxispos == 'top') {
y = this._chartGutter._top + Math.abs(height);
}
// Account for negative lengths - Some browsers (eg Chrome) don't like a negative value
if (height < 0) {
y += height;
height = Math.abs(height);
}
/**
* Draw the bar
*/
this.context.beginPath();
if (typeof(this.data[i]) == 'number') {
var barWidth = width - (2 * hmargin);
// Set the fill color
this.context.strokeStyle = strokeStyle;
this.context.fillStyle = colors[0];
if (variant == 'sketch') {
this.context.lineCap = 'round';
var sketchOffset = 3;
this.context.beginPath();
this.context.strokeStyle = colors[0];
// Left side
this.context.moveTo(x + hmargin + 2, y + height - 2);
this.context.lineTo(x + hmargin , y - 2);
// The top
this.context.moveTo(x + hmargin - 3, y + -2 + (this.data[i] < 0 ? height : 0));
this.context.bezierCurveTo(x + ((hmargin + width) * 0.33),y + 5 + (this.data[i] < 0 ? height - 10: 0),x + ((hmargin + width) * 0.66),y + 5 + (this.data[i] < 0 ? height - 10 : 0),x + hmargin + width + -1, y + 0 + (this.data[i] < 0 ? height : 0));
// The right side
this.context.moveTo(x + hmargin + width - 2, y + -2);
this.context.lineTo(x + hmargin + width - 3, y + height - 3);
for (var r=0.2; r<=0.8; r+=0.2) {
this.context.moveTo(x + hmargin + width + (r > 0.4 ? -1 : 3) - (r * width),y - 1);
this.context.lineTo(x + hmargin + width - (r > 0.4 ? 1 : -1) - (r * width), y + height + (r == 0.2 ? 1 : -2));
}
this.context.stroke();
// Regular bar
} else if (variant == 'bar') {
this.context.strokeRect(x + hmargin, y, barWidth, height);
this.context.fillRect(x + hmargin, y, barWidth, height);
// This bit draws the text labels that appear above the bars if requested
if (this._otherProps._labels_above) {
var yPos = y - 3;
// Account for negative bars
if (this.data[i] < 0) {
yPos += height + 6 + (this._otherProps._text_size - 4);
}
if (this._otherProps._xaxispos == 'top') {
yPos = this._chartGutter._top + height + 6 + (typeof(this._otherProps._labels_above_size) == 'number' ? this._otherProps._labels_above_size : this._otherProps._text_size - 4);
}
this.context.fillStyle = this._otherProps._text_color;
OfficeExcel.Text(this.context,
this._otherProps._labels_above_font,
typeof(this._otherProps._labels_above_size) == 'number' ? this._otherProps._labels_above_size : this._otherProps._text_size - 3,
x + hmargin + (barWidth / 2),
yPos,
OfficeExcel.number_format(this, OfficeExcel.num_round(this.data[i]),this._otherProps._units_pre,this._otherProps._units_post),
null,
'center',
null,
null,
null,
bold,
null,
textOptions
);
}
// Dot chart
} else if (variant == 'dot') {
this.context.beginPath();
this.context.moveTo(x + (width / 2), y);
this.context.lineTo(x + (width / 2), y + height);
this.context.stroke();
this.context.beginPath();
this.context.fillStyle = this._otherProps._colors[i];
this.context.arc(x + (width / 2), y + (this.data[i] > 0 ? 0 : height), 2, 0, 6.28, 0);
// Set the colour for the dots
this.context.fillStyle = this._otherProps._colors[0];
this.context.stroke();
this.context.fill();
// Pyramid chart
} else if (variant == 'pyramid') {
this.context.beginPath();
var startY = (this._otherProps._xaxispos == 'center' ? (OfficeExcel.GetHeight(this) / 2) : (OfficeExcel.GetHeight(this) - this._chartGutter._bottom));
this.context.moveTo(x + hmargin, startY);
this.context.lineTo(
x + hmargin + (barWidth / 2),
y + (this._otherProps._xaxispos == 'center' && (this.data[i] < 0) ? height : 0)
);
this.context.lineTo(x + hmargin + barWidth, startY);
this.context.closePath();
this.context.stroke();
this.context.fill();
// Arrow chart
} else if (variant == 'arrow') {
var startY = (this._otherProps._xaxispos == 'center' ? (OfficeExcel.GetHeight(this) / 2) : (OfficeExcel.GetHeight(this) - this._chartGutter._bottom));
this.context.lineWidth = this._otherProps._linewidth ? this._otherProps._linewidth : 1;
this.context.lineCap = 'round';
this.context.beginPath();
this.context.moveTo(x + hmargin + (barWidth / 2), startY);
this.context.lineTo(x + hmargin + (barWidth / 2), y + (this._otherProps._xaxispos == 'center' && (this.data[i] < 0) ? height : 0));
this.context.arc(x + hmargin + (barWidth / 2),
y + (this._otherProps._xaxispos == 'center' && (this.data[i] < 0) ? height : 0),
5,
this.data[i] > 0 ? 0.78 : 5.6,
this.data[i] > 0 ? 0.79 : 5.48,
this.data[i] < 0);
this.context.moveTo(x + hmargin + (barWidth / 2), y + (this._otherProps._xaxispos == 'center' && (this.data[i] < 0) ? height : 0));
this.context.arc(x + hmargin + (barWidth / 2),
y + (this._otherProps._xaxispos == 'center' && (this.data[i] < 0) ? height : 0),
5,
this.data[i] > 0 ? 2.355 : 4,
this.data[i] > 0 ? 2.4 : 3.925,
this.data[i] < 0);
this.context.stroke();
this.context.lineWidth = 1;
}
this.coords.push([x + hmargin, y, width - (2 * hmargin), height]);
} else if (typeof(this.data[i]) == 'object') {
this.context.lineWidth = this._otherProps._linewidth;
for (var j=0; j<this.data[i].length; ++j) {
// Set the fill and stroke colors
this.context.strokeStyle = strokeStyle;
this.context.fillStyle = colors[j];
var individualBarWidth = (width - (2 * hmargin)) / this.data[i].length;
var height;
if('auto' == this._otherProps._ylabels_count)
{
if(this.min < 0 && this.max > 0)
{
height = ((OfficeExcel.array_sum(this.data[i][j]) < 0 ? OfficeExcel.array_sum(this.data[i][j]): OfficeExcel.array_sum(this.data[i][j])) / (this.max - this.min)) * (this.canvas.height - this._chartGutter._top - this._chartGutter._bottom);
}
else
height = ((OfficeExcel.array_sum(this.data[i][j]) < 0 ? OfficeExcel.array_sum(this.data[i][j] + this.min): OfficeExcel.array_sum(this.data[i][j]) - this.min) / (this.max - this.min)) * (this.canvas.height - this._chartGutter._top - this._chartGutter._bottom);
}
// If the X axis pos is in the center, we need to half the height
if (xaxispos == 'center') {
height /= 2;
}
var startX = x + hmargin + (j * individualBarWidth);
if('auto' == this._otherProps._ylabels_count)
{
var startY = this.nullPositionOX - height;
}
if(this._otherProps._type == 'accumulative' || this._otherProps._autoGrouping == 'stackedPer')
{
individualBarWidth = ((width) - (2 * hmargin));
startX = hmargin + i*2*hmargin + (i * individualBarWidth) + this._chartGutter._left;
//считаем общую высоту
var allHeight = 0;
var allHeightAbNull = 0;
var allHeightLessNull = 0;
/*if(this.min < 0 && this.max <= 0 && this._otherProps._autoGrouping == 'stackedPer')
{
var asd;
}
else
{*/
for (var n = 0; n < j; ++n)
{
if(this.min < 0 && this.max > 0)
{
allHeight = ((OfficeExcel.array_sum(this.data[i][n]) < 0 ? OfficeExcel.array_sum(this.data[i][n]): OfficeExcel.array_sum(this.data[i][n])) / (this.max - this.min)) * (this.canvas.height - this._chartGutter._top - this._chartGutter._bottom);
}
else
allHeight = ((OfficeExcel.array_sum(this.data[i][n]) < 0 ? OfficeExcel.array_sum(this.data[i][n] + this.min): OfficeExcel.array_sum(this.data[i][n]) - this.min) / (this.max - this.min)) * (this.canvas.height - this._chartGutter._top - this._chartGutter._bottom);
if(allHeight > 0)
allHeightAbNull += allHeight;
else
allHeightLessNull += allHeight;
}
if(this.data[i][j] > 0)
startY = startY - allHeightAbNull;
else
startY = startY - allHeightLessNull;
//}
//startY =
}
if(height != 0)
{
//this.context.strokeRect(startX, startY, individualBarWidth, height);
this.context.fillRect(startX, startY, individualBarWidth, height);
}
y += height;
var formatCellTrue = formatCell;
if(this.arrFormatAdobeLabels && this.arrFormatAdobeLabels[i])
formatCellTrue = this.arrFormatAdobeLabels[i][j];
var catName;
if(this.catNameLabels && this.catNameLabels[i] && this.catNameLabels[i][j])
catName = this.catNameLabels[i][j];
this.coords.push([startX, startY, individualBarWidth, height, formatCellTrue, this.firstData[i][j], catName]);
}
}
this.context.closePath();
}
}
}
/**
* Draws the labels for the graph
*/
OfficeExcel.Bar.prototype.DrawLabels = function (isFormatCell)
{
var context = this.context;
var labels = this._otherProps._labels;
var scaleFactor = 1;
if(OfficeExcel.drawingCtxCharts && OfficeExcel.drawingCtxCharts.scaleFactor)
scaleFactor = OfficeExcel.drawingCtxCharts.scaleFactor;
// Draw the Y axis labels:
if (this._otherProps._ylabels) {
this.Drawlabels_top(isFormatCell);
this.Drawlabels_bottom(isFormatCell);
}
/**
* The X axis labels
*/
if (typeof(labels) == 'object' && labels && this._otherProps._xlabels) {
var yOffset = 13;
/**
* Text angle
*/
var angle = 0;
var halign = 'center';
// Draw the X axis labels
context.fillStyle = this._otherProps._text_color;
// How wide is each bar
var barWidth = (OfficeExcel.GetWidth(this) - this._chartGutter._right - this._chartGutter._left) / labels.length;
// Reset the xTickGap
var xTickGap = (OfficeExcel.GetWidth(this) - this._chartGutter._right - this._chartGutter._left) / labels.length
// Draw the X tickmarks
var i=0;
var font = this._otherProps._xlabels_font;
var bold = this._otherProps._xlabels_bold;
var textOptions =
{
color: this._otherProps._xlabels_color,
italic: this._otherProps._xlabels_italic,
underline: this._otherProps._xlabels_underline
}
var text_size = this._otherProps._xlabels_size;
if('auto' == this._otherProps._ylabels_count)
yOffset =+ 23;
var countLabels = 0;
var axisOxAngleOptions;
if(this._otherProps._axisOxAngleOptions && this._otherProps._axisOxAngleOptions.angle)
{
axisOxAngleOptions = this._otherProps._axisOxAngleOptions;
angle = this._otherProps._axisOxAngleOptions.angle;
}
var diffWidth;
var diffHeight;
for (var x=this._chartGutter._left + (xTickGap / 2); x<=OfficeExcel.GetWidth(this) - this._chartGutter._right; x+=xTickGap) {
if('auto' == this._otherProps._ylabels_count)
{
diffWidth = axisOxAngleOptions ? (axisOxAngleOptions[countLabels]*Math.sin(angle*Math.PI/180))/(4) : 0;
diffHeight = axisOxAngleOptions ? (axisOxAngleOptions[countLabels]*Math.cos(angle*Math.PI/180) - 10) : 0;
OfficeExcel.Text(context, font,
text_size,
x - diffWidth,
this.nullPositionOX + yOffset*scaleFactor + diffHeight,
String(labels[i++]),
null,
halign,
null,
angle,
null,
bold,
null,
textOptions);
}
countLabels++;
}
}
}
/**
* Draws the X axis at the top
*/
OfficeExcel.Bar.prototype.Drawlabels_top = function (isFormatCell)
{
this.context.beginPath();
this.context.fillStyle = this._otherProps._text_color;
this.context.strokeStyle = 'black';
if (this._otherProps._xaxispos == 'top') {
var context = this.context;
var interval = (this.grapharea * (1/5) );
var text_size = this._otherProps._ylabels_size;
var units_pre = this._otherProps._units_pre;
var units_post = this._otherProps._units_post;
var align = this._otherProps._yaxispos == 'left' ? 'right' : 'left';
var font = this._otherProps._ylabels_font;
var numYLabels = this._otherProps._ylabels_count;
var bold = this._otherProps._ylabels_bold;
var textOptions =
{
color: this._otherProps._ylabels_color,
italic: this._otherProps._ylabels_italic,
underline: this._otherProps._ylabels_underline
}
var xpos = this._otherProps._yaxispos == 'left' ? this._chartGutter._left - 5 : this.canvas.width - this._chartGutter._right + 5;
var boxed = false;
if('auto' == numYLabels)
{
var scale = OfficeExcel.array_reverse(this.scale);
/*var elemArr;
for (var i=0; i<this.scale.length; ++i) {
elemArr = (scale[scale.length - i])
if(0 == i)
elemArr = scale[scale.length - 1] - (scale[scale.length - 2] - scale[scale.length - 1])
OfficeExcel.Text(context,font,text_size,xpos,this._chartGutter._top + this.halfTextHeight + ((i/scale.length) * (this.grapharea) ),-elemArr,null,align,bounding,null,bgcolor);
}*/
for (var i=0; i<=this.scale.length; ++i) {
var elemArr;
elemArr = (scale[scale.length - i])
if(0 == i)
{
var floatKoff = 100000000000;
elemArr = Math.round(OfficeExcel.array_exp(scale[scale.length - 1] - (scale[scale.length - 2] - scale[scale.length - 1]))*floatKoff)/floatKoff ;
}
if(elemArr == 0)
OfficeExcel.Text(context,font,text_size,xpos - 5,this._chartGutter._top + this.halfTextHeight + ((i/this.scale.length) * (this.grapharea) ),OfficeExcel.numToFormatText(elemArr.toString(),isFormatCell),null, align, boxed, null, null, bold, null, textOptions);
else
OfficeExcel.Text(context,font,text_size,xpos - 5,this._chartGutter._top + this.halfTextHeight + ((i/this.scale.length) * (this.grapharea) ),OfficeExcel.numToFormatText("-" + elemArr.toString(),isFormatCell),null, align, boxed, null, null, bold, null, textOptions);
}
}
}
this.context.fill();
this.context.stroke();
}
/**
* Draws the X axdis at the bottom (the default)
*/
OfficeExcel.Bar.prototype.Drawlabels_bottom = function (isFormatCell)
{
this.context.beginPath();
this.context.fillStyle = this._otherProps._text_color;
this.context.strokeStyle = 'black';
if (this._otherProps._xaxispos != 'center' && this._otherProps._xaxispos != 'top') {
var interval = (this.grapharea * (1/5) );
var text_size = this._otherProps._xlabels_size;
var units_pre = this._otherProps._units_pre;
var units_post = this._otherProps._units_post;
var context = this.context;
var align = this._otherProps._yaxispos == 'left' ? 'right' : 'left';
var font = this._otherProps._xlabels_font;
var numYLabels = this._otherProps._ylabels_count;
var bold = this._otherProps._xlabels_bold;
var textOptions =
{
color: this._otherProps._xlabels_color,
italic: this._otherProps._xlabels_italic,
underline: this._otherProps._xlabels_underline
}
var xpos = this._otherProps._yaxispos == 'left' ? this._chartGutter._left - 5 : OfficeExcel.GetWidth(this) - this._chartGutter._right + 5;
var boxed = false;
// 1 label
if('auto' == numYLabels)
{
for (var i=0; i<this.scale.length; ++i) {
var stepY;
stepY = this.scale[this.scale.length -1 - i]
OfficeExcel.Text(context,font,text_size,xpos - 5,this._chartGutter._top + this.halfTextHeight + ((i/this.scale.length) * (this.grapharea) ),OfficeExcel.numToFormatText(stepY.toString(),isFormatCell) + units_post,null,align,boxed, null, null, bold, null, textOptions);
}
}
/**
* Show the minimum value if its not zero
*/
if (this._otherProps._ymin != 0 || 'auto' == numYLabels) {
if(typeof(this._otherProps._ymin) == 'string' && this._otherProps._ymin.search('E') != -1)
{
OfficeExcel.Text(context,
font,
text_size,
xpos - 5,
this.canvas.height - this._chartGutter._bottom,
this.min + units_post,
'center',
align,
boxed, null, null, bold, null, textOptions);
}
else{
OfficeExcel.Text(context,
font,
text_size,
xpos - 5,
this.canvas.height - this._chartGutter._bottom,
OfficeExcel.numToFormatText(this.min,isFormatCell) + units_post,
//OfficeExcel.number_format(this,(this.min.toFixed((this._otherProps._scale_decimals))), units_pre, units_post),
'center',
align,
boxed, null, null, bold, null, textOptions);
}
}
}
this.context.fill();
this.context.stroke();
}
OfficeExcel.Bar.prototype.DrawAboveLabels = function (isFormatCell)
{
// This bit draws the text labels that appear above the bars if requested
if (this._otherProps._labels_above && this.coords) {
// Get these variables outside of the loop
var xaxispos = this._otherProps._xaxispos;
var width = (this.canvas.width - this._chartGutter._left - this._chartGutter._right ) / this.data.length;
var hmargin = this._otherProps._hmargin;
var strokeStyle = this._otherProps._strokecolor;
var colors = this._otherProps._colors;
var startX;
var startY;
var individualBarWidth;
var value = 0;
var bold = this._otherProps._labels_above_bold;
var textOptions =
{
color: this._otherProps._labels_above_color,
italic: this._otherProps._labels_above_italic,
underline: this._otherProps._labels_above_underline
};
for(var i = 0; i < this.coords.length; i ++)
{
this.context.strokeStyle = 'rgba(0,0,0,0)';
startX = this.coords[i][0];
startY = this.coords[i][1];
individualBarWidth = this.coords[i][2];
//this._otherProps._labels_above_coords
var formatCellTrue = isFormatCell;
if(this.coords[i][4])
formatCellTrue = this.coords[i][4];
if(this.coords[i][4] == null && !this.coords[i][5])
value = "";
else if(this.coords[i][5] != undefined)
value = this.coords[i][5];
if(value != '')
value = OfficeExcel.numToFormatText(OfficeExcel.num_round(value),formatCellTrue);
//catName
if(this.catNameLabels && this.coords[i][6])
value = this.coords[i][6];
this.context.fillStyle = this._otherProps._text_color;
OfficeExcel.Text(this.context,
this._otherProps._labels_above_font,
typeof(this._otherProps._labels_above_size) == 'number' ? this._otherProps._labels_above_size : this._otherProps._text_size - 3,startX + (individualBarWidth / 2),
startY - 2,
//OfficeExcel.number_format(this, OfficeExcel.num_round(this.data[i][j]),this._otherProps._units_pre,this._otherProps._units_post),
value,
null,
'center',
null,
null,
null,
bold,
null,
textOptions);
}
}
}
\ No newline at end of file
"use strict";
if (typeof(window["OfficeExcel"]) == 'undefined') window["OfficeExcel"] = {};
OfficeExcel.Gutter = function()
{
this._left = 25;
this._right = 25;
this._top = 25;
this._bottom = 25;
}
OfficeExcel.OtherProps = function()
{
this._xmin = 0;
this._xmax = 0;
this._ymin = 0;
this._ymax = 0;
this._noaxes = false;
this._noxaxis = false;
this._noyaxis = false;
this._xaxispos = 'bottom';
this._yaxispos = 'left';
this._strokecolor = '#666';
this._hmargin = 5;
this._vmargin = 3;
this._numyticks = 10;
this._text_color = 'black';
this._text_font = 'Arial';
this._text_size = 10;
this._axis_color = 'black';
this._units_pre = '';
this._units_post = '';
this._scale_decimals = 0;
this._scale_point = '.';
this._scale_thousand = ',';
this._colors = ['rgb(0,0,255)', '#0f0', '#00f', '#ff0', '#0ff', '#0f0'];
this._radius = null;
this._exploded = 0;
this._area_border = true; // граница для всей области диаграммы
this._align = 'center';
this._xlabels = true;
this._ylabels = true;
this._ylabels_count = 'auto';
this._labels = [];
this._labels_above = false;
this._labels_above_size = null;
this._background_barcolor1 = 'rgba(0,0,0,0)';
this._background_barcolor2 = 'rgba(0,0,0,0)';
this._background_grid = true;
this._background_grid_color = '#ddd';
this._background_grid_width = 1;
this._background_grid_hsize = 20;
this._background_grid_vsize = 20;
this._background_grid_hlines = true;
this._background_grid_vlines = true;
this._background_grid_autofit = true;
this._background_grid_autofit_numhlines = 5;
this._background_grid_autofit_numvlines = 20;
this._background_vbars = null;
this._background_hbars = null;
this._variant = null;
this._stepped = false;
this._xticks = null;
this._linewidth = 1.01;
this._fillstyle = null;
this._smallyticks = 3;
this._ticksize = 3;
this._tickmarks = null; // can be reverse
this._tickmarks_dot_color = 'white';
this._key = [];
this._key_color_shape = 'square';
this._key_colors = null;
this._key_halign = 'right';
this._key_text_size = 10;
this._filled = false;
this._filled_range = false;
this._xaxis = true;
this._defaultcolor = 'white';
this._line = false;
this._line_linewidth = 1;
this._line_colors = ['green', 'red'];
this._line_stepped = false;
this._boxplot_width = 1;
this._boxplot_capped = true;
this._xscale = false;
this._xscale_units_pre = '';
this._xscale_units_post = '';
this._xscale_numlabels = 10;
this._boxplot = false;
}
\ No newline at end of file
"use strict";
if (typeof(window["OfficeExcel"]) == 'undefined') window["OfficeExcel"] = {type:'common'};
OfficeExcel.background = {};
/**
* Returns five values which are used as a nice scale
*
* @param max int The maximum value of the graph
* @param obj object The graph object
* @return array An appropriate scale
*/
OfficeExcel.getScale = function (max, obj, minVal, maxVal,yminVal,ymaxVal)
{
var original_max = max;
var mainObj = obj;
if(undefined == mainObj)
mainObj = bar;
if('auto' == mainObj._otherProps._ylabels_count)
{
if(( 'bar' == mainObj.type || 'line' == mainObj.type) && mainObj._otherProps._autoGrouping != undefined && mainObj._otherProps._autoGrouping == 'stackedPer')
{
var arrNew = mainObj.data;
if(typeof(arrNew[0]) == 'object')
{
var arrMin = [];
var arrMax = [];
for (var j=0; j < arrNew.length; j++) {
var newMax = 0;
var newMin = 0;
if('bar' == mainObj.type)
{
for (var i=0; i<arrNew[j].length; i++) {
if(arrNew[j][i] > 0)
newMax += arrNew[j][i]
else
newMin += arrNew[j][i]
}
arrMin[j] = newMin;
arrMax[j] = newMax;
}
else
{
min = Math.min.apply(null, arrNew[j]);
max = Math.max.apply(null, arrNew[j]);
arrMin[j] = min;
arrMax[j] = max;
}
}
min = Math.min.apply(null, arrMin);
max = Math.max.apply(null, arrMax);
}
else
{
min = minVal;
max = maxVal;
}
var newMin = min;
var newMax = max;
//находим максимум после преобразования
if('bar' != mainObj.type)
{
if(typeof(arrNew[0]) == 'object')
{
var arrMin = [];
var arrMax = [];
for (var j=0; j < arrNew.length; j++) {
newMin = Math.min.apply(null, arrNew[j]);
newMax = Math.max.apply(null, arrNew[j]);
arrMin[j] = newMin;
arrMax[j] = newMax;
}
newMin = Math.min.apply(null, arrMin);
newMax = Math.max.apply(null, arrMax);
}
else
{
newMin = Math.min.apply(null, arrNew);
newMax = Math.max.apply(null, arrNew);
}
}
if(max <= 0 && min < 0)
{
var tempVal = Math.abs(newMax)
newMax = Math.abs(newMin);
newMin = tempVal;
}
var massRes = [];
//шаг нужно высчитывать
var step = 10;
if(((newMax - newMin)/10) > 11 )
step = 20;
if('bar' == mainObj.type && max > 0 && min < 0)
step = 20;
var maxValue = 100;
//находим максимум
for (var i=0; i < 11; i++) {
if(newMax < 100 - step*i && newMax > 100 - step*(i+1))
maxValue = 100 - step*i;
}
if(maxValue > 100)
maxValue = 100;
//получаем массив
if(max <= 0 && min < 0)
{
if('bar' == mainObj.type)
{
for (var j=0; j < 11; j++) {
massRes[j] = (maxValue - step*j);
if(massRes[j] == step)
{
break;
}
}
mainObj._otherProps._xaxispos = 'top';
massRes = OfficeExcel.array_reverse(massRes);
mainObj._otherProps._ymax = massRes[massRes.length - 1];
mainObj._otherProps._ymin = 0;
}
else
{
for (var j=0; j < 11; j++) {
massRes[j] = -(maxValue - step - step*j);
if(massRes[j] == 0)
{
break;
}
}
mainObj._otherProps._ymax = 0;
mainObj._otherProps._ymin = OfficeExcel.array_exp(massRes[0] - step);
}
}
else if(max > 0 && min > 0)
{
for (var j=0; j < 11; j++) {
massRes[j] = maxValue - step*j;
if(massRes[j] - step == 0)
{
massRes = OfficeExcel.array_reverse(massRes);
break;
}
}
mainObj._otherProps._ymax = OfficeExcel.array_exp(maxValue);
mainObj._otherProps._ymin = OfficeExcel.array_exp(massRes[0] - step);
}
else
{
for (var j=0; j < 11; j++) {
massRes[j] = maxValue - step*j;
if(massRes[j] - step <= newMin)
{
massRes = OfficeExcel.array_reverse(massRes);
break;
}
}
mainObj._otherProps._ymax = OfficeExcel.array_exp(maxValue);
mainObj._otherProps._ymin = massRes[0] - step;
}
return OfficeExcel.array_exp(massRes);
}
else if('scatter' == mainObj.type || 'hbar' == mainObj.type)
{
var max1;
var arr = [];
//находим минимальное значение
var min;
var trueOX = false;
if('hbar' == mainObj.type)
{
trueOX = true;
if(typeof(mainObj.data[0]) == 'object')
{
var arrMin = [];
var arrMax = [];
for (var j=0; j < mainObj.data.length; j++) {
min = Math.min.apply(null, mainObj.data[j]);
max = Math.max.apply(null, mainObj.data[j]);
arrMin[j] = min;
arrMax[j] = max;
}
min = Math.min.apply(null, arrMin);
max = Math.max.apply(null, arrMax);
}
else
{
min = Math.min.apply(null, mainObj.data);
max = Math.max.apply(null, mainObj.data);
}
//min = minVal;
//max = maxVal;
}
if('scatter' == mainObj.type)
{
//в этом случае определяем значения для оси OX(max == true)
if(mainObj._otherProps._type == 'burse2')
{
var arrTemp = []
var k = 0;
for (var j=0; j < mainObj.data[0].length; j++) {
for (var i=0; i<5; i++)
{
arrTemp[k] = mainObj.data[0][j][1][i];
k++;
}
}
min = Math.min.apply(null, arrTemp);
max = Math.max.apply(null, arrTemp);
if(min == max && max == 0)
{
mainObj._otherProps._ymax = 1;
mainObj._otherProps._ymin = 0;
return [0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1]
}
}
else if(undefined != max && true == max)
{
min = minVal;
max = maxVal;
trueOX = true;
}
else
{
min = yminVal;
max = ymaxVal;
}
if((min == 0 && max == 0) ||(isNaN(min) && isNaN(max)))
return [0,0.2,0.4,0.6,0.8,1,1.2];
}
var degreeNum = 1;
var maxString = max.toExponential();
var minString = min.toExponential();
var floatKoff = 1000000000000;
if(maxString.search('e-') != -1 || minString.search('e-') != -1)
{
var partMin = minString.split('e-');
var partMax = maxString.split('e-');
if(partMin[1] != undefined)
degreeNum = Math.pow(10, partMin[1])
if(partMax[1] != undefined && ((parseFloat(partMin[1]) < parseFloat(partMax[1])) || partMin[1] == undefined))
degreeNum = Math.pow(10, partMax[1])
max = OfficeExcel.num_round(max*degreeNum);
min = OfficeExcel.num_round(min*degreeNum);
}
var axisXMax;
var axisXMin;
var stepOY;
var checkInput = false;
var greaterNull;
var chackBelowNull = false;
var checkIsMaxMin = false;
var arrForRealDiff = [];
if((min == 0 && max == 0) ||(isNaN(min) && isNaN(max)))
{
if( mainObj._otherProps._autoGrouping == 'stackedPer')
return [20,40,60,80,100];
else
return [0.2,0.4,0.6,0.8,1,1.2];
}
//подготовительная работы для дальнейшего вычисления шага
if(max >= 0 && min >= 0)
{
if(max == min)
{
checkIsMaxMin = true;
min = 0;
}
var diffPerMaxMin = ((max - min)/max)*100;
axisXMax = max + 0.05 * (max - min);
stepOY = (max-min)/4;
if(16.667 > diffPerMaxMin)
{
if(trueOX)
{
axisXMin = min;
greaterNull = (max - min)/4;
arrForRealDiff = [1.59595959,3.18181818,7.954545454];
}
else
{
axisXMin = min;
greaterNull = (max - min)/6;
arrForRealDiff = [1.51515151,3.03030303,7.57575757];
}
}
else
{
if(trueOX)
{
greaterNull = max/4;
arrForRealDiff = [1.66666666,3.33333333,8.33333333];
axisXMin = 0;
}
else
{
axisXMin = 0;
}
}
}
else if(max <= 0 && min <= 0)
{
if(max == min)
{
checkIsMaxMin = true;
max = 0;
}
var tempMax = max;
if(!trueOX)
mainObj._otherProps._xaxispos = 'top';
else
mainObj._otherProps._yaxispos = 'right';
max = Math.abs(min);
min = Math.abs(tempMax);
checkInput = true;
var diffPerMaxMin = Math.abs(((max - min)/max))*100;
axisXMax = max;
stepOY = (max-min)/4;
chackBelowNull = true;
if(16.667 > diffPerMaxMin)
{
axisXMin = min;
greaterNull = Math.abs((Math.abs(max) - Math.abs(min)))/6;
arrForRealDiff = [1.51515151,3.03030303,7.57575757];
}
else
{
if(trueOX)
{
greaterNull = max/4;
arrForRealDiff = [1.66666666,3.33333333,8.33333333];
axisXMin = 0;
}
else
{
axisXMin = 0;
}
}
}
else if(max > 0 && min < 0)
{
stepOY = (max + Math.abs(min))/4;
axisXMax = max;
axisXMin = min;
if(trueOX)
{
greaterNull = (Math.abs(max) + Math.abs(min))/4;
arrForRealDiff = [1.59090909,3.18181818,7.954545454]
}
else
{
greaterNull = Math.abs((Math.abs(max) + Math.abs(min)))/6;
arrForRealDiff = [1.51515151,3.03030303,7.57575757]
}
}
//приводим к первому порядку для дальнейших вычислений
var secPart = max.toString().split('.');
var numPow = 1;
if(secPart[1] && secPart[1].toString().search('e+') != -1 && secPart[0] && secPart[0].toString().length == 1)
{
var expNum = secPart[1].toString().split('e+');
numPow = Math.pow(10, expNum[1]);
}
else if(0 != secPart[0])
numPow = Math.pow(10, secPart[0].toString().length - 1)
max = max/numPow;
if(0 == max.toString().split('.')[0])
{
var tempMax = max;
var num = -1;
while(0 == tempMax.toString().split('.')[0])
{
tempMax = max;
numPow = Math.pow(10, num);
tempMax = tempMax/numPow;
num--;
}
max = tempMax;
}
var stepOYPart = stepOY.toString().split('.');
var numPowOY;
var tempVal;
if(0 != stepOYPart[0])
numPowOY = Math.pow(10, stepOYPart[0].toString().length - 1)
if(10 == stepOYPart[0])
numPowOY = 1;
if(0 == stepOYPart[0])
{
var tempMax = stepOY;
var num = -1;
while(0 == tempMax.toString().split('.')[0])
{
tempMax = stepOY;
numPowOY = Math.pow(10, num);
tempMax = tempMax/numPowOY;
num--;
}
}
//поиск шага
if(undefined != greaterNull)
{
var greaterNullTemp = greaterNull.toString().split('.'), greaterNullNum;
if(0 != greaterNullTemp[0])
greaterNullNum = Math.pow(10, greaterNullTemp[0].toString().length - 1)
if(0 == greaterNullTemp[0])
{
var tempMax = greaterNull;
var num = -1;
while(0 == tempMax.toString().split('.')[0])
{
tempMax = greaterNull;
greaterNullNum = Math.pow(10, num);
tempMax = tempMax/greaterNullNum;
num--;
}
}
else if(greaterNull.toString().indexOf("e+") > -1)
{
var splitString = greaterNull.toString().split("e+");
if(splitString[1])
greaterNullNum = Math.pow(10, parseFloat(splitString[1]));
}
greaterNull = greaterNull/greaterNullNum;
if(1 < greaterNull && arrForRealDiff[0] >= greaterNull)
greaterNull = 1;
else if(arrForRealDiff[0] < greaterNull && arrForRealDiff[1] >= greaterNull)
greaterNull = 2;
else if(arrForRealDiff[1] < greaterNull && arrForRealDiff[2] >= greaterNull)
greaterNull = 5;
else if(arrForRealDiff[2] < greaterNull && 10 >= greaterNull)
greaterNull = 10;
greaterNull = greaterNull*greaterNullNum;
stepOY = greaterNull;
}
arr[0] = 0;arr[1] = 1;arr[2] = 2;arr[3] = 5;arr[4] = 10;
//если максимальное значение больше числа из данного массива, меняем диапазон по оси OY
var arrMaxVal = [0,0.952380952,1.904761904,4.76190476,9.523809523]
//массив диапазонов
var arrDiffVal1 = [0,0.2,0.5,1,2]
if(axisXMin == 0 && undefined == greaterNull)//если разница между min и max такая, что не нужно масштабировать
{
var trueDiff = 1;
for (var i=0; i<arr.length; i++) {
if( max >= arr[i] && max <= arr[i+1])
{
var max1 = arr[i+1];
var trueMax;
var diff = max1/10;
trueDiff = diff;
var maxVal;
//проверяем есть ли переход в следующий диапазон
if(max > arrMaxVal[i+1])
{
trueDiff = arrDiffVal1[i+1]
}
}
}
stepOY = trueDiff*numPow;
}
if('hbar' == mainObj.type && mainObj._otherProps._autoGrouping == 'stackedPer')
{
if(axisXMin < 0 && axisXMax > 0)
{
var summVal = Math.abs(axisXMin) + Math.abs(axisXMax)
if(summVal <= 100)
stepOY = 10;
else if(summVal > 100 && summVal <= 139)
stepOY = 20;
else
stepOY = 50;
}
else
{
stepOY = 20;
}
}
//находим истинные min и max
var testDiff;
var axisXMinTest;
if(axisXMin == 0)
{
testDiff = stepOY/numPow;
axisXMinTest = axisXMin/numPow
}
else
{
testDiff = stepOY/numPowOY;
axisXMinTest = axisXMin/numPowOY;
}
var tempNum;
var countAfterPoint = 1;
if(undefined != axisXMinTest.toString().split('.')[1])
{
countAfterPoint = Math.pow(10, axisXMinTest.toString().split('.')[1].toString().length - 1)
}
if(1 == testDiff)
tempNum = testDiff/4;
else if(2 == testDiff)
tempNum = testDiff/4;
else if(5 == testDiff)
tempNum = testDiff/10;
else if(10 == testDiff)
tempNum = testDiff/20;
axisXMinTest = Math.floor(axisXMinTest);
while(0 != axisXMinTest%testDiff)
{
axisXMinTest = axisXMinTest - tempNum;
}
//возвращаем массив
var varMin = axisXMinTest*numPowOY;
var massRes = [];
var tempKoff = 100000000000;
varMin = OfficeExcel.num_round(varMin);
var lengthNum;
if(!trueOX)
{
if(chackBelowNull)
{
if(min == varMin && !checkIsMaxMin && min != 0 )
varMin = varMin - stepOY ;
varMin = varMin/degreeNum;
stepOY = stepOY/degreeNum;
axisXMax = axisXMax/degreeNum;
max = max/degreeNum;
if(undefined != varMin.toString().split('.')[1])
lengthNum = varMin.toString().split('.')[1].length;
for (var k=0; k <= 11; k++) {
massRes[k] = OfficeExcel.num_round(varMin + (k)*(stepOY));
if(massRes[k] > axisXMax)
{
break;
}
}
if(massRes[massRes.length - 1] == max && !checkIsMaxMin)
massRes[massRes.length] = massRes[massRes.length - 1] + stepOY;
mainObj._otherProps._ymax = -massRes[0];
mainObj._otherProps._ymin = -massRes[massRes.length - 1];
mainObj.max = -massRes[0];
}
else
{
if(min == varMin && !checkIsMaxMin)
varMin = varMin - stepOY ;
if(undefined != varMin.toString().split('.')[1])
lengthNum = varMin.toString().split('.')[1].length;
varMin = varMin/degreeNum;
stepOY = stepOY/degreeNum;
axisXMax = axisXMax/degreeNum;
max = max/degreeNum;
if(min == 0 && (mainObj._otherProps._type == 'burse2' || mainObj.type == 'scatter'))
varMin = 0;
if(max == 0 && mainObj._otherProps._type == 'burse2')
axisXMax = 0 + stepOY;
for (var k=0; k <= 11; k++) {
massRes[k] = OfficeExcel.num_round(varMin + (k)*(stepOY));
if(massRes[k] > axisXMax)
{
break;
}
}
if(massRes[massRes.length - 1] == max && !checkIsMaxMin)
massRes[massRes.length] = massRes[massRes.length - 1] + stepOY;
mainObj.max = massRes[massRes.length - 1];
mainObj._otherProps._ymax = massRes[massRes.length - 1];
mainObj._otherProps._ymin = massRes[0];
}
}
else
{
if(chackBelowNull)
{
if(min == varMin && !checkIsMaxMin && min != 0)
varMin = varMin - stepOY ;
if(undefined != varMin.toString().split('.')[1])
lengthNum = varMin.toString().split('.')[1].length;
varMin = varMin/degreeNum;
stepOY = stepOY/degreeNum;
axisXMax = axisXMax/degreeNum;
max = max/degreeNum;
for (var k=0; k <= 11; k++) {
massRes[k] = OfficeExcel.num_round(varMin + (k)*(stepOY));
if('hbar' == mainObj.type && mainObj._otherProps._autoGrouping == 'stackedPer')
{
if(massRes[k] >= original_max)
{
break;
}
}
else
{
if(massRes[k] > axisXMax)
{
break;
}
}
}
if(massRes[massRes.length - 1] == max && !checkIsMaxMin)
massRes[massRes.length] = massRes[massRes.length - 1] + stepOY;
mainObj._otherProps._xmax = -massRes[0];
mainObj._otherProps._xmin = -massRes[massRes.length - 1];
}
else
{
if(min == varMin && !checkIsMaxMin && 'hbar' != mainObj.type && mainObj._otherProps._autoGrouping != 'stackedPer')
varMin = varMin - stepOY ;
if(undefined != varMin.toString().split('.')[1])
lengthNum = varMin.toString().split('.')[1].length;
varMin = varMin/degreeNum;
stepOY = stepOY/degreeNum;
axisXMax = axisXMax/degreeNum;
max = max/degreeNum;
for (var k=0; k <= 11; k++) {
massRes[k] = OfficeExcel.num_round(parseFloat(varMin + (k)*(stepOY)));
if('hbar' == mainObj.type && mainObj._otherProps._autoGrouping == 'stackedPer')
{
if(massRes[k] >= original_max)
{
break;
}
}
else
{
if(massRes[k] > axisXMax)
{
break;
}
}
}
if(massRes[massRes.length - 1] == max && !checkIsMaxMin)
massRes[massRes.length] = massRes[massRes.length - 1] + stepOY;
mainObj._otherProps._xmax = massRes[massRes.length - 1];
mainObj._otherProps._xmin = massRes[0];
mainObj._otherProps._xmax = massRes[massRes.length - 1];
}
}
if('hbar' == mainObj.type)
{
massRes.splice(0,1);
}
return OfficeExcel.array_exp(massRes);
}
else
{
var max1;
var arr = [];
//находим минимальное значение
var min;
var max;
if('bar' == mainObj.type || 'hbar' == mainObj.type || 'radar' == mainObj.type)
{
if(mainObj._otherProps._type == 'accumulative')
{
//суммируем отрицательные и положительные значения
if(typeof(mainObj.data[0]) == 'object')
{
var arrMin = [];
var arrMax = [];
for (var j=0; j < mainObj.data.length; j++) {
var allHeightAbNull = 0;
var allHeightLessNull = 0;
for (var i=0; i < mainObj.data[j].length; i++)
{
if(mainObj.data[j][i] > 0)
allHeightAbNull += mainObj.data[j][i];
else
allHeightLessNull += mainObj.data[j][i];
}
arrMin[j] = allHeightLessNull;
arrMax[j] = allHeightAbNull;
}
min = Math.min.apply(null, arrMin);
max = Math.max.apply(null, arrMax);
}
else
{
min = Math.min.apply(null, mainObj.data);
max = Math.max.apply(null, mainObj.data);
}
}
else
{
min = minVal;
max = maxVal;
}
}
else
{
if(('line' == mainObj.type && mainObj._otherProps._autoGrouping == 'stacked' ) || 'line' != mainObj.type )
{
var arrMin = [];
var arrMax = [];
for (var j=0; j<mainObj.data.length; j++) {
min = Math.min.apply(null, mainObj.data[j]);
max = Math.max.apply(null, mainObj.data[j]);
arrMin[j] = min;
arrMax[j] = max;
}
min = Math.min.apply(null, arrMin);
max = Math.max.apply(null, arrMax);
}
else
{
min = minVal;
max = maxVal;
}
}
if(max == min)
{
if(max > 0)
min = 0;
else if(max < 0)
max = 0;
}
var degreeNum = 1;
var maxString = max.toExponential();
var minString = min.toExponential();
var floatKoff = 10000000000;
if(maxString.search('e-') != -1 || minString.search('e-') != -1)
{
var partMin = minString.split('e-');
var partMax = maxString.split('e-');
if(partMin[1] != undefined)
degreeNum = Math.pow(10, partMin[1])
if(partMax[1] != undefined && (parseFloat(partMin[1]) < parseFloat(partMax[1])))
degreeNum = Math.pow(10, partMax[1])
max = OfficeExcel.num_round(max*degreeNum);
min = OfficeExcel.num_round(min*degreeNum);
}
var axisXMax;
var axisXMin;
var stepOY;
var checkInput = false;
var greaterNull;
var firstMax = max;
var firstMin = min;
var arrForRealDiff = [];
if(max >= 0 && min >= 0)
{
var diffPerMaxMin = ((max - min)/max)*100;
axisXMax = max + 0.05 * (max - min);
stepOY = (max-min)/4;
if(16.667 > diffPerMaxMin)
{
axisXMin = min - ((max - min) / 2);
greaterNull = (max - min)/4;
arrForRealDiff = [1.5873,3.1745,7.93651]
}
else
{
axisXMin = 0;
}
}
else if(max <= 0 && min <= 0)
{
var tempMax = max;
mainObj._otherProps._xaxispos = 'top';
max = Math.abs(min);
min = Math.abs(tempMax);
checkInput = true;
var diffPerMaxMin = ((max - min)/max)*100;
axisXMax = max + 0.05 * (max - min);
stepOY = (max-min)/4;
if(16.667 > diffPerMaxMin)
{
axisXMin = min - ((max - min) / 2);
greaterNull = (max - min)/4;
arrForRealDiff = [1.5873,3.1745,7.93651]
}
else
{
axisXMin = 0;
}
}
else if(max > 0 && min < 0)
{
stepOY = (max + Math.abs(min))/4;
axisXMax = max + 0.05 * (max - min);
axisXMin = min + 0.05 * (min - max);
greaterNull = (Math.abs(max) + Math.abs(min))/6;
arrForRealDiff = [1.51515151,3.03030303,7.57575757]
}
//приведение к первому порядку для дальнейших вычислений
var secPart = max.toString().split('.');
var numPow = 1;
if(secPart[1] && secPart[1].toString().search('e+') != -1 && secPart[0] && secPart[0].toString().length == 1)
{
var expNum = secPart[1].toString().split('e+');
numPow = Math.pow(10, expNum[1]);
}
else if(0 != secPart[0])
numPow = Math.pow(10, secPart[0].toString().length - 1)
max = max/numPow;
if((min == 0 && max == 0) ||(isNaN(min) && isNaN(max)))
return [0.2,0.4,0.6,0.8,1,1.2];
if(0 == max.toString().split('.')[0])
{
var tempMax = max;
var num = -1;
while(0 == tempMax.toString().split('.')[0])
{
tempMax = max;
numPow = Math.pow(10, num);
tempMax = tempMax/numPow;
num--;
}
max = tempMax;
}
var stepOYPart = stepOY.toString().split('.');
var numPowOY;
var tempVal;
if(0 != stepOYPart[0])
numPowOY = Math.pow(10, stepOYPart[0].toString().length - 1)
if(10 == stepOYPart[0])
numPowOY = 1;
if(0 == stepOYPart[0])
{
var tempMax = stepOY;
var num = -1;
while(0 == tempMax.toString().split('.')[0])
{
tempMax = stepOY;
numPowOY = Math.pow(10, num);
tempMax = tempMax/numPowOY;
num--;
}
}
//поиск шага
if(undefined != greaterNull)
{
var greaterNullTemp = greaterNull.toString().split('.');
if(0 != greaterNullTemp[0])
greaterNullNum = Math.pow(10, greaterNullTemp[0].toString().length - 1)
if(0 == greaterNullTemp[0])
{
var tempMax = greaterNull;
var num = -1;
while(0 == tempMax.toString().split('.')[0])
{
tempMax = greaterNull;
greaterNullNum = Math.pow(10, num);
tempMax = tempMax/greaterNullNum;
num--;
}
}
greaterNull = greaterNull/greaterNullNum;
if(1 < greaterNull && arrForRealDiff[0] >= greaterNull)
greaterNull = 1;
else if(arrForRealDiff[0] < greaterNull && arrForRealDiff[1] >= greaterNull)
greaterNull = 2;
else if(arrForRealDiff[1] < greaterNull && arrForRealDiff[2] >= greaterNull)
greaterNull = 5;
else if(arrForRealDiff[2] < greaterNull && 10 >= greaterNull)
greaterNull = 10;
greaterNull = greaterNull*greaterNullNum;
stepOY = greaterNull;
}
arr[0] = 0;arr[1] = 1;arr[2] = 2;arr[3] = 5;arr[4] = 10;
//если максимальное значение больше числа из данного массива, меняем диапазон по оси OY
var arrMaxVal = [0,0.952380952,1.904761904,4.76190476,9.523809523]
//массив диапазонов
var arrDiffVal1 = [0,0.2,0.5,1,2]
if(axisXMin == 0)//если разница между min и max такая, что не нужно масштабировать
{
var trueDiff = 1;
for (var i=0; i<arr.length; i++) {
if( max >= arr[i] && max <= arr[i+1])
{
var max1 = arr[i+1];
var trueMax;
var diff = max1/10;
trueDiff = diff;
var maxVal;
//проверяем есть ли переход в следующий диапазон
if(max > arrMaxVal[i+1])
{
trueDiff = arrDiffVal1[i+1]
}
}
}
stepOY = trueDiff*numPow;
}
stepOY = OfficeExcel.num_round(stepOY);
//находим истинные min и max
var testDiff;
var axisXMinTest;
if(axisXMin == 0)
{
testDiff = stepOY/numPow;
axisXMinTest = axisXMin/numPow
}
else
{
testDiff = stepOY/numPowOY;
axisXMinTest = axisXMin/numPowOY;
}
var tempNum;
var countAfterPoint = 1;
if(undefined != axisXMinTest.toString().split('.')[1])
{
countAfterPoint = Math.pow(10, axisXMinTest.toString().split('.')[1].toString().length - 1)
}
var floatKoff = 10000000000;
if(0.5 == testDiff)
tempNum = testDiff/5;
else if(1 == testDiff)
tempNum = testDiff/4;
else if(2 == testDiff)
tempNum = testDiff/4;
else if(5 == testDiff)
tempNum = testDiff/10;
else
tempNum = testDiff/20;
if(testDiff != 0.5)
axisXMinTest = Math.floor(axisXMinTest);
else
{
axisXMinTest = Math.round(axisXMinTest*100)/100;
if(axisXMinTest.toString().split('.')[1] != undefined)
{
var lengthAfterPoint = axisXMinTest.toString().split('.')[1].length;
var l = 0;
while(axisXMinTest.toString().split('.')[1].length != 1)
{
axisXMinTest = axisXMinTest - Math.pow(10,-(lengthAfterPoint));
if(l > 9)
{
axisXMinTest = Math.floor(axisXMinTest);
break;
}
l++;
}
}
}
while(0 != axisXMinTest%testDiff)
{
axisXMinTest = axisXMinTest - tempNum;
if(testDiff == 0.5)
{
axisXMinTest = OfficeExcel.num_round(axisXMinTest);
}
}
//возвращаем массив
var varMin = axisXMinTest*numPowOY;
var massRes = [];
var tempKoff = 100000000000000;
varMin = OfficeExcel.num_round(varMin);
if(undefined != varMin.toString().split('.')[1])
lengthNum = varMin.toString().split('.')[1].length;
if('radar' == mainObj.type)
{
for (var k=0; k <= 11; k++) {
if(undefined != lengthNum)
massRes[k] = (varMin + (k)*(stepOY)).toFixed(lengthNum);
else
massRes[k] = varMin + (k)*(stepOY);
if(massRes[k] > axisXMax)
{
break;
}
}
if(firstMax < 0 && firstMin < 0)
{
for (var k=0; k < massRes.length; k++) {
massRes[k] = - massRes[k];
}
var tempMax = firstMax;
firstMax = firstMin;
firstMin = tempMax;
}
if(firstMax == massRes[massRes.length - 2])
massRes.splice(massRes.length - 1,massRes.length - 1);
if(firstMin == massRes[1])
massRes.splice(0,0);
if(firstMin < 0 && firstMax > 0)
{
for (var i=0; i <= massRes.length; i++) {
if(firstMin == massRes[i])
{
massRes.splice(0,i);
break;
}
}
}
if(firstMax < 0 && firstMin < 0)
massRes = OfficeExcel.array_reverse(massRes);
return [massRes,min,max];
}
else if('line' == mainObj.type && max > 0 && min < 0)
{
//varMin = varMin + stepOY;
varMin = varMin/degreeNum;
stepOY = stepOY/degreeNum;
axisXMax = axisXMax/degreeNum;
for (var k=0; k <= 11; k++) {
massRes[k] = OfficeExcel.num_round((parseFloat(varMin + (k+1)*(stepOY))));
if(massRes[k] > axisXMax)
{
break;
}
}
}
else
{
varMin = varMin/degreeNum;
stepOY = stepOY/degreeNum;
axisXMax = axisXMax/degreeNum;
for (var k=0; k <= 11; k++) {
massRes[k] = OfficeExcel.num_round((varMin + (k+1)*(stepOY)));
if(massRes[k] > axisXMax)
{
break;
}
}
}
if('hbar' == mainObj.type)
{
mainObj._otherProps._xmin = massRes[0] - stepOY;
mainObj._otherProps._xmax = massRes[massRes.length - 1];
}
else if('line' == mainObj.type && max > 0 && min < 0)
{
mainObj._otherProps._ymax = massRes[massRes.length - 1];
mainObj._otherProps._ymin = OfficeExcel.num_round(OfficeExcel.array_exp(massRes[0] - stepOY));
}
else
{
mainObj._otherProps._ymax = massRes[massRes.length - 1];
mainObj._otherProps._ymin = OfficeExcel.num_round(OfficeExcel.array_exp(massRes[0] - stepOY));
}
return OfficeExcel.array_exp(massRes);
}
}
if (max <= 1) {
if (max > 0.5) {
return [0.2,0.4,0.6,0.8, Number(1).toFixed(1)];
} else if (max >= 0.1) {
return [0.1,0.2,0.3,0.4,0.5];
} else {
var tmp = max;
var exp = 0;
while (tmp < 1.01) {
exp += 1;
tmp *= 10;
}
var ret = ['2e-' + exp, '4e-' + exp, '6e-' + exp, '8e-' + exp, '10e-' + exp];
if (max <= ('5e-' + exp)) {
ret = ['1e-' + exp, '2e-' + exp, '3e-' + exp, '4e-' + exp, '5e-' + exp];
}
return ret;
}
}
// Take off any decimals
if (String(max).indexOf('.') > 0) {
max = String(max).replace(/\.\d+$/, '');
}
var interval = Math.pow(10, Number(String(Number(max)).length - 1));
var topValue = interval;
while (topValue < max) {
topValue += (interval / 2);
}
// Handles cases where the max is (for example) 50.5
if (Number(original_max) > Number(topValue)) {
topValue += (interval / 2);
}
// Custom if the max is greater than 5 and less than 10
if (max < 10) {
topValue = (Number(original_max) <= 5 ? 5 : 10);
}
return [topValue * 0.2, topValue * 0.4, topValue * 0.6, topValue * 0.8, topValue];
}
/**
* Returns the maximum numeric value which is in an array
*
* @param array arr The array (can also be a number, in which case it's returned as-is)
* @param int Whether to ignore signs (ie negative/positive)
* @return int The maximum value in the array
*/
OfficeExcel.array_max = function (arr)
{
var max = null;
if (typeof(arr) == 'number') {
return arr;
}
for (var i=0; i<arr.length; ++i) {
if (typeof(arr[i]) == 'number') {
var val = arguments[1] ? Math.abs(arr[i]) : arr[i];
if (typeof(max) == 'number') {
max = Math.max(max, val);
} else {
max = val;
}
}
}
return max;
}
OfficeExcel.array_exp = function (arr)
{
var maxDig = 1000000000;
var minDig = 0.000000001;
var floatKoff = 100000000000;
if(typeof(arr) == 'number')
{
if(arr < 0)
maxDig = 100000000;
if(Math.abs(arr) > maxDig)
{
var tmp = Math.abs(arr);
var exp = 0;
while (tmp > 9) {
exp += 1;
tmp /= 10;
}
if(arr < 0)
tmp *= -1;
arr = tmp + "E+" + exp;
}
}
else
{
for (var i=0; i<arr.length; ++i) {
maxDig = 1000000000
if(arr[i] < 0)
maxDig = 100000000;
if(Math.abs(arr[i]) > maxDig)
{
var tmp = Math.abs(arr[i]);
var exp = 0;
while (tmp > 9) {
exp += 1;
tmp /= 10;
}
tmp = Math.round(tmp*floatKoff)/floatKoff
if(arr[i] < 0)
tmp *= -1;
arr[i] = tmp + "E+" + exp;
}
}
}
return arr;
}
OfficeExcel.num_round = function (num)
{
if(num.toString() && num.toString().indexOf('e+') == -1 && isNaN(parseFloat(num)))
return num;
var floatKoff = 100000000000;
if(num.toString() && num.toString().indexOf('e+') > -1)
{
var parseVal = num.toString().split("e+");
var roundVal = Math.round(parseFloat(parseVal[0])*floatKoff)/floatKoff;
var changeSymbol = roundVal.toString() + "e+" + parseVal[1];
num = parseFloat(changeSymbol);
}
num = Math.round(num*floatKoff)/floatKoff ;
return num;
}
/**
* An array sum function
*
* @param array arr The array to calculate the total of
* @return int The summed total of the arrays elements
*/
OfficeExcel.array_sum = function (arr)
{
// Allow integers
if (typeof(arr) == 'number') {
return arr;
}
var i, sum;
var len = arr.length;
for(var i=0,sum=0;i<len;sum+=arr[i++]);
return sum;
}
OfficeExcel.Text = function (context, font, size, x, y, text)
{
var drwContext = OfficeExcel.drawingCtxCharts;
var scale = 1;
if(drwContext)
{
scale = drwContext.scaleFactor;
drwContext.setCanvas(bar.canvas);
var fontProp = window["Asc"].FontProperties;
if(!fontProp)
fontProp = FontProperties;
context = drwContext;
// Need these now the angle can be specified, ie defaults for the former two args
if (typeof(arguments[6]) == null) arguments[6] = 'bottom'; // Vertical alignment. Default to bottom/baseline
if (typeof(arguments[7]) == null) arguments[7] = 'left'; // Horizontal alignment. Default to left
if (typeof(arguments[8]) == null) arguments[8] = null; // Show a bounding box. Useful for positioning during development. Defaults to false
if (typeof(arguments[9]) == null) arguments[9] = 0; // Angle (IN DEGREES) that the text should be drawn at. 0 is middle right, and it goes clockwise
if (typeof(arguments[12]) == null) arguments[12] = true; // Whether the bounding box has the placement indicator
// The alignment is recorded here for purposes of Opera compatibility
if (navigator.userAgent.indexOf('Opera') != -1) {
context.canvas.__OfficeExcel_valign__ = arguments[6];
context.canvas.__OfficeExcel_halign__ = arguments[7];
}
// First, translate to x/y coords
/*context.save();
context.canvas.__OfficeExcel_originalx__ = x;
context.canvas.__OfficeExcel_originaly__ = y;
context.translate(x, y);*/
var italic = arguments[13] && arguments[13].italic ? arguments[13].italic : false;
var underline = arguments[13] && arguments[13].underline ? arguments[13].underline : false;
var ascFont = new fontProp(font, size, arguments[11], italic, underline);
context.setFont(ascFont);
var width;
var textSize, size1;
if(typeof text != 'string')
text = text.toString();
if(text != "")
textSize = context.measureText(text,1);
// Vertical alignment - defaults to bottom
if (arguments[6]) {
var vAlign = arguments[6];
if(textSize)
size1 = (textSize.height/0.75)*scale;
else
size1 = size;
if (vAlign == 'center') {
y = y + size1 / 2;
//context.translate(0, size / 2);
} else if (vAlign == 'top') {
y = y + size1;
//context.translate(0, size);
}
}
// Hoeizontal alignment - defaults to left
if (arguments[7] && textSize) {
var hAlign = arguments[7];
width = (textSize.width/0.75)*scale;
if (hAlign) {
if (hAlign == 'center') {
//context.translate(-1 * (width / 2), 0)
x = x - width/2;
} else if (hAlign == 'right') {
x = x - width;
//context.translate(-1 * width, 0)
}
}
}
if(arguments[13] && arguments[13].color)
context.setFillStyle(arguments[13].color);
else
context.setFillStyle(new CColor(0, 0, 0));
x = x/(scale);
y = y/(scale);
// Rotate the canvas if need be
if (arguments[9] && textSize) {
var textOptions =
{
font: ascFont,
width: textSize.width,
height: textSize.height,
x: x*0.75,
y: y*0.75
};
OfficeExcel.drawTurnedText(context,textOptions, text, arguments[9]);
}
if(!arguments[9])
{
context.fillText(text, x*0.75, y*0.75);
context.lineWidth = 1;
}
//context.restore();
}
}
OfficeExcel.drawTurnedText = function(drawingCtx,textOptions, text, angle)
{
var cx = textOptions.x;
var cy = textOptions.y;
var textWidth = 0;
var textHeight = 0;
var font = textOptions.font;
var size = textOptions.size;
var asc = window["Asc"];
if(!angle)
angle = 90;
if(window["editor"])
{
var m = new CMatrix();
drawingCtx.setFont(font);
m.Rotate(angle);
drawingCtx.transform(m.sx, m.shy, m.shx, m.sy, m.tx, m.ty);
var invertM = m.CreateDublicate().Invert();
var newX = invertM.TransformPointX(cx,cy);
var newY = invertM.TransformPointY(cx,cy);
drawingCtx.fillText(text, newX, newY, 0, 0, angle);
}
else
{
var m = new asc.Matrix();
m.rotate(angle, 0);
var mbt = new asc.Matrix();
mbt.translate(cx + textWidth, cy + textHeight);
drawingCtx.setFont(font, angle);
drawingCtx.setTextTransform(m.sx, m.shy, m.shx, m.sy, m.tx, m.ty);
drawingCtx.setTransform(mbt.sx, mbt.shy, mbt.shx, mbt.sy, mbt.tx, mbt.ty);
drawingCtx.updateTransforms();
drawingCtx.fillText(text, 0, 0, 0, 0, angle);
drawingCtx.resetTransforms();
}
}
// Clear canvas settings and fill rect
OfficeExcel.Clear = function (canvas, color)
{
var context = canvas.getContext('2d');
if (OfficeExcel.isIE8() && !color)
color = 'white';
// Clear canvas
if (!color || (color && color == 'transparent')) {
context.clearRect(0, 0, canvas.width, canvas.height);
// Reset the globalCompositeOperation
context.globalCompositeOperation = 'source-over';
} else {
context.fillStyle = color;
context = canvas.getContext('2d');
context.beginPath();
if (OfficeExcel.isIE8())
context.fillRect(0, 0, canvas.width, canvas.height);
else
context.fillRect(-10, -10, canvas.width + 20, canvas.height + 20);
context.fill();
}
}
OfficeExcel.background.Draw = function (obj)
{
var context = obj.context;
var height = 0;
var gutterLeft = obj._chartGutter._left;
var gutterRight = obj._chartGutter._right;
var gutterTop = obj._chartGutter._top;
var gutterBottom = obj._chartGutter._bottom;
context.fillStyle = obj._otherProps._text_color;
obj.context.beginPath();
// Draw the horizontal bars
context.fillStyle = obj._otherProps._background_barcolor1;
height = (OfficeExcel.GetHeight(obj) - gutterBottom);
for (var i=gutterTop; i < height ; i+=80) {
obj.context.fillRect(gutterLeft, i, OfficeExcel.GetWidth(obj) - gutterLeft - gutterRight, Math.min(40, OfficeExcel.GetHeight(obj) - gutterBottom - i) );
}
context.fillStyle = obj._otherProps._background_barcolor2;
height = (OfficeExcel.GetHeight(obj) - gutterBottom);
for (var i= (40 + gutterTop); i < height; i+=80) {
obj.context.fillRect(gutterLeft, i, OfficeExcel.GetWidth(obj) - gutterLeft - gutterRight, i + 40 > (OfficeExcel.GetHeight(obj) - gutterBottom) ? OfficeExcel.GetHeight(obj) - (gutterBottom + i) : 40);
}
context.stroke();
// Draw the background grid
if (obj._otherProps._background_grid) {
// If autofit is specified, use the .numhlines and .numvlines along with the width to work
// out the hsize and vsize
if (obj._otherProps._background_grid_autofit) {
var vsize = ((obj.canvas.width - gutterLeft - gutterRight)) / obj._otherProps._background_grid_autofit_numvlines;
var hsize = (obj.canvas.height - gutterTop - gutterBottom) / (obj._otherProps._background_grid_autofit_numhlines);
if(vsize > -1 && vsize < 1)
vsize = 1;
if(hsize > -1 && hsize < 1)
hsize = 1;
obj._otherProps._background_grid_vsize = vsize;
obj._otherProps._background_grid_hsize = hsize;
}
context.beginPath();
context.lineWidth = obj._otherProps._background_grid_width ? obj._otherProps._background_grid_width : 1;
context.strokeStyle = obj._otherProps._background_grid_color;
// Draw the horizontal lines
if (obj._otherProps._background_grid_hlines) {
height = (OfficeExcel.GetHeight(obj) - gutterBottom - gutterTop);
for (var y = gutterTop; y <= height + gutterTop + 1; y+=obj._otherProps._background_grid_hsize) {
if((y + obj._otherProps._background_grid_hsize) > (height + gutterTop + 1))
{
y = height + gutterTop;
context.moveTo(gutterLeft, AA(this, y));
context.lineTo(OfficeExcel.GetWidth(obj) - gutterRight, AA(this, y));
break;
}
else
{
context.moveTo(gutterLeft, AA(this, y));
context.lineTo(OfficeExcel.GetWidth(obj) - gutterRight, AA(this, y));
}
}
}
if (obj._otherProps._background_grid_vlines) {
// Draw the vertical lines
var width = (obj.canvas.width - gutterRight - gutterLeft)
for (var x=gutterLeft; x<=width + gutterLeft + 1; x+=obj._otherProps._background_grid_vsize) {
if((x + obj._otherProps._background_grid_vsize) > width + gutterLeft + 1)
{
x = width + gutterLeft;
context.moveTo(AA(this, x), gutterTop);
context.lineTo(AA(this, x), obj.canvas.height - gutterBottom);
context.stroke();
break;
}
context.moveTo(AA(this, x), gutterTop);
context.lineTo(AA(this, x), obj.canvas.height - gutterBottom);
context.stroke();
}
}
context.stroke();
}
}
// Makes a clone of an array
OfficeExcel.array_clone = function (obj)
{
if(obj == null || typeof(obj) != 'object')
return obj;
var temp = [];
for (var i = 0;i < obj.length; ++i) {
if (typeof(obj[i]) == 'number')
temp[i] = (function (arg) {return Number(arg);})(obj[i]);
else if (typeof(obj[i]) == 'string')
temp[i] = (function (arg) {return String(arg);})(obj[i]);
else if (typeof(obj[i]) == 'function')
temp[i] = obj[i];
else
temp[i] = OfficeExcel.array_clone(obj[i]);
}
return temp;
}
/**
* This function reverses an array
*/
OfficeExcel.array_reverse = function (arr)
{
var newarr = [];
for (var i=arr.length - 1; i>=0; i--) {
newarr.push(arr[i]);
}
return newarr;
}
OfficeExcel.numToFormatText = function (value,format)
{
if(format == 'General')
return value;
var numFormat = oNumFormatCache.get(format);
var aFormatedValue = numFormat.format(value, CellValueType.number, 15);
if(aFormatedValue[0].t == '#')
return "";
return aFormatedValue[0].text;
}
OfficeExcel.number_format = function (obj, num)
{
var i;
var prepend = arguments[2] ? String(arguments[2]) : '';
var append = arguments[3] ? String(arguments[3]) : '';
var output = '';
var decimal = '';
var decimal_seperator = obj._otherProps._scale_point ? obj._otherProps._scale_point : '.';
var thousand_seperator = obj._otherProps._scale_thousand ? obj._otherProps._scale_thousand : ',';
RegExp.$1 = '';
var i,j;
// Ignore the preformatted version of "1e-2"
if (String(num).indexOf('e') > 0) {
return String(prepend + String(num) + append);
}
// We need then number as a string
num = String(num);
// Take off the decimal part - we re-append it later
if (num.indexOf('.') > 0) {
num = num.replace(/\.(.*)/, '');
decimal = RegExp.$1;
}
// Thousand seperator
//var seperator = arguments[1] ? String(arguments[1]) : ',';
var seperator = thousand_seperator;
/**
* Work backwards adding the thousand seperators
*/
var foundPoint;
for (var i=(num.length - 1),j=0; i>=0; j++,i--) {
var character = num.charAt(i);
if ( j % 3 == 0 && j != 0) {
output += seperator;
}
/**
* Build the output
*/
output += character;
}
/**
* Now need to reverse the string
*/
var rev = output;
output = '';
for (var i=(rev.length - 1); i>=0; i--) {
output += rev.charAt(i);
}
// Tidy up
//output = output.replace(/^-,/, '-');
if (output.indexOf('-' + obj._otherProps._scale_thousand) == 0) {
output = '-' + output.substr(('-' + obj._otherProps._scale_thousand).length);
}
// Reappend the decimal
if (decimal.length) {
output = output + decimal_seperator + decimal;
decimal = '';
RegExp.$1 = '';
}
// Minor bugette
if (output.charAt(0) == '-') {
output = output.replace(/-/, '');
prepend = '-' + prepend;
}
return prepend + output + append;
}
/**
* Draws horizontal coloured bars on something like the bar, line or scatter
*/
OfficeExcel.DrawBars = function (obj)
{
var hbars = obj._otherProps._background_hbars;
/**
* Draws a horizontal bar
*/
obj.context.beginPath();
for (var i=0; i<hbars.length; ++i) {
// If null is specified as the "height", set it to the upper max value
if (hbars[i][1] == null) {
hbars[i][1] = obj.max;
// If the first index plus the second index is greater than the max value, adjust accordingly
} else if (hbars[i][0] + hbars[i][1] > obj.max) {
hbars[i][1] = obj.max - hbars[i][0];
}
// If height is negative, and the abs() value is greater than .max, use a negative max instead
if (Math.abs(hbars[i][1]) > obj.max) {
hbars[i][1] = -1 * obj.max;
}
// If start point is greater than max, change it to max
if (Math.abs(hbars[i][0]) > obj.max) {
hbars[i][0] = obj.max;
}
// If start point plus height is less than negative max, use the negative max plus the start point
if (hbars[i][0] + hbars[i][1] < (-1 * obj.max) ) {
hbars[i][1] = -1 * (obj.max + hbars[i][0]);
}
var ystart = (obj.grapharea - ((hbars[i][0] / obj.max) * obj.grapharea));
var height = (Math.min(hbars[i][1], obj.max - hbars[i][0]) / obj.max) * obj.grapharea;
// Account for the X axis being in the center
if (obj._otherProps._xaxispos == 'center') {
ystart /= 2;
height /= 2;
}
ystart += obj._chartGutter._top
var x = obj._chartGutter._left;
var y = ystart - height;
var w = obj.canvas.width - obj._chartGutter._left - obj._chartGutter._right;
var h = height;
// Accommodate Opera :-/
if (navigator.userAgent.indexOf('Opera') != -1 && obj._otherProps._xaxispos == 'center' && h < 0) {
h *= -1;
y = y - h;
}
/**
* Account for X axis at the top
*/
if (obj._otherProps._xaxispos == 'top') {
y = obj.canvas.height - y;
h *= -1;
}
obj.context.fillStyle = hbars[i][2];
obj.context.fillRect(x, y, w, h);
}
obj.context.fill();
}
// Compatibility canvas browser
OfficeExcel.CanvasBrowserCompat = function (context)
{
if (!context) {
return;
}
if (!context.measureText) {
// This emulates the measureText() function
context.measureText = function (text)
{
var textObj = document.createElement('DIV');
textObj.innerHTML = text;
textObj.style.backgroundColor = 'white';
textObj.style.position = 'absolute';
textObj.style.top = -100
textObj.style.left = 0;
document.body.appendChild(textObj);
var width = {width: textObj.offsetWidth};
textObj.style.display = 'none';
return width;
}
}
if (!context.fillText) {
// This emulates the fillText() method
context.fillText = function (text, targetX, targetY)
{
return false;
}
}
// If IE8, add addEventListener()
if (!context.canvas.addEventListener) {
window.addEventListener = function (ev, func, bubble)
{
return this.attachEvent('on' + ev, func);
}
context.canvas.addEventListener = function (ev, func, bubble)
{
return this.attachEvent('on' + ev, func);
}
}
}
// Checks the browser for traces of MSIE8
OfficeExcel.isIE8 = function ()
{
return navigator.userAgent.indexOf('MSIE 8') > 0;
}
// Checks the browser for traces of MSIE7
OfficeExcel.isIE7 = function ()
{
return navigator.userAgent.indexOf('MSIE 7') > 0;
}
// Checks the browser for traces of MSIE9
OfficeExcel.isOld = function ()
{
return OfficeExcel.isIE7() || OfficeExcel.isIE8();
}
/**
* These are older functions that were used before the move to seperate gutter settings
*/
OfficeExcel.GetHeight=function(obj){return obj.canvas.height;}
OfficeExcel.GetWidth=function(obj){return obj.canvas.width;}
/**
* This function skirts the annoying canvas anti-aliasing
*
* @param object obj The object
* @param number value The number to round
*/
function AA (obj, value)
{
var value = String(value).replace(/^(\d+)\.\d+/, '$1');
var newvalue = Number(value) + 0.5;
return (newvalue - value) >= 0 ? newvalue : Math.floor(value);
}
OfficeExcel.background.DrawArea = function (obj)
{
// Don't draw the axes?
if (obj._otherProps._noaxes)
return;
obj.context.lineWidth = 1;
obj.context.lineCap = 'butt';
obj.context.strokeStyle = obj._otherProps._axis_color;
obj.context.beginPath();
obj.context.fillStyle = obj._otherProps._background_image_color;
obj.context.fillRect(0,0,obj.canvas.width,obj.canvas.height);
// border
if ( !g_bChartPreview && obj._otherProps._area_border ) {
obj.context.beginPath();
obj.context.rect(0, 0, obj.canvas.width,obj.canvas.height);
obj.context.strokeStyle = "black";
}
obj.context.stroke();
}
\ No newline at end of file
"use strict";
OfficeExcel.DrawKey = function (obj, key, colors)
{
var context = obj.context;
context.lineWidth = 1;
context.beginPath();
/**
* Account for null values in the key
*/
var key_non_null = [];
var colors_non_null = [];
for (var i=0; i<key.length; ++i) {
if (key[i] != null) {
colors_non_null.push(colors[i]);
key_non_null.push(key[i]);
}
}
key = key_non_null;
colors = colors_non_null;
OfficeExcel.DrawKey_graph(obj, key, colors);
}
OfficeExcel.DrawKey_graph = function (obj, key, colors)
{
var canvas = obj.canvas;
var context = obj.context;
var text_size = typeof(obj._otherProps._key_text_size) == 'number' ? obj._otherProps._key_text_size : obj._otherProps._text_size;
var text_font = obj._otherProps._key_text_font;
var gutterLeft = obj._chartGutter._left;
var gutterRight = obj._chartGutter._right;
var gutterTop = obj._chartGutter._top;
var hpos = obj._otherProps._yaxispos == 'right' ? gutterLeft + 10 : OfficeExcel.GetWidth(obj) - gutterRight - 10;
var vpos = gutterTop + 10;
var blob_size = text_size; // The blob of color
var width = 0;
var scale = 1;
if(OfficeExcel.drawingCtxCharts && OfficeExcel.drawingCtxCharts.scaleFactor)
scale = OfficeExcel.drawingCtxCharts.scaleFactor;
var sizeLine = 26*scale;
if(bar._otherProps._key_color_shape != 'line')
sizeLine = 8*scale;
// Need to set this so that measuring the text works out OK
context.font = text_size + 'pt ' + obj._otherProps._text_font;
// Work out the longest bit of text
for (var i=0; i<key.length; ++i) {
width = Math.max(width, context.measureText(key[i]).width);
}
width += 5;
width += blob_size;
width += 5;
width += 5;
width += 5;
/**
* Now we know the width, we can move the key left more accurately
*/
if ( obj._otherProps._yaxispos == 'left'
|| (obj.type == 'pie' && !obj._otherProps._yaxispos)
|| (obj.type == 'hbar' && !obj._otherProps._yaxispos)
|| (obj.type == 'hbar' && obj._otherProps._yaxispos == 'center')
|| (obj.type == 'rscatter' && !obj._otherProps._yaxispos)
|| (obj.type == 'radar' && !obj._otherProps._yaxispos)
|| (obj.type == 'rose' && !obj._otherProps._yaxispos)
|| (obj.type == 'funnel' && !obj._otherProps._yaxispos)
|| (obj.type == 'vprogress' && !obj._otherProps._yaxispos)
|| (obj.type == 'hprogress' && !obj._otherProps._yaxispos)
) {
hpos -= width;
}
/**
* Horizontal alignment
*/
var scale = 1;
if(OfficeExcel.drawingCtxCharts && OfficeExcel.drawingCtxCharts.scaleFactor)
scale = OfficeExcel.drawingCtxCharts.scaleFactor;
var widthAllKey = 70*(key.length);
/*if((obj._otherProps._key_halign == 'top' || obj._otherProps._key_halign == 'bottom' ))
{
if(widthAllKey > obj.canvas.width - 50)
{
var lengthKey = Math.round((obj.canvas.width - 50)/(70));
if(lengthKey == 0)
lengthKey = 1;
obj._otherProps._key = obj._otherProps._key.slice(0,lengthKey);
key = obj._otherProps._key;
}
widthAllKey = 70*(key.length);
}*/
var drwContext = OfficeExcel.drawingCtxCharts;
var font = getFontProperties("key");
if(obj._otherProps._key_halign == 'top' || obj._otherProps._key_halign == 'bottom' && key.length != 0)
{
widthAllKey = 0;
var widthEveryElemKey = [];
var widthKey;
for(var l = 0; l < key.length; l++)
{
var props1 = getMaxPropertiesText(drwContext,font,key[l]);
if(bar._otherProps._key_max_width)
widthKey = bar._otherProps._key_max_width;
else
widthKey = props1.width;
widthAllKey += widthKey + (3)*scale + sizeLine;
widthEveryElemKey[l] = widthKey + (3)*scale + sizeLine;
}
}
var heigthTextKey = 24;
if(key && key.length != 0)
{
var props = getMaxPropertiesText(drwContext,font,bar._otherProps._key);
heigthTextKey = (drwContext.getHeightText()/0.75)*scale;
}
var heightKeyVer = key.length*heigthTextKey;
if (typeof(obj._otherProps._key_halign) == 'string') {
if (obj._otherProps._key_halign == 'left') {
hpos = calculatePosiitionObjects("key_hpos");
vpos = canvas.height/2 - heightKeyVer/2;
} else if (obj._otherProps._key_halign == 'right') {
hpos = calculatePosiitionObjects("key_hpos");
vpos = canvas.height/2 - heightKeyVer/2;
}
else if (obj._otherProps._key_halign == 'top') {
hpos = canvas.width/2 - widthAllKey/2;
vpos = calculatePosiitionObjects("key_hpos");
}
else if (obj._otherProps._key_halign == 'bottom') {
hpos = canvas.width/2 - widthAllKey/2;
vpos = calculatePosiitionObjects("key_hpos");
}
}
// Draw the box that the key resides in
context.beginPath();
context.fillStyle = 'white';
context.strokeStyle = 'black';
if('radar' == obj.type)
{
colors = obj._otherProps._strokecolor
}
context.beginPath();
/**
* Custom colors for the key
*/
if (obj._otherProps._key_colors) {
colors = obj._otherProps._key_colors;
}
//colors = OfficeExcel.array_reverse(colors);
// Draw the labels given
if( obj._otherProps._autoGrouping == 'stacked' || obj._otherProps._autoGrouping == 'stackedPer' || obj._otherProps._type != undefined && obj._otherProps._type == 'accumulative' && 'bar' == obj.type)
{
colors = OfficeExcel.array_reverse(colors)
if('hbar' != obj.type)
key = OfficeExcel.array_reverse(key)
}
if(obj._otherProps._key_halign == 'bottom' || obj._otherProps._key_halign == 'top')
{
var levels;
if(obj._otherProps._key_levels)
levels = obj._otherProps._key_levels;
var gVpos = vpos;
//если не умещается легенда, делаем её в несколько строк
if(levels && levels.length)
{
var widthCurKey = 0;
for(var i = 0; i < levels[0].length; i++)
{
widthCurKey += widthEveryElemKey[i];
}
hpos = (canvas.width - widthCurKey)/2;
var startLevelNum = 0;
var elemeNum = 0;;
for (var i = 0; i < levels.length; i++) {
startLevelNum = elemeNum;
for(var j = 0; j < levels[i].length; j++)
{
// Draw the blob of color
var leftDiff = 0;
for(var n = startLevelNum ; n < elemeNum; n++)
{
leftDiff += widthEveryElemKey[n];
}
if(obj._otherProps._key_halign == 'top')
vpos = gVpos + props.height*(i)*scale;
else
vpos = gVpos - props.height*(levels.length - i - 1)*scale;
if (obj._otherProps._key_color_shape == 'line') {
context.beginPath();
context.strokeStyle = colors[elemeNum];
context.lineWidth = '2.7'
context.moveTo(hpos + leftDiff + 2*scale,vpos - props.height/2);
context.lineTo(hpos + leftDiff + sizeLine + 2*scale, vpos - props.height/2);
context.stroke();
} else {
context.fillStyle = colors[elemeNum];
context.fillRect(hpos + leftDiff + 2*scale, vpos - 7*scale, 7*scale, 7*scale);
}
context.beginPath();
context.fillStyle = 'black';
OfficeExcel.Text(context,
text_font,
text_size,
hpos + leftDiff + sizeLine + 3*scale,
vpos,
levels[i][j]);
elemeNum++;
}
}
}
else
{
for (var i=0; i<key.length; i++) {
// Draw the blob of color
var leftDiff = 0;
for(var n = 0 ; n < i; n++)
{
leftDiff += widthEveryElemKey[n];
}
if (obj._otherProps._key_color_shape == 'circle') {
context.beginPath();
context.strokeStyle = 'rgba(0,0,0,0)';
context.fillStyle = colors[i];
context.arc(hpos + 5 + (blob_size / 2), vpos + (5 * j) + (text_size * j) - text_size + (blob_size / 2), blob_size / 2, 0, 6.26, 0);
context.fill();
} else if (obj._otherProps._key_color_shape == 'line') {
context.beginPath();
context.strokeStyle = colors[i];
context.lineWidth = '2.7'
context.moveTo(hpos + leftDiff + 2*scale,vpos - props.height/2);
context.lineTo(hpos + leftDiff + sizeLine + 2*scale, vpos - props.height/2);
context.stroke();
} else {
context.fillStyle = colors[i];
context.fillRect(hpos + leftDiff + 2*scale, vpos - 7*scale, 7*scale, 7*scale);
//context.fillRect(hpos, vpos + (10 * j) + (text_size * j) - text_size, 22, obj._otherProps._linewidth);
}
context.beginPath();
context.fillStyle = 'black';
OfficeExcel.Text(context,
text_font,
text_size,
hpos + leftDiff + sizeLine + 3*scale,
vpos,
key[i]);
}
}
}
else
{
for (var i=key.length - 1; i>=0; i--) {
var j = Number(i) + 1;
// Draw the blob of color
var diffKeyAndLine = 3*scale;
if (obj._otherProps._key_color_shape == 'circle') {
context.beginPath();
context.strokeStyle = 'rgba(0,0,0,0)';
context.fillStyle = colors[i];
context.arc(hpos + 5 + (blob_size / 2), vpos + (5 * j) + (text_size * j) - text_size + (blob_size / 2), blob_size / 2, 0, 6.26, 0);
context.fill();
} else if (obj._otherProps._key_color_shape == 'line') {
context.beginPath();
context.strokeStyle = colors[i];
context.lineWidth = '2.7'
context.moveTo(hpos, vpos + heigthTextKey*j - heigthTextKey + (heigthTextKey / 2));
context.lineTo(hpos + sizeLine, vpos + heigthTextKey*j - heigthTextKey + (heigthTextKey / 2));
//context.moveTo(hpos + 5, vpos + (5 * j) + (text_size * j) - text_size + (blob_size / 2));
//context.lineTo(hpos + blob_size + 5, vpos + (5 * j) + (text_size * j) - text_size + (blob_size / 2));
context.stroke();
} else {
context.fillStyle = colors[i];
context.fillRect(hpos, vpos + heigthTextKey*j - props.height/2 - 7*scale, 7*scale, 7*scale);
diffKeyAndLine = 5;
}
context.beginPath();
context.fillStyle = 'black';
OfficeExcel.Text(context,
text_font,
text_size,
hpos + sizeLine + diffKeyAndLine,
vpos + heigthTextKey*j - props.height/2,
key[i]);
}
}
context.fill();
}
\ No newline at end of file
"use strict";
if (typeof(window["OfficeExcel"]) == 'undefined') window["OfficeExcel"] = {};
OfficeExcel.HBar = function (chartCanvas, data)
{
this.canvas = chartCanvas;
this.context = (this.canvas && this.canvas.getContext) ? this.canvas.getContext("2d") : null;
this.canvas.__object__ = this;
this.data = data;
this.type = 'hbar';
this.coords = [];
/**
* Compatibility with older browsers
*/
OfficeExcel.CanvasBrowserCompat(this.context);
// Chart gutter
this._chartGutter = new OfficeExcel.Gutter();
// Other Props
this._otherProps = new OfficeExcel.OtherProps();
this.max = 0;
}
/**
* The function you call to draw the bar chart
*/
OfficeExcel.HBar.prototype.Draw = function (xmin,xmax,ymin,ymax,isSkip,isFormatCell)
{
/**
* Stop the coords array from growing uncontrollably
*/
this.coords = [];
this.max = 0;
var value = 0;
for (var i=0; i<this.data.length; ++i) {
if (typeof(this.data[i]) == 'object') {
value = Number(OfficeExcel.array_max(this.data[i], true));
} else {
value = Number(Math.abs(this.data[i]));
}
this.max = Math.max(Math.abs(this.max), Math.abs(value));
}
this.scale = OfficeExcel.getScale(this.max, this);
//определяем куда ставить ось
var numNull = this._otherProps._background_grid_autofit_numhlines;
var arrTemp = [], min, max;
if(typeof(this.data[0]) == 'object')
{
var arrMin = [];
var arrMax = [];
for (var j=0; j < this.data.length; j++) {
min = Math.min.apply(null, this.data[j]);
max = Math.max.apply(null, this.data[j]);
arrMin[j] = min;
arrMax[j] = max;
}
min = Math.min.apply(null, arrMin);
max = Math.max.apply(null, arrMax);
}
else
{
min = Math.min.apply(null, this.data);
max = Math.max.apply(null, this.data);
}
if(min >= 0 && max >= 0)
{
numNull = 0;
}
else if(min <= 0 && max <= 0)
{
numNull = this._otherProps._background_grid_autofit_numvlines;
}
else
{
for (var i=0; i<this.scale.length; i++)
{
if(this.scale[i] == 0)
{
numNull = i + 1;
break;
}
}
}
var nullPosition;
if(0 == numNull)
nullPosition = 0;
else
nullPosition = (this.canvas.width - this._chartGutter._left - this._chartGutter._right)/(this._otherProps._background_grid_autofit_numvlines)*numNull;
this.nullPositionOX = nullPosition + this._chartGutter._left;
/**
* Work out a few things. They need to be here because they depend on things you can change before you
* call Draw() but after you instantiate the object
*/
this.graphwidth = this.canvas.width - this._chartGutter._left - this._chartGutter._right;
this.graphheight = this.canvas.height - this._chartGutter._top - this._chartGutter._bottom;
this.halfgrapharea = this.grapharea / 2;
this.halfTextHeight = this._otherProps._text_size / 2;
//Draw Area
OfficeExcel.background.DrawArea(this);
// Progressively Draw the chart
OfficeExcel.background.Draw(this);
this.Drawbars(isFormatCell);
this.DrawAxes();
this.DrawLabels(isFormatCell);
// Draw the key if necessary
if (this._otherProps._key.length) {
OfficeExcel.DrawKey(this, this._otherProps._key, this._otherProps._colors);
}
}
/**
* This draws the axes
*/
OfficeExcel.HBar.prototype.DrawAxes = function ()
{
var halfway = (this.graphwidth / 2) + this._chartGutter._left;
this.context.beginPath();
this.context.lineWidth = 1;
this.context.strokeStyle = this._otherProps._axis_color;
// Draw the Y axis
if(!this._otherProps._noyaxis)
{
if('auto' == this._otherProps._ylabels_count)
{
this.context.moveTo(AA(this, this.nullPositionOX), this._chartGutter._top);
this.context.lineTo(AA(this, this.nullPositionOX), this.canvas.height - this._chartGutter._bottom);
//this.nullPositionOX = this._chartGutter._left + nullPosition;
//this.min = min;
//this.max = max;
//context.moveTo(this._chartGutter._left, AA(this, this.canvas.height - this._chartGutter._bottom - nullPosition));
//context.lineTo(this.canvas.width - this._chartGutter._right, AA(this, this.canvas.height - this._chartGutter._bottom - nullPosition));
}
}
// Draw the X axis
if(!this._otherProps._noxaxis)
{
this.context.moveTo(this._chartGutter._left, AA(this, OfficeExcel.GetHeight(this) - this._chartGutter._bottom));
this.context.lineTo(this.canvas.width - this._chartGutter._right, AA(this, this.canvas.height - this._chartGutter._bottom));
}
// Draw the Y tickmarks
if(!this._otherProps._noyaxis)
{
var yTickGap = (this.canvas.height - this._chartGutter._top - this._chartGutter._bottom) / this.data.length;
for (var y=this._chartGutter._top; y<=(this.canvas.height - this._chartGutter._bottom) + 1; y+=yTickGap) {
if('auto' == this._otherProps._ylabels_count)
{
if( (y + yTickGap) > (this.canvas.height - this._chartGutter._bottom))
{
y = this.canvas.height - this._chartGutter._bottom;
this.context.moveTo(this.nullPositionOX, AA(this, y));
this.context.lineTo( this.nullPositionOX - 3, AA(this, y));
break;
}
y = this.canvas.height - this._chartGutter._bottom;
this.context.moveTo(this.nullPositionOX, AA(this, y));
this.context.lineTo( this.nullPositionOX - 3, AA(this, y));
}
}
}
// Draw the X tickmarks
var xTickGap, yStart, yEnd;
if(!this._otherProps._noxaxis)
{
xTickGap = (this.canvas.width - this._chartGutter._left - this._chartGutter._right ) / (this.scale.length);
yStart = this.canvas.height - this._chartGutter._bottom;
yEnd = (this.canvas.height - this._chartGutter._bottom) + 5;
for (var x=(this.canvas.width - this._chartGutter._right), i=0; this._otherProps._yaxispos == 'center' ? x>=this._chartGutter._left : x>=this._chartGutter._left; x-=xTickGap) {
if (this._otherProps._yaxispos != 'center' || i != 5) {
this.context.moveTo(AA(this, x), yStart);
this.context.lineTo(AA(this, x), yEnd);
}
i++;
}
}
this.context.stroke();
}
/**
* This draws the labels for the graph
*/
OfficeExcel.HBar.prototype.DrawLabels = function (isFormatCell)
{
var context = this.context;
var units_pre = this._otherProps._units_pre;
var units_post = this._otherProps._units_post;
var text_size = this._otherProps._xlabels_size;
var font = this._otherProps._xlabels_font;
var scaleFactor = 1;
if(OfficeExcel.drawingCtxCharts && OfficeExcel.drawingCtxCharts.scaleFactor)
scaleFactor = OfficeExcel.drawingCtxCharts.scaleFactor;
/**
* Draw the X axis labels
*/
if (this._otherProps._xlabels) {
var gap = 13*scaleFactor;
this.context.beginPath();
this.context.fillStyle = this._otherProps._text_color;
var bold = this._otherProps._xlabels_bold;
var textOptions =
{
color: this._otherProps._xlabels_color,
underline: this._otherProps._xlabels_underline,
italic: this._otherProps._xlabels_italic
}
if('auto' == this._otherProps._ylabels_count)
{
var elemArr;
if(typeof(this.data[0]) == 'object')
{
var arrMin = [];
var arrMax = [];
var min, max;
for (var j=0; j < this.data.length; j++) {
min = Math.min.apply(null, this.data[j]);
max = Math.max.apply(null, this.data[j]);
arrMin[j] = min;
arrMax[j] = max;
}
var minX = Math.min.apply(null, arrMin);
var maxX = Math.max.apply(null, arrMax);
}
else
{
var minX = Math.min.apply(null, this.data);
var maxX = Math.max.apply(null, this.data);
}
if(minX < 0 && maxX <= 0)
{
var xRevScale = OfficeExcel.array_reverse(this.scale);
for (var i=0; i<=xRevScale.length; i++) {
elemArr = xRevScale[i]
if(xRevScale.length == i)
{
var floatKoff = 100000000000;
elemArr = Math.round(OfficeExcel.array_exp(xRevScale[xRevScale.length - 1] - (Math.abs(xRevScale[1] - xRevScale[0])))*floatKoff)/floatKoff ;
}
if(elemArr == 0)
OfficeExcel.Text(context, font, text_size, this._chartGutter._left + (this.graphwidth * (i/xRevScale.length)), this._chartGutter._top + this.halfTextHeight*scaleFactor + this.graphheight + gap, OfficeExcel.numToFormatText(elemArr.toString(),isFormatCell) + units_post, 'center', 'center', false, null, null, bold, null,textOptions);
else
OfficeExcel.Text(context, font, text_size, this._chartGutter._left + (this.graphwidth * (i/xRevScale.length)), this._chartGutter._top + this.halfTextHeight*scaleFactor + this.graphheight + gap,OfficeExcel.numToFormatText("-" + elemArr.toString(),isFormatCell) + units_post, 'center', 'center', false, null, null, bold, null,textOptions);
}
this._otherProps._background_grid_autofit_numvlines = xRevScale.length;
this._otherProps._numxticks = xRevScale.length;
}
else
{
for (var i=0; i<=this.scale.length; i++) {
elemArr = this.scale[i-1]
if(0 == i)
{
var floatKoff = 100000000000;
elemArr = Math.round(OfficeExcel.array_exp(this.scale[0] - (this.scale[1] - this.scale[0]))*floatKoff)/floatKoff ;
}
OfficeExcel.Text(context, font, text_size, this._chartGutter._left + (this.graphwidth * (i/this.scale.length)), this._chartGutter._top + this.halfTextHeight*scaleFactor + this.graphheight + gap, (OfficeExcel.numToFormatText(elemArr.toString(),isFormatCell) + units_post), 'center', 'center', false, null, null, bold, null,textOptions);
}
this._otherProps._background_grid_autofit_numvlines = this.scale.length;
this._otherProps._numxticks = this.scale.length;
}
}
this.context.fill();
this.context.stroke();
}
/**
* The Y axis labels
*/
if (typeof(this._otherProps._labels) == 'object' && this._otherProps._ylabels) {
var xOffset = 11;
text_size = this._otherProps._ylabels_size;
font = this._otherProps._ylabels_font;
var bold = this._otherProps._ylabels_bold;
var textOptions =
{
color: this._otherProps._ylabels_color,
underline: this._otherProps._ylabels_underline,
italic: this._otherProps._ylabels_italic
}
// Draw the X axis labels
this.context.fillStyle = this._otherProps._text_color;
// How wide is each bar
var barHeight = (OfficeExcel.GetHeight(this) - this._chartGutter._top - this._chartGutter._bottom ) / this._otherProps._labels.length;
// Reset the xTickGap
var yTickGap = (OfficeExcel.GetHeight(this) - this._chartGutter._top - this._chartGutter._bottom) / this._otherProps._labels.length
// Draw the X tickmarks
var i=0;
if('auto' == this._otherProps._ylabels_count)
{
for (var y=this._chartGutter._top + (yTickGap / 2); y<=OfficeExcel.GetHeight(this) - this._chartGutter._bottom; y+=yTickGap) {
OfficeExcel.Text(this.context, font,text_size, this.nullPositionOX - xOffset,y,String(this._otherProps._labels[i++]),'center','right', false, null, null, bold, null,textOptions);
}
}
}
}
/**
* This function draws the actual bars
*/
OfficeExcel.HBar.prototype.Drawbars = function (isFormatCell)
{
this.context.lineWidth = 1;
this.context.strokeStyle = this._otherProps._strokecolor;
this.context.fillStyle = this._otherProps._colors[0];
var prevX = 0;
var prevY = 0;
/**
* Work out the max value
*/
if (this._otherProps._xmax) {
if('auto' == this._otherProps._ylabels_count)
{
var lengSc = this.scale.length;
this.max = this.scale[lengSc -1];
this._otherProps._background_grid_autofit_numhlines = lengSc;
this._otherProps._numxticks = lengSc;
}
} else {
if('auto' == this._otherProps._ylabels_count)
{
var lengSc = this.scale.length;
this.max = this.scale[lengSc -1];
this._otherProps._background_grid_autofit_numhlines = lengSc;
this._otherProps._numxticks = lengSc;
}
}
if (this._otherProps._scale_decimals == null && Number(this.max) == 1) {
this._otherProps._scale_decimals = 1;
}
/*******************************************************
* This is here to facilitate sequential colors
*******************************************************/
var colorIdx = 0;
/**
* The bars are drawn HERE
*/
var graphwidth = (this.canvas.width - this._chartGutter._left - this._chartGutter._right);
var halfwidth = graphwidth / 2;
for (var i=0; i<this.data.length; ++i) {
// Work out the width and height
var width;
if('auto' == this._otherProps._ylabels_count)
{
var tempMax = this._otherProps._xmax;
var tempMin = this._otherProps._xmin;
this.max = tempMax;
this.min = tempMin;
if(this.min < 0 && this.max > 0)
{
width = (OfficeExcel.array_sum(this.data[i])) / (tempMax - tempMin) * (graphwidth);
}
else if(this.min < 0 && this.max < 0)
width = ((OfficeExcel.array_sum(this.data[i]) - tempMin) / (tempMax - tempMin)) * (graphwidth);
else if(this.min < 0 && this.max == 0)
width = ((OfficeExcel.array_sum(this.data[i]) < 0 ? OfficeExcel.array_sum(this.data[i]): OfficeExcel.array_sum(this.data[i]) - tempMin) / (tempMax - tempMin)) * (graphwidth);
else
width = ((OfficeExcel.array_sum(this.data[i]) < 0 ? OfficeExcel.array_sum(this.data[i] + tempMin): OfficeExcel.array_sum(this.data[i]) - tempMin) / (tempMax - tempMin)) * (graphwidth);
}
var height = this.graphheight / this.data.length;
var orig_height = height;
var x;
if('auto' == this._otherProps._ylabels_count)
{
if(this.min < 0 && this.max < 0)
x = this.nullPositionOX - width;
else if(0 > OfficeExcel.array_sum(this.data[i]))
x = this.nullPositionOX + 2*width;
else
x = this.nullPositionOX;
}
var y = this._chartGutter._top + (i * height);
var vmargin = this._otherProps._vmargin;
// Account for negative lengths - Some browsers (eg Chrome) don't like a negative value
if (width < 0) {
x -= width;
width = Math.abs(width);
}
/**
* Draw the bar
*/
this.context.beginPath();
if (typeof(this.data[i]) == 'number') {
var barHeight = height - (2 * vmargin);
var barWidth = ((this.data[i] - this._otherProps._xmin) / (this.max - this._otherProps._xmin)) * this.graphwidth;
var barX = this._chartGutter._left;
// Account for Y axis pos
if (this._otherProps._yaxispos == 'center') {
barWidth /= 2;
barX += halfwidth;
if (this.data[i] < 0) {
barWidth = (Math.abs(this.data[i]) - this._otherProps._xmin) / (this.max - this._otherProps._xmin);
barWidth = barWidth * (this.graphwidth / 2);
barX = ((this.graphwidth / 2) + this._chartGutter._left) - barWidth;
}
}
if('auto' == this._otherProps._ylabels_count)
{
barWidth = width;
barX = x;
}
// Set the fill color
this.context.strokeStyle = this._otherProps._strokecolor;
this.context.fillStyle = this._otherProps._colors[0];
this.context.strokeRect(barX, this._chartGutter._top + (i * height) + this._otherProps._vmargin, barWidth, barHeight);
this.context.fillRect(barX, this._chartGutter._top + (i * height) + this._otherProps._vmargin, barWidth, barHeight);
this.coords.push([barX,
y + vmargin,
barWidth,
height - (2 * vmargin),
this.context.fillStyle,
this.data[i],
true]);
/**
* Stacked bar chart
*/
} else if (typeof(this.data[i]) == 'object') {
for (var j=0; j<this.data[i].length; ++j) {
// Set the fill/stroke colors
this.context.strokeStyle = this._otherProps._strokecolor;
if(this._otherProps._colors[j])
this.context.fillStyle = this._otherProps._colors[j];
var width;
if('auto' == this._otherProps._ylabels_count)
{
var tempMax = this._otherProps._xmax;
var tempMin = this._otherProps._xmin;
this.max = tempMax;
this.min = tempMin;
if(this.min < 0 && this.max > 0)
{
width = (OfficeExcel.array_sum(this.data[i][j])) / (tempMax - tempMin) * (graphwidth);
}
else if(this.min < 0 && this.max < 0)
width = ((OfficeExcel.array_sum(this.data[i][j]) - tempMin) / (tempMax - tempMin)) * (graphwidth);
else if(this.min < 0 && this.max == 0)
width = graphwidth - ((OfficeExcel.array_sum(this.data[i][j]) - tempMin) / (tempMax - tempMin)) * (graphwidth);
else
width = ((OfficeExcel.array_sum(this.data[i][j]) < 0 ? OfficeExcel.array_sum(this.data[i][j] + tempMin): OfficeExcel.array_sum(this.data[i][j]) - tempMin) / (tempMax - tempMin)) * (graphwidth);
}
var height = this.graphheight / this.data.length;
var orig_height = height;
var individualBarHeight = (height - (2 * vmargin)) / this.data[i].length;
var startX;
if('auto' == this._otherProps._ylabels_count)
{
if(this.min < 0 && this.max < 0)
startX = this.nullPositionOX - width;
else if(0 > OfficeExcel.array_sum(this.data[i][j]) && this.min < 0 && this.max > 0)
startX = this.nullPositionOX
else if(0 > OfficeExcel.array_sum(this.data[i][j]))
startX = this.nullPositionOX - width;
else
startX = this.nullPositionOX;
}
var startY = y + vmargin + (j * individualBarHeight);
if(this._otherProps._autoGrouping == 'stackedPer' || this._otherProps._autoGrouping == 'stacked')
{
startY = y + vmargin + (0*individualBarHeight);
individualBarHeight = individualBarHeight*this.data[0].length
}
// Account for the Y axis being in the middle
if (this._otherProps._yaxispos == 'center') {
width /= 2;
startX += halfwidth;
}
if (width < 0) {
startX += width;
width *= -1;
}
//this.context.strokeRect(startX, startY, width, individualBarHeight);
if(width != 0)
this.context.fillRect(startX, startY, width, individualBarHeight);
var catName;
if(this.catNameLabels && this.catNameLabels[i] && this.catNameLabels[i][j])
{
catName = this.catNameLabels[i][j];
}
this.coords.push([startX,
startY,
width,
individualBarHeight,
this.context.fillStyle,
this.data[i][j],
true,
this.arrFormatAdobeLabels[i][j],
this.firstData[i][j],
catName
]);
}
}
this.context.closePath();
}
this.context.fill();
this.context.stroke();
this.RedrawBars(isFormatCell);
}
/**
* This function goes over the bars after they been drawn, so that upwards shadows are underneath the bars
*/
OfficeExcel.HBar.prototype.RedrawBars = function (format)
{
var coords = this.coords;
var font = this._otherProps._labels_above_font;
var size = this._otherProps._labels_above_size;
var color = this._otherProps._text_color;
var bold = this._otherProps._labels_above_bold;
var textOptions =
{
color: this._otherProps._labels_above_color,
underline: this._otherProps._labels_above_underline,
italic: this._otherProps._labels_above_italic
};
this.context.strokeStyle = this._otherProps._strokecolor;
for (var i=0; i<coords.length; ++i) {
/**
* Draw labels "above" the bar
*/
if (this._otherProps._labels_above && coords[i][6]) {
this.context.fillStyle = color;
this.context.strokeStyle = 'black';
var border = (coords[i][0] + coords[i][2] + 7 + this.context.measureText(this._otherProps._units_pre + this.coords[i][5] + this._otherProps._units_post).width) > OfficeExcel.GetWidth(this) ? true : false;
var textLabel = this.coords[i][5];
var formatLabel = format;
if(this.coords[i][7])
formatLabel = this.coords[i][7];
if(this.coords[i][9])
textLabel = this.coords[i][9];
else if(this.coords[i][8])
textLabel = this.coords[i][8];
else
continue;
if(this.coords[i][7] == null && !textLabel)
textLabel = "";
if(textLabel != '' && !this.coords[i][9])
textLabel = OfficeExcel.numToFormatText(OfficeExcel.num_round(textLabel),formatLabel);
OfficeExcel.Text(this.context,
font,
size,
coords[i][0] + coords[i][2] + (border ? -5 : 5),
coords[i][1] + (coords[i][3] / 2),
//OfficeExcel.number_format(this, OfficeExcel.num_round(this.coords[i][5]), this._otherProps._units_pre, this._otherProps._units_post),
textLabel,
'center',
border ? 'right' : 'left',
null,
null,
border ? 'rgba(255,255,255,0.9)' : null, bold, null, textOptions);
}
}
}
\ No newline at end of file
"use strict";
if (typeof(window["OfficeExcel"]) == 'undefined') window["OfficeExcel"] = {};
OfficeExcel.Line = function (chartCanvas, data)
{
this.canvas = chartCanvas;
this.context = (this.canvas && this.canvas.getContext) ? this.canvas.getContext("2d") : null;
this.canvas.__object__ = this;
this.type = 'line';
this.max = 0;
this.coords = [];
this.coords2 = [];
this.hasnegativevalues = false;
this.data = data;
// Compatibility canvas browser
OfficeExcel.CanvasBrowserCompat(this.context);
// Chart gutter
this._chartGutter = new OfficeExcel.Gutter();
// Other Props
this._otherProps = new OfficeExcel.OtherProps();
// Change null arguments to empty arrays
for (var i = 1; i < arguments.length; ++i) {
if ('null' == typeof(arguments[i]) || !arguments[i])
arguments[i] = [];
}
// Store the original data.
this.original_data = [];
for (var i = 1; i < arguments.length; ++i) {
if (arguments[i] && 'object' == typeof(arguments[i]) && arguments[i][0] && 'object' == typeof(arguments[i][0]) && arguments[i][0].length) {
var tmp = [];
for (var j = 0; j < arguments[i].length; ++j)
tmp[j] = OfficeExcel.array_clone(arguments[i][j]);
for (var j = 0; j < tmp.length; ++j)
this.original_data[this.original_data.length] = OfficeExcel.array_clone(tmp[j]);
} else
this.original_data[this.original_data.length] = OfficeExcel.array_clone(arguments[i]);
}
/**
* Store the data here as one big array
*/
this.data_arr = [];
for (var i=1; i<arguments.length; ++i) {
for (var j=0; j<arguments[i].length; ++j) {
this.data_arr.push(arguments[i][j]);
}
}
}
// Draw the line chart
OfficeExcel.Line.prototype.Draw = function (min,max,ymin,ymax,isSkip,isFormatCell)
{
// MUST be the FIRST thing done - Hand over drawing to the bar chart if it's a combo back to the Bar chart
if (this.__bar__ && !arguments[0]) {
this.__bar__.Draw();
return;
}
// Reset the data back to that which was initially supplied
this.data = OfficeExcel.array_clone(this.original_data);
// Reset max
this.max = 0;
// Max y
if (this._otherProps._ymax && this.scale) {
this.max = this._otherProps._ymax;
this.min = this._otherProps._ymin ? this._otherProps._ymin : 0;
for (var dataset = 0; dataset < this.data.length; ++dataset) {
for (var datapoint = 0; datapoint < this.data[dataset].length; ++datapoint) {
// Check for negative values
this.hasnegativevalues = (this.data[dataset][datapoint] < 0) || this.hasnegativevalues;
}
}
} else {
this.min = this._otherProps._ymin ? this._otherProps._ymin : 0;
this.scale = OfficeExcel.getScale(Math.abs(parseFloat(this.max)),this,min,max);
//this.max = this.scale[4] ? this.scale[4] : 0;
if('auto' == this._otherProps._ylabels_count)
{
var lengSc = this.scale.length;
this.max = this.scale[lengSc -1];
this.min = this._otherProps._ymin;
this._otherProps._background_grid_autofit_numhlines = lengSc;
this._otherProps._numyticks = lengSc;
}
}
// Reset coords
this.coords = [];
this.grapharea = this.canvas.height - this._chartGutter._top - this._chartGutter._bottom;
this.halfgrapharea = this.grapharea / 2;
this.halfTextHeight = this._otherProps._text_size / 2;
//Draw Area
OfficeExcel.background.DrawArea(this);
// Progressively Draw the chart
OfficeExcel.background.Draw (this);
// Draw Bars
if (this._otherProps._background_hbars && this._otherProps._background_hbars.length > 0)
OfficeExcel.DrawBars(this);
// Draw Axes
this.DrawAxes(min,max);
for (var i = 0, j = 0; i < this.data.length; ++i, ++j) {
this.context.beginPath();
// Draw line
var fill = null;
if (this._otherProps._fillstyle) {
if (typeof(this._otherProps._fillstyle) == 'object' && this._otherProps._fillstyle[j])
fill = this._otherProps._fillstyle[j];
else if (typeof(this._otherProps._fillstyle) == 'string')
fill = this._otherProps._fillstyle;
} else if (this._otherProps._filled)
fill = this._otherProps._colors[j];
// tickmarks
var tickmarks = null;
if (this._otherProps._tickmarks && typeof(this._otherProps._tickmarks) == 'object')
tickmarks = this._otherProps._tickmarks[i];
else if (this._otherProps._tickmarks && typeof(this._otherProps._tickmarks) == 'string')
tickmarks = this._otherProps._tickmarks;
else if (this._otherProps._tickmarks && typeof(this._otherProps._tickmarks) == 'function')
tickmarks = this._otherProps._tickmarks;
//var isSkip = false;
if(this._otherProps._filled == true && (this._otherProps._autoGrouping == 'stacked' || this._otherProps._autoGrouping == 'stackedPer'))
{
var k = 0;
if(!isSkip[i])
this.DrawLine(this.data[this.data.length - 1 - i], 'inherit', this._otherProps._colors[this._otherProps._colors.length - 1- j], this.GetLineWidth(j), tickmarks, i);
}
else
{
if(!isSkip[i])
this.DrawLine(this.data[i], this._otherProps._colors[j], fill, this.GetLineWidth(j), tickmarks, i);
}
this.context.stroke();
}
// Draw the labels
this.DrawLabels(isFormatCell);
// Draw range
this.DrawRange();
// Draw keys
if (this._otherProps._key.length)
OfficeExcel.DrawKey(this, this._otherProps._key, this._otherProps._colors);
// Draw above labels
if (this._otherProps._labels_above)
this.DrawAboveLabels(isFormatCell);
// Redraw the lines if a filled range is on the cards
if (this._otherProps._filled && this._otherProps._filled_range && this.data.length == 2) {
this.context.beginPath();
var len = this.coords.length / 2;
this.context.lineWidth = this._otherProps._linewidth;
this.context.strokeStyle = this._otherProps._colors[0];
for (var i=0; i<len; ++i) {
if (i == 0)
this.context.moveTo(this.coords[i][0], this.coords[i][1]);
else
this.context.lineTo(this.coords[i][0], this.coords[i][1]);
}
this.context.stroke();
this.context.beginPath();
if (this._otherProps._colors[1])
this.context.strokeStyle = this._otherProps._colors[1];
for (var i=this.coords.length - 1; i>=len; --i) {
if (i == (this.coords.length - 1) )
this.context.moveTo(this.coords[i][0], this.coords[i][1]);
else
this.context.lineTo(this.coords[i][0], this.coords[i][1]);
}
this.context.stroke();
}
}
// Draws the axes
OfficeExcel.Line.prototype.DrawAxes = function (min,max)
{
// Don't draw the axes?
if (this._otherProps._noaxes)
return;
this.context.lineWidth = 1;
this.context.lineCap = 'butt';
this.context.strokeStyle = this._otherProps._axis_color;
this.context.beginPath();
// Draw the X axis
if('auto' == this._otherProps._ylabels_count && this._otherProps._xaxispos)
{
//определяем куда ставить ось
var numNull = this._otherProps._background_grid_autofit_numhlines;
var arrTemp = []
var k = 0;
for (var j=0; j < this.data.length; j++) {
for (var i=0; i<this.data[j].length; i++)
{
arrTemp[k] = this.data[j][i];
k++;
}
}
//min = Math.min.apply(null, arrTemp);
//max = Math.max.apply(null, arrTemp);
if(min >= 0 && max >= 0)
{
numNull = 0;
}
else if(min <= 0 && max <= 0)
{
numNull = this._otherProps._background_grid_autofit_numhlines;
}
else
{
for (var i=0; i<this.scale.length; i++)
{
if(this.scale[i] == 0)
{
numNull = i + 1;
break;
}
}
}
var nullPosition;
if(0 == numNull)
nullPosition = 0;
else
nullPosition = (this.canvas.height - this._chartGutter._bottom - this._chartGutter._top)/(this._otherProps._background_grid_autofit_numhlines)*numNull;
if (this._otherProps._noxaxis == false) {
this.context.moveTo(this._chartGutter._left, AA(this, this.canvas.height - this._chartGutter._bottom - nullPosition));
this.context.lineTo(this.canvas.width - this._chartGutter._right, AA(this, this.canvas.height - this._chartGutter._bottom - nullPosition));
}
this.nullPositionOX = this.canvas.height - this._chartGutter._bottom - nullPosition;
}
else if (this._otherProps._xaxispos == 'center') {
this.context.moveTo(this._chartGutter._left, AA(this, (this.grapharea / 2) + this._chartGutter._top));
this.context.lineTo(this.canvas.width - this._chartGutter._right, AA(this, (this.grapharea / 2) + this._chartGutter._top));
} else if (this._otherProps._xaxispos == 'top') {
this.context.moveTo(this._chartGutter._left, AA(this, this._chartGutter._top));
this.context.lineTo(this.canvas.width - this._chartGutter._right, AA(this, this._chartGutter._top));
} else {
this.context.moveTo(this._chartGutter._left, AA(this, this.canvas.height - this._chartGutter._bottom));
this.context.lineTo(this.canvas.width - this._chartGutter._right, AA(this, this.canvas.height - this._chartGutter._bottom));
}
// Draw the Y axis
if (this._otherProps._noyaxis == false) {
if (this._otherProps._yaxispos == 'left') {
this.context.moveTo(AA(this, this._chartGutter._left), this._chartGutter._top);
this.context.lineTo(AA(this, this._chartGutter._left), this.canvas.height - this._chartGutter._bottom + 1);
} else {
this.context.moveTo(AA(this, this.canvas.width - this._chartGutter._right), this._chartGutter._top);
this.context.lineTo(AA(this, this.canvas.width - this._chartGutter._right), this.canvas.height - this._chartGutter._bottom);
}
}
// Draw X tickmarks
if(!this._otherProps._noxaxis)
{
if('auto' == this._otherProps._ylabels_count)
{
var x = this._chartGutter._left;
var yStart = this.nullPositionOX;
var yEnd = this.nullPositionOX + 5;
for (var j=0; j <= this._otherProps._background_grid_autofit_numvlines; j++)
{
var newX = x + ((this.canvas.width - this._chartGutter._right - this._chartGutter._left)/(this._otherProps._background_grid_autofit_numvlines))*j;
this.context.moveTo(AA(this, newX), yStart);
this.context.lineTo(AA(this, newX), yEnd);
}
}
}
// Draw Y tickmarks
var numyticks = this._otherProps._numyticks;
if (this._otherProps._noyaxis == false) {
var adjustment = 0;
if (this._otherProps._yaxispos == 'right')
adjustment = (this.canvas.width - this._chartGutter._left - this._chartGutter._right);
// X axis at the center
if (this._otherProps._xaxispos == 'center') {
var interval = (this.grapharea / numyticks);
var lineto = (this._otherProps._yaxispos == 'left' ? this._chartGutter._left : this.canvas.width - this._chartGutter._right + this._otherProps._smallyticks);
// Draw the upper halves Y tick marks
for (var y=this._chartGutter._top; y < (this.grapharea / 2) + this._chartGutter._top; y+=interval) {
this.context.moveTo((this._otherProps._yaxispos == 'left' ? this._chartGutter._left - this._otherProps._smallyticks : this.canvas.width - this._chartGutter._right), AA(this, y));
this.context.lineTo(lineto, AA(this, y));
}
// Draw the lower halves Y tick marks
for (var y = this._chartGutter._top + (this.halfgrapharea) + interval; y <= this.grapharea + this._chartGutter._top; y += interval) {
this.context.moveTo((this._otherProps._yaxispos == 'left' ? this._chartGutter._left - this._otherProps._smallyticks : this.canvas.width - this._chartGutter._right), AA(this, y));
this.context.lineTo(lineto, AA(this, y));
}
// X axis at the top
} else if (this._otherProps._xaxispos == 'top') {
var interval = (this.grapharea / numyticks);
var lineto = (this._otherProps._yaxispos == 'left' ? this._chartGutter._left : this.canvas.width - this._chartGutter._right + this._otherProps._smallyticks);
// Draw the Y tick marks
//for (var y = this._chartGutter._top + interval; y <= this.grapharea + this._chartGutter._top; y += interval) {
for (var y = this._chartGutter._top,counter = 0 ; y <= this.grapharea + this._chartGutter._top + 2; y += interval, ++counter) {
if(counter == numyticks)
y = this.canvas.height - this._chartGutter._bottom;
this.context.moveTo((this._otherProps._yaxispos == 'left' ? this._chartGutter._left - this._otherProps._smallyticks : this.canvas.width - this._chartGutter._right), AA(this, y));
this.context.lineTo(lineto, AA(this, y));
}
// If there's no X axis draw an extra tick
if (this._otherProps._noxaxis) {
this.context.moveTo((this._otherProps._yaxispos == 'left' ? this._chartGutter._left - this._otherProps._smallyticks : this.canvas.width - this._chartGutter._right), this._chartGutter._top);
this.context.lineTo(lineto, this._chartGutter._top);
}
// X axis at the bottom
} else {
var lineto = (this._otherProps._yaxispos == 'left' ? this._chartGutter._left - this._otherProps._smallyticks : this.canvas.width - this._chartGutter._right + this._otherProps._smallyticks);
for (var y = this._chartGutter._top, counter = 0; y <= (this.canvas.height - this._chartGutter._bottom) + 2 && counter <= numyticks; y += ((this.canvas.height - this._chartGutter._top - this._chartGutter._bottom) / numyticks), ++counter) {
if(counter == numyticks)
y = this.canvas.height - this._chartGutter._bottom;
this.context.moveTo(this._chartGutter._left + adjustment, AA(this, y));
this.context.lineTo(lineto, AA(this, y));
}
}
}
this.context.stroke();
}
// Draw the text labels for the axes
OfficeExcel.Line.prototype.DrawLabels = function (isFormatCell)
{
this.context.strokeStyle = 'black';
this.context.fillStyle = this._otherProps._text_color;
this.context.lineWidth = 1;
var scaleFactor = 1;
if(OfficeExcel.drawingCtxCharts && OfficeExcel.drawingCtxCharts.scaleFactor)
scaleFactor = OfficeExcel.drawingCtxCharts.scaleFactor;
// This needs to be here
var font = this._otherProps._ylabels_font;
var text_size = this._otherProps._ylabels_size;
var context = this.context;
var canvas = this.canvas;
var bold = this._otherProps._ylabels_bold;
var textOptions =
{
color: this._otherProps._ylabels_color,
underline:this._otherProps._ylabels_underline,
italic: this._otherProps._ylabels_italic
}
// Draw the Y axis labels
if (this._otherProps._ylabels) {
var units_pre = this._otherProps._units_pre;
var units_post = this._otherProps._units_post;
var xpos = this._otherProps._yaxispos == 'left' ? this._chartGutter._left - 5 : this.canvas.width - this._chartGutter._right + 5;
var align = this._otherProps._yaxispos == 'left' ? 'right' : 'left';
var numYLabels = this._otherProps._ylabels_count;
var bounding = false;
var bgcolor = null;
if (this._otherProps._xaxispos == 'center') {
var half = this.grapharea / 2;
if('auto' == numYLabels)
{
for (var i=0; i<this.scale.length; ++i) {
OfficeExcel.Text(context,font,text_size,xpos - 5,this._chartGutter._top + this.halfTextHeight + ((i/this.scale.length) * (this.grapharea) ),this.scale[this.scale.length -1 - i],null,align,bounding,null,bgcolor, bold, null, textOptions);
}
}
// X axis at the top
} else if (this._otherProps._xaxispos == 'top') {
if('auto' == numYLabels)
{
var scale = OfficeExcel.array_reverse(this.scale);
/*var elemArr;
for (var i=0; i<this.scale.length; ++i) {
elemArr = (scale[scale.length - i])
if(0 == i)
elemArr = scale[scale.length - 1] - (scale[scale.length - 2] - scale[scale.length - 1])
OfficeExcel.Text(context,font,text_size,xpos,this._chartGutter._top + this.halfTextHeight + ((i/scale.length) * (this.grapharea) ),-elemArr,null,align,bounding,null,bgcolor);
}*/
for (var i=0; i<=this.scale.length; ++i) {
var elemArr;
elemArr = (scale[scale.length - i])
if(0 == i)
{
var floatKoff = 100000000000;
elemArr = Math.round(OfficeExcel.array_exp(scale[scale.length - 1] - (scale[scale.length - 2] - scale[scale.length - 1]))*floatKoff)/floatKoff ;
}
if(elemArr == 0)
OfficeExcel.Text(context,font,text_size,xpos - 5,this._chartGutter._top + this.halfTextHeight + ((i/this.scale.length) * (this.grapharea) ),OfficeExcel.numToFormatText(elemArr.toString(),isFormatCell),null,align,bounding,null,bgcolor, bold, null, textOptions);
else
OfficeExcel.Text(context,font,text_size,xpos - 5,this._chartGutter._top + this.halfTextHeight + ((i/this.scale.length) * (this.grapharea) ),OfficeExcel.numToFormatText("-" + elemArr.toString(),isFormatCell),null,align,bounding,null,bgcolor, bold, null, textOptions);
}
}
} else {
if('auto' == numYLabels)
{
for (var i=0; i<this.scale.length; ++i) {
OfficeExcel.Text(context,font,text_size,xpos - 5,this._chartGutter._top + this.halfTextHeight + ((i/this.scale.length) * (this.grapharea) ),OfficeExcel.numToFormatText((this.scale[this.scale.length -1 - i]).toString(),isFormatCell) + units_post,null,align,bounding,null,bgcolor, bold, null, textOptions);
//OfficeExcel.Text(context,font,text_size,xpos - 5,this._chartGutter._top + this.halfTextHeight + ((i/this.scale.length) * (this.grapharea) ),OfficeExcel.number_format(this, (this.scale[this.scale.length -1 - i]).toString().replace('.',','), units_pre, units_post),null,align,bounding,null,bgcolor);
//OfficeExcel.Text(context,font,text_size,xpos - 5,this._chartGutter._top + this.halfTextHeight + ((i/this.scale.length) * (this.grapharea) ),this.scale[this.scale.length -1 - i],null,align,bounding,null,bgcolor);
}
}
if (typeof(this._otherProps._ymin) == 'number' || typeof(this._otherProps._ymin) == 'string' && this._otherProps._ymin.search('E') != -1) {
OfficeExcel.Text(context,font,text_size,xpos - 5,this.canvas.height - this._chartGutter._bottom,OfficeExcel.numToFormatText(this._otherProps._ymin.toString(),isFormatCell) + units_post,'center',align,bounding,null,bgcolor, bold, null, textOptions);
}
}
// No X axis - so draw 0 - but not if the X axis is in the center
if ( this._otherProps._noxaxis == true
&& this._otherProps._ymin == null
&& this._otherProps._xaxispos != 'center'
) {
OfficeExcel.Text(context,font,text_size,xpos,this._otherProps._xaxispos == 'top' ? this._chartGutter._top + this.halfTextHeight: (this.canvas.height - this._chartGutter._bottom + this.halfTextHeight),this._otherProps._units_pre + '0' + this._otherProps._units_post,null, align, bounding, null, bgcolor, bold, null, textOptions);
}
}
// Draw the X axis labels
if (this._otherProps._labels && this._otherProps._labels.length > 0 && this._otherProps._xlabels ) {
var yOffset = 5;
var bordered = false;
var bgcolor = null;
font = this._otherProps._xlabels_font;
bold = this._otherProps._xlabels_bold;
textOptions =
{
color: this._otherProps._xlabels_color,
underline: this._otherProps._xlabels_underline,
italic: this._otherProps._xlabels_italic
}
/**
* Text angle
*/
var angle = 0;
var valign = 'top';
var halign = 'center';
if (this._otherProps._xaxispos == 'top') {
valign = 'bottom';
yOffset += 2;
}
if(this._otherProps._xaxispos == 'top' && 'auto' == this._otherProps._ylabels_count)
yOffset = 20;
else if('auto' == this._otherProps._ylabels_count)
yOffset = 11;
this.context.fillStyle = this._otherProps._text_color;
var numLabels = this._otherProps._labels.length;
var axisOxAngleOptions;
if(this._otherProps._axisOxAngleOptions && this._otherProps._axisOxAngleOptions.angle)
{
axisOxAngleOptions = this._otherProps._axisOxAngleOptions;
angle = this._otherProps._axisOxAngleOptions.angle;
}
var diffWidth;
var diffHeight;
for (var i=0; i<numLabels; ++i) {
// Changed 8th Nov 2010 to be not reliant on the coords
//if (this._otherProps._labels[i] && this.coords && this.coords[i] && this.coords[i][0]) {
if (this._otherProps._labels[i]) {
var labelX = ((this.canvas.width - this._chartGutter._left - this._chartGutter._right - (2 * this._otherProps._hmargin)) / (numLabels - 1) ) * i;
labelX += this._chartGutter._left + this._otherProps._hmargin;
/**
* Account for an unrelated number of labels
*/
if (this._otherProps._labels.length != this.data[0].length) {
//labelX = this._chartGutter._left + this._otherProps._hmargin + ((this.canvas.width - this._chartGutter._left - this._chartGutter._right - (2 * this._otherProps._hmargin)) * (i / (this._otherProps._labels.length - 1)));
labelX = this._chartGutter._left - this._otherProps._background_grid_vsize/2 + i*this._otherProps._background_grid_vsize;
}
// This accounts for there only being one point on the chart
if (!labelX) {
labelX = this._chartGutter._left + this._otherProps._hmargin;
}
if('auto' == this._otherProps._ylabels_count)
{
diffWidth = axisOxAngleOptions ? (axisOxAngleOptions[i]*Math.sin(angle*Math.PI/180))/(4) : 0;
diffHeight = axisOxAngleOptions ? (axisOxAngleOptions[i]*Math.cos(angle*Math.PI/180) - 10) : 0;
OfficeExcel.Text(context,
font,
text_size,
labelX - diffWidth,
this.nullPositionOX + yOffset*scaleFactor + diffHeight,
String(this._otherProps._labels[i]),
valign,
halign,
bordered,
angle,
bgcolor, bold, null, textOptions);
}
}
}
}
this.context.stroke();
if(this._otherProps._filled != true)
this.context.fill();
}
// Draws the line
OfficeExcel.Line.prototype.DrawLine = function (lineData, color, fill, linewidth, tickmarks, index)
{
var penUp = false;
var yPos = null;
var xPos = 0;
this.context.lineWidth = 1;
var lineCoords = [];
/**
* Get the previous line data
*/
if (index > 0) {
var prevLineCoords = this.coords2[index - 1];
}
// Work out the X interval
var xInterval
if('auto' == this._otherProps._ylabels_count && 'object' == typeof this.data_arr[0])
xInterval = (this.canvas.width - (2 * this._otherProps._hmargin) - this._chartGutter._left - this._chartGutter._right) / (this._otherProps._labels.length - 1);
else
xInterval = (this.canvas.width - (2 * this._otherProps._hmargin) - this._chartGutter._left - this._chartGutter._right) / (lineData.length - 1);
// Loop thru each value given, plotting the line
// (FORMERLY FIRST)
for (var i=0; i<lineData.length; i++) {
var data_point = lineData[i];
yPos = this.canvas.height - (((data_point - (data_point > 0 ? this._otherProps._ymin : (-1 * this._otherProps._ymin))) / (this.max - this.min) ) * this.grapharea);
yPos = (this.grapharea / (this.max - this.min)) * (data_point - this.min);
yPos = this.canvas.height - yPos;
/**
* This skirts an annoying JS rounding error
* SEARCH TAGS: JS ROUNDING ERROR DECIMALS
*/
if (data_point == this.max) {
yPos = Math.round(yPos);
}
// Make adjustments depending on the X axis position
if (this._otherProps._xaxispos == 'center') {
yPos = (yPos - this._chartGutter._bottom - this._chartGutter._top) / 2;
yPos = yPos + this._chartGutter._top;
// TODO Check this
} else if (this._otherProps._xaxispos == 'top') {
yPos = (this.grapharea / (this.max - this.min)) * (Math.abs(data_point) - this.min);
yPos += this._chartGutter._top;
} else if (this._otherProps._xaxispos == 'bottom') {
// TODO
yPos -= this._chartGutter._bottom; // Without this the line is out of place due to the gutter
}
if ( lineData[i] == null
|| (this._otherProps._xaxispos == 'bottom' && lineData[i] < this.min)
|| (this._otherProps._xaxispos == 'center' && lineData[i] < (-1 * this.max))) {
yPos = null;
}
// Not always very noticeable, but it does have an effect
// with thick lines
this.context.lineCap = 'round';
this.context.lineJoin = 'round';
// Plot the line if we're at least on the second iteration
if (i > 0) {
xPos = xPos + xInterval;
} else {
xPos = this._otherProps._hmargin + this._chartGutter._left;
}
/**
* Add the coords to an array
*/
if(data_point.toString() == '')
{
this.coords.push(['', '']);
lineCoords.push(['', '']);
}
else
{
this.coords.push([xPos, yPos]);
lineCoords.push([xPos, yPos]);
}
}
this.context.stroke();
// Store the coords in another format, indexed by line number
this.coords2[index] = lineCoords;
/**
* Now draw the actual line [FORMERLY SECOND]
*/
this.context.beginPath();
// Transparent now as of 11/19/2011
this.context.strokeStyle = 'rgba(0,0,0,0)';
//this.context.strokeStyle = fill;
if (fill) {
this.context.fillStyle = fill;
}
var isStepped = this._otherProps._stepped;
var isFilled = this._otherProps._filled;
if (this._otherProps._xaxispos == 'top') {
var xAxisPos = this._chartGutter._top;
} else if (this._otherProps._xaxispos == 'center') {
var xAxisPos = this._chartGutter._top + (this.grapharea / 2);
} else if (this._otherProps._xaxispos == 'bottom') {
var xAxisPos = this.canvas.height - this._chartGutter._bottom;
}
for (var i=0; i<lineCoords.length; ++i) {
xPos = lineCoords[i][0];
yPos = lineCoords[i][1];
var set = index;
var prevY = (lineCoords[i - 1] ? lineCoords[i - 1][1] : null);
var isLast = (i + 1) == lineCoords.length;
/**
* This nullifys values which are out-of-range
*/
if (prevY < this._chartGutter._top || prevY > (this.canvas.height - this._chartGutter._bottom) ) {
penUp = true;
}
if (i == 0 || penUp || !yPos || !prevY /*|| prevY < this._chartGutter._top*/) {
if (this._otherProps._filled && !this._otherProps._filled_range) {
this.context.moveTo(xPos + 1, xAxisPos);
// This facilitates the X axis being at the top
// NOTE: Also done below
if (this._otherProps._xaxispos == 'top') {
this.context.moveTo(xPos + 1, xAxisPos);
}
this.context.moveTo(xPos, yPos);
} else {
if (OfficeExcel.isOld() && yPos == null) {
// Nada
} else {
this.context.moveTo(xPos + 1, yPos);
}
}
if (yPos == null) {
penUp = true;
} else {
penUp = false;
}
} else {
// Draw the stepped part of stepped lines
if (isStepped) {
this.context.lineTo(xPos, lineCoords[i - 1][1]);
}
if (yPos >= this._chartGutter._top && yPos <= (this.canvas.height - this._chartGutter._bottom)) {
if (isLast && this._otherProps._filled && !this._otherProps._filled_range && this._otherProps._yaxispos == 'right') {
xPos -= 1;
}
// Added 8th September 2009
if (!isStepped || !isLast) {
this.context.lineTo(xPos, yPos);
if (isFilled && lineCoords[i+1] && lineCoords[i+1][1] == null) {
this.context.lineTo(xPos, xAxisPos);
}
// Added August 2010
} else if (isStepped && isLast) {
this.context.lineTo(xPos,yPos);
}
penUp = false;
} else {
penUp = true;
}
}
}
/**
* Draw a line to the X axis if the chart is filled
*/
if (this._otherProps._filled && !this._otherProps._filled_range) {
if (this._otherProps._xaxispos == 'top') {
this.context.lineTo(xPos, this._chartGutter._top + 1);
this.context.lineTo(lineCoords[0][0],this._chartGutter._top + 1);
} else if (typeof(lineCoords[i - 1][1]) == 'number') {
var yPosition = this.nullPositionOX;
this.context.lineTo(xPos,yPosition);
this.context.lineTo(lineCoords[0][0],yPosition);
}
this.context.fillStyle = fill;
this.context.fill();
this.context.beginPath();
}
this.context.stroke();
// Now redraw the lines with the correct line width
if(!this._otherProps._filled)
this.RedrawLine(lineCoords, color, linewidth);
this.context.stroke();
// Draw the tickmarks
for (var i=0; i<lineCoords.length; ++i) {
i = Number(i);
if (isStepped && i == (lineCoords.length - 1)) {
this.context.beginPath();
//continue;
}
if (
(
tickmarks != 'endcircle'
&& tickmarks != 'endsquare'
&& tickmarks != 'filledendsquare'
&& tickmarks != 'endtick'
&& tickmarks != 'endtriangle'
&& tickmarks != 'arrow'
&& tickmarks != 'filledarrow'
)
|| (i == 0 && tickmarks != 'arrow' && tickmarks != 'filledarrow')
|| i == (lineCoords.length - 1)
) {
var prevX = (i <= 0 ? null : lineCoords[i - 1][0]);
var prevY = (i <= 0 ? null : lineCoords[i - 1][1]);
this.DrawTick(lineData, lineCoords[i][0], lineCoords[i][1], color, prevX, prevY, tickmarks, i);
// Draws tickmarks on the stepped bits of stepped charts. Takend out 14th July 2010
//
//if (this._otherProps._stepped && lineCoords[i + 1] && this._otherProps._tickmarks != 'endsquare' && this._otherProps._tickmarks != 'endcircle' && this._otherProps._tickmarks != 'endtick') {
// this.DrawTick(lineCoords[i + 1][0], lineCoords[i][1], color);
//}
}
}
// Draw something off canvas to skirt an annoying bug
this.context.beginPath();
this.context.arc(this.canvas.width + 50000, this.canvas.height + 50000, 2, 0, 6.38, 1);
}
// Draws a tick
OfficeExcel.Line.prototype.DrawTick = function (lineData, xPos, yPos, color, prevX, prevY, tickmarks, index)
{
// If the yPos is null - no tick
if (yPos == null || yPos > (this.canvas.height - this._chartGutter._bottom) || yPos < this._chartGutter._top)
return;
this.context.beginPath();
var offset = 0;
this.context.lineWidth = this._otherProps._linewidth;
this.context.strokeStyle = this.context.strokeStyle;
this.context.fillStyle = this.context.strokeStyle;
if ( tickmarks == 'circle'
|| tickmarks == 'filledcircle'
|| tickmarks == 'endcircle') {
if (tickmarks == 'circle'|| tickmarks == 'filledcircle' || (tickmarks == 'endcircle') ) {
this.context.beginPath();
this.context.arc(xPos + offset, yPos + offset, this._otherProps._ticksize, 0, 360 / (180 / Math.PI), false);
if (tickmarks == 'filledcircle') {
this.context.fillStyle = this.context.strokeStyle;
} else {
this.context.fillStyle = 'white';
}
this.context.stroke();
this.context.fill();
}
// Halfheight "Line" style tick marks
} else if (tickmarks == 'halftick') {
this.context.beginPath();
this.context.moveTo(xPos, yPos);
this.context.lineTo(xPos, yPos + this._otherProps._ticksize);
this.context.stroke();
// Tick style tickmarks
} else if (tickmarks == 'tick') {
this.context.beginPath();
this.context.moveTo(xPos, yPos - this._otherProps._ticksize);
this.context.lineTo(xPos, yPos + this._otherProps._ticksize);
this.context.stroke();
// Endtick style tickmarks
} else if (tickmarks == 'endtick') {
this.context.beginPath();
this.context.moveTo(xPos, yPos - this._otherProps._ticksize);
this.context.lineTo(xPos, yPos + this._otherProps._ticksize);
this.context.stroke();
// "Cross" style tick marks
} else if (tickmarks == 'cross') {
this.context.beginPath();
this.context.moveTo(xPos - this._otherProps._ticksize, yPos - this._otherProps._ticksize);
this.context.lineTo(xPos + this._otherProps._ticksize, yPos + this._otherProps._ticksize);
this.context.moveTo(xPos + this._otherProps._ticksize, yPos - this._otherProps._ticksize);
this.context.lineTo(xPos - this._otherProps._ticksize, yPos + this._otherProps._ticksize);
this.context.stroke();
// Triangle style tick marks
} else if (tickmarks == 'triangle' || tickmarks == 'filledtriangle' || tickmarks == 'endtriangle') {
this.context.beginPath();
if (tickmarks == 'filledtriangle') {
this.context.fillStyle = this.context.strokeStyle;
} else {
this.context.fillStyle = 'white';
}
this.context.moveTo(xPos - this._otherProps._ticksize, yPos + this._otherProps._ticksize);
this.context.lineTo(xPos, yPos - this._otherProps._ticksize);
this.context.lineTo(xPos + this._otherProps._ticksize, yPos + this._otherProps._ticksize);
this.context.closePath();
this.context.stroke();
this.context.fill();
// A white bordered circle
} else if (tickmarks == 'borderedcircle' || tickmarks == 'dot') {
this.context.lineWidth = 1;
this.context.strokeStyle = this._otherProps._tickmarks_dot_color;
this.context.fillStyle = this._otherProps._tickmarks_dot_color;
// The outer white circle
this.context.beginPath();
this.context.arc(xPos, yPos, this._otherProps._ticksize, 0, 360 / (180 / Math.PI), false);
this.context.closePath();
this.context.fill();
this.context.stroke();
// Now do the inners
this.context.beginPath();
this.context.fillStyle = color;
this.context.strokeStyle = color;
this.context.arc(xPos, yPos, this._otherProps._ticksize - 2, 0, 360 / (180 / Math.PI), false);
this.context.closePath();
this.context.fill();
this.context.stroke();
} else if ( tickmarks == 'square'
|| tickmarks == 'filledsquare'
|| (tickmarks == 'endsquare')
|| (tickmarks == 'filledendsquare') ) {
this.context.fillStyle = 'white';
this.context.strokeStyle = this.context.strokeStyle; // FIXME Is this correct?
this.context.beginPath();
this.context.strokeRect(xPos - this._otherProps._ticksize, yPos - this._otherProps._ticksize, this._otherProps._ticksize * 2, this._otherProps._ticksize * 2);
// Fillrect
if (tickmarks == 'filledsquare' || tickmarks == 'filledendsquare') {
this.context.fillStyle = this.context.strokeStyle;
this.context.fillRect(xPos - this._otherProps._ticksize, yPos - this._otherProps._ticksize, this._otherProps._ticksize * 2, this._otherProps._ticksize * 2);
} else if (tickmarks == 'square' || tickmarks == 'endsquare') {
this.context.fillStyle = 'white';
this.context.fillRect((xPos - this._otherProps._ticksize) + 1, (yPos - this._otherProps._ticksize) + 1, (this._otherProps._ticksize * 2) - 2, (this._otherProps._ticksize * 2) - 2);
}
this.context.stroke();
this.context.fill();
/**
* FILLED arrowhead
*/
} else if (tickmarks == 'filledarrow') {
var x = Math.abs(xPos - prevX);
var y = Math.abs(yPos - prevY);
if (yPos < prevY) {
var a = Math.atan(x / y) + 1.57;
} else {
var a = Math.atan(y / x) + 3.14;
}
this.context.beginPath();
this.context.moveTo(xPos, yPos);
this.context.arc(xPos, yPos, 7, a - 0.5, a + 0.5, false);
this.context.closePath();
this.context.stroke();
this.context.fill();
/**
* Arrow head, NOT filled
*/
} else if (tickmarks == 'arrow') {
var x = Math.abs(xPos - prevX);
var y = Math.abs(yPos - prevY);
var orig_linewidth = this.context.lineWidth;
if (yPos < prevY) {
var a = Math.atan(x / y) + 1.57;
} else {
var a = Math.atan(y / x) + 3.14;
}
this.context.beginPath();
this.context.moveTo(xPos, yPos);
this.context.arc(xPos, yPos, 7, a - 0.5 - (document.all ? 0.1 : 0.01), a - 0.4, false);
this.context.moveTo(xPos, yPos);
this.context.arc(xPos, yPos, 7, a + 0.5 + (document.all ? 0.1 : 0.01), a + 0.5, true);
this.context.stroke();
this.context.fill();
// Revert to original lineWidth
this.context.lineWidth = orig_linewidth;
/**
* Custom tick drawing function
*/
} else if (typeof(tickmarks) == 'function') {
tickmarks(this, lineData, lineData[index], index, xPos, yPos, color, prevX, prevY);
}
}
// Draws a filled range if necessary
OfficeExcel.Line.prototype.DrawRange = function ()
{
// Fill the range if necessary
if (this._otherProps._filled_range && this._otherProps._filled) {
this.context.beginPath();
this.context.fillStyle = this._otherProps._fillstyle;
this.context.strokeStyle = this._otherProps._fillstyle;
this.context.lineWidth = 1;
var len = (this.coords.length / 2);
for (var i = 0; i < len; ++i) {
if (i == 0)
this.context.moveTo(this.coords[i][0], this.coords[i][1])
else
this.context.lineTo(this.coords[i][0], this.coords[i][1])
}
for (var i = this.coords.length - 1; i >= len; --i)
this.context.lineTo(this.coords[i][0], this.coords[i][1])
this.context.stroke();
this.context.fill();
}
}
// Redraws the line with the correct line width etc
OfficeExcel.Line.prototype.RedrawLine = function (coords, color, linewidth)
{
this.context.strokeStyle = (typeof(color) == 'object' && color ? color[0] : color);
this.context.lineWidth = linewidth;
this.context.beginPath();
var len = coords.length;
var width = this.canvas.width
var height = this.canvas.height;
var penUp = false;
for (var i = 0; i < len; ++i) {
var xPos = coords[i][0];
var yPos = coords[i][1];
if (i > 0) {
var prevX = coords[i - 1][0];
var prevY = coords[i - 1][1];
}
if ((i == 0 && coords[i])
/*|| (yPos < this._chartGutter._top)
|| (prevY < this._chartGutter._top)*/
|| yPos == ''
|| prevY == ''
|| (yPos > (height - this._chartGutter._bottom))
|| (i > 0 && prevX > (width - this._chartGutter._right))
|| (i > 0 && prevY > (height - this._chartGutter._bottom))
|| prevY == null
|| penUp == true
) {
if (OfficeExcel.isOld() && yPos == null) {
// ...?
} else {
this.context.moveTo(coords[i][0], coords[i][1]);
}
penUp = false;
} else {
if (this._otherProps._stepped && i > 0) {
this.context.lineTo(coords[i][0], coords[i - 1][1]);
}
// Don't draw the last bit of a stepped chart. Now DO
//if (!this._otherProps._stepped || i < (coords.length - 1)) {
this.context.lineTo(coords[i][0], coords[i][1]);
//}
penUp = false;
}
}
}
// Returns the linewidth
OfficeExcel.Line.prototype.GetLineWidth = function (i)
{
var linewidth = this._otherProps._linewidth;
if (typeof(linewidth) == 'number')
return linewidth;
else if (typeof(linewidth) == 'object') {
if (linewidth[i])
return linewidth[i];
else
return linewidth[0];
}
}
// Draws the above line labels
OfficeExcel.Line.prototype.DrawAboveLabels = function (format)
{
var context = this.context;
var size = this._otherProps._labels_above_size;
var font = this._otherProps._labels_above_font;
var bold = this._otherProps._labels_above_bold;
var textOptions =
{
color: this._otherProps._labels_above_color,
underline: this._otherProps._labels_above_underline,
italic: this._otherProps._labels_above_italic
}
context.beginPath();
var formatLabels = [];
var tempData = [];
var n = 0;
for (var i = 0; i < this.firstData.length; ++i) {
for (var j = 0; j < this.firstData[i].length; ++j) {
if(this.catNameLabels && this.catNameLabels[i] && this.catNameLabels[i][j])
{
tempData[n] = this.catNameLabels[i][j];
formatLabels[n] = "General";
}
else
{
tempData[n] = this.firstData[i][j];
if(this.arrFormatAdobeLabels && this.arrFormatAdobeLabels[i] && this.arrFormatAdobeLabels[i][j])
formatLabels[n] = this.arrFormatAdobeLabels[i][j];
else
formatLabels[n] = format;
}
n++;
}
}
for (var i = 0; i < this.coords.length; ++i) {
var coords = this.coords[i];
OfficeExcel.Text(context, font, size, coords[0], coords[1] - 5 - size,OfficeExcel.numToFormatText( OfficeExcel.num_round(tempData[i]),formatLabels[i]), 'center', 'center', false, null, 'rgba(255, 255, 255, 0.7)', bold, null, textOptions);
// OfficeExcel.Text(context, font, size, coords[0], coords[1] - 5 - size, OfficeExcel.number_format(this, OfficeExcel.num_round(tempData[i]), units_pre, units_post), 'center', 'center', false, null, 'rgba(255, 255, 255, 0.7)');
}
context.fill();
}
\ No newline at end of file
"use strict";
if (typeof(window["OfficeExcel"]) == 'undefined') window["OfficeExcel"] = {};
OfficeExcel.Pie = function (chartCanvas, data)
{
this.canvas = chartCanvas;
this.context = (this.canvas && this.canvas.getContext) ? this.canvas.getContext("2d") : null;
this.canvas.__object__ = this;
this.total = 0;
this.subTotal = 0;
this.angles = [];
this.data = data;
this.type = 'pie';
/**
* Compatibility with older browsers
*/
OfficeExcel.CanvasBrowserCompat(this.context);
// Chart gutter
this._chartGutter = new OfficeExcel.Gutter();
// Other Props
this._otherProps = new OfficeExcel.OtherProps();
/**
* Calculate the total
*/
for (var i=0,len=data.length; i<len; i++) {
this.total += data[i];
}
}
/**
* This draws the pie chart
*/
OfficeExcel.Pie.prototype.Draw = function (min,max,ymin,ymax,isSkip,isFormatCell)
{
this.radius = this._otherProps._radius ? this._otherProps._radius : this.getRadius();
// this.centerx now defined below
this.centery = ((this.canvas.height - this._chartGutter._top - this._chartGutter._bottom) / 2) + this._chartGutter._top;
this.subTotal = 0;
this.angles = [];
/**
* Alignment (Pie is center aligned by default) Only if centerx is not defined - donut defines the centerx
*/
if (this._otherProps._align == 'left') {
this.centerx = this.radius + this._chartGutter._left;
} else if (this._otherProps._align == 'right') {
this.centerx = this.canvas.width - this.radius - this._chartGutter._right;
} else {
this.centerx = this.canvas.width / 2;
}
//Draw Area
OfficeExcel.background.DrawArea(this);
/**
* The total of the array of values
*/
this.total = OfficeExcel.array_sum(this.data);
for (var i=0,len=this.data.length; i<len; i++) {
var angle = ((this.data[i] / this.total) * (Math.PI * 2));
// Draw the segment
this.DrawSegment(angle,this._otherProps._colors[i],i == (this.data.length - 1), i);
}
/**
* Redraw the seperating lines
*/
this.DrawBorders();
//TODO граница между секторами круговой диаграммы - в следующей версии нужно зачитывать из xml
/*for (var i=0; i<this.angles.length; i++) {
this.context.beginPath();
this.context.strokeStyle = this._otherProps._strokecolor;
this.context.fillStyle = this._otherProps._colors[i];
this.context.arc(this.angles[i][2],
this.angles[i][3],
this.radius,
(this.angles[i][0]),
(this.angles[i][1]),
false);
if (this._otherProps._variant == 'donut') {
this.context.arc(this.angles[i][2],
this.angles[i][3],
this.radius / 2,
(this.angles[i][1]),
(this.angles[i][0]),
true);
} else {
this.context.lineTo(this.angles[i][2], this.angles[i][3]);
}
this.context.closePath();
this.context.fill();
this.context.stroke();
}*/
/**
* Draw the labels
*/
this.DrawLabels(isFormatCell);
if (this._otherProps._key != null) {
OfficeExcel.DrawKey(this, this._otherProps._key, this._otherProps._colors);
}
}
/**
* Draws a single segment of the pie chart
*
* @param int degrees The number of degrees for this segment
*/
OfficeExcel.Pie.prototype.DrawSegment = function (radians, color, last, index)
{
var context = this.context;
var canvas = this.canvas;
var subTotal = this.subTotal;
var centerx = this.centerx;
if(this._otherProps._key_halign == 'right')
centerx = (this.canvas.width - this._chartGutter._right)/2;
else if(this._otherProps._key_halign == 'left')
centerx = (this.canvas.width + this._chartGutter._left)/2;
if(centerx <= (this.radius + 14) || (this.canvas.width - (this.radius*2) - this._chartGutter._left) <= 14)
centerx = this.centerx;
context.beginPath();
context.fillStyle = color;
context.strokeStyle = this._otherProps._strokecolor;
context.lineWidth = 0;
/**
* Exploded segments
*/
if ( (typeof(this._otherProps._exploded) == 'object' && this._otherProps._exploded[index] > 0) || typeof(this._otherProps._exploded) == 'number') {
var explosion = typeof(this._otherProps._exploded) == 'number' ? this._otherProps._exploded : this._otherProps._exploded[index];
var x = 0;
var y = 0;
var h = explosion;
var t = (subTotal + (radians / 2)) - 1.57;
var x = (Math.cos(t) * explosion);
var y = (Math.sin(t) * explosion);
this.context.moveTo(centerx + x, this.centery + y);
} else {
var x = 0;
var y = 0;
}
/**
* Calculate the angles
*/
var startAngle = (subTotal) - 1.57;
var endAngle = (((subTotal + radians))) - 1.57;
if(this.radius < 0)
this.radius = 0;
context.arc(centerx + x,
this.centery + y,
this.radius,
startAngle,
endAngle,
0);
if (this._otherProps._variant == 'donut') {
context.arc(centerx + x,
this.centery + y,
(this.radius / 2),
endAngle,
startAngle,
true);
} else {
context.lineTo(centerx + x, this.centery + y);
}
this.context.closePath();
// Keep hold of the angles
this.angles.push([subTotal - (Math.PI / 2), subTotal + radians - (Math.PI / 2), centerx + x, this.centery + y]);
//this.context.stroke();
this.context.fill();
this.subTotal += radians;
}
/**
* Draws the graphs labels
*/
OfficeExcel.Pie.prototype.DrawLabels = function (isFormatCell)
{
var hAlignment = 'left';
var vAlignment = 'center';
var labels = this._otherProps._labels;
var context = this.context;
var bold = this._otherProps._labels_above_bold;
var curLabel, isFormatCellTrue;
var textOptions =
{
color: this._otherProps._labels_above_color,
underline: this._otherProps._labels_above_underline,
italic: this._otherProps._labels_above_italic
}
var centerx = this.centerx;
if(this._otherProps._key_halign == 'right')
centerx = (this.canvas.width - this._chartGutter._right)/2;
else if(this._otherProps._key_halign == 'left')
centerx = (this.canvas.width + this._chartGutter._left)/2;
if(centerx <= (this.radius + 14) || (this.canvas.width - (this.radius*2) - this._chartGutter._left) <= 14)
centerx = this.centerx;
context.fillStyle = 'black';
context.beginPath();
/**
* Draw the key (ie. the labels)
*/
if (labels && labels.length) {
var text_size = this._otherProps._text_size;
for (var lNum=0; lNum<labels.length; ++lNum) {
isFormatCellTrue = isFormatCell;
if(this.arrFormatAdobeLabels && this.arrFormatAdobeLabels[lNum])
isFormatCellTrue = this.arrFormatAdobeLabels[0][lNum];
/**
* T|his ensures that if we're given too many labels, that we don't get an error
*/
if (typeof(this.angles) == 'undefined') {
continue;
}
// Move to the centre
context.moveTo(centerx,this.centery);
var a = this.angles[lNum][0] + ((this.angles[lNum][1] - this.angles[lNum][0]) / 2);
/**
* Alignment
*/
if (a < 1.57) {
hAlignment = 'left';
vAlignment = 'center';
} else if (a < 3.14) {
hAlignment = 'right';
vAlignment = 'center';
} else if (a < 4.71) {
hAlignment = 'right';
vAlignment = 'center';
} else if (a < 6.28) {
hAlignment = 'left';
vAlignment = 'center';
}
var angle = ((this.angles[lNum][1] - this.angles[lNum][0]) / 2) + this.angles[lNum][0];
/**
* Handle the additional "explosion" offset
*/
if (typeof(this._otherProps._exploded) == 'object' && this._otherProps._exploded[lNum] || typeof(this._otherProps._exploded) == 'number') {
var t = ((this.angles[lNum][1] - this.angles[lNum][0]) / 2);
var seperation = typeof(this._otherProps._exploded) == 'number' ? this._otherProps._exploded : this._otherProps._exploded[lNum];
// Adjust the angles
var explosion_offsetx = (Math.cos(angle) * seperation);
var explosion_offsety = (Math.sin(angle) * seperation);
} else {
var explosion_offsetx = 0;
var explosion_offsety = 0;
}
context.fillStyle = this._otherProps._text_color;
if(this.catNameLabels && typeof this.catNameLabels[0][lNum] == "string")
{
curLabel = this.catNameLabels[0][lNum];
isFormatCellTrue = "General";
}
else
curLabel = labels[lNum];
OfficeExcel.Text(context,
this._otherProps._text_font,
text_size,
centerx + explosion_offsetx + ((this.radius - 10)* Math.cos(a)),
this.centery + explosion_offsety + (((this.radius - 10) * Math.sin(a))),
OfficeExcel.numToFormatText(curLabel,isFormatCellTrue),
vAlignment,
hAlignment, false, null,null, bold, null, textOptions);
}
context.fill();
}
}
OfficeExcel.Pie.prototype.DrawBorders = function ()
{
if (this._otherProps._linewidth > 0) {
this.context.lineWidth = this._otherProps._linewidth;
this.context.strokeStyle = this._otherProps._strokecolor;
for (var i=0,len=this.angles.length; i<len; ++i) {
this.context.beginPath();
this.context.arc(this.angles[i][2],
this.angles[i][3],
this.radius,
(this.angles[i][0]),
(this.angles[i][0] + 0.001),
0);
this.context.arc(this.angles[i][2],
this.angles[i][3],
this._otherProps._variant == 'donut' ? this.radius / 2: this.radius,
this.angles[i][0],
this.angles[i][0],
0);
this.context.closePath();
this.context.stroke();
}
}
}
/**
* Returns the radius of the pie chart
*/
OfficeExcel.Pie.prototype.getRadius = function ()
{
return Math.min(this.canvas.height - this._chartGutter._top - this._chartGutter._bottom, this.canvas.width - this._chartGutter._left - this._chartGutter._right) / 2;
}
\ No newline at end of file
"use strict";
if (typeof(window["OfficeExcel"]) == 'undefined') window["OfficeExcel"] = {};
OfficeExcel.Scatter = function (chartCanvas, data)
{
this.canvas = chartCanvas;
this.canvas.__object__ = this;
this.context = (this.canvas && this.canvas.getContext) ? this.canvas.getContext("2d") : null;
this.max = 0;
this.coords = [];
this.data = [];
this.type = 'scatter';
/**
* Compatibility with older browsers
*/
OfficeExcel.CanvasBrowserCompat(this.context);
// Chart gutter
this._chartGutter = new OfficeExcel.Gutter();
// Other Props
this._otherProps = new OfficeExcel.OtherProps();
// Handle multiple datasets being given as one argument
if (arguments[1][0] && arguments[1][0][0] && typeof(arguments[1][0][0][0]) == 'number') {
// Store the data set(s)
for (var i=0; i<arguments[1].length; ++i) {
this.data[i] = arguments[1][i];
}
// Handle multiple data sets being supplied as seperate arguments
} else {
// Store the data set(s)
for (var i=1; i<arguments.length; ++i) {
this.data[i - 1] = arguments[i];
}
}
}
/**
* The function you call to draw the line chart
*/
OfficeExcel.Scatter.prototype.Draw = function (min,max,ymin,ymax,isSkip,isFormatCell,isformatCellScOy)
{
var xScale;
// Reset the coords array
this.coords = [];
// Reset the maximum value
this.max = 0;
var i = 0;
var j = 0;
if('auto' == this._otherProps._ylabels_count && undefined != this._otherProps._ymax)
this.max = this._otherProps._ymax;
else
{
for (var i=0; i<this.data.length; ++i) {
for (j=0; j<this.data[i].length; ++j) {
this.max = Math.max(this.max, typeof(this.data[i][j][1]) == 'object' ? OfficeExcel.array_max(this.data[i][j][1]) : Math.abs(this.data[i][j][1]));
}
}
}
if(this.scale == undefined)
this.scale = OfficeExcel.getScale(this.max, this);
if('auto' == this._otherProps._ylabels_count)
{
var lengSc = this.scale.length;
//this.max = this.scale[lengSc -1];
//this.min = this._otherProps._ymin;
this._otherProps._background_grid_autofit_numhlines = lengSc-1;
this._otherProps._numyticks = lengSc -1;
var conX = true;
if(this._otherProps._type == 'burse2')
xScale = this._otherProps._labels;
else
{
if(this.xScale == undefined)
xScale = OfficeExcel.getScale(conX, this);
else
xScale = this.xScale;
}
this.xScale = xScale;
if(this._otherProps._type == 'burse2')
this._otherProps._background_grid_autofit_numvlines = xScale.length;
else
this._otherProps._background_grid_autofit_numvlines = xScale.length - 1;
this._otherProps._numxticks = xScale.length;
}
this.grapharea = this.canvas.height - this._chartGutter._top - this._chartGutter._bottom;
//Draw Area
OfficeExcel.background.DrawArea(this);
// Progressively Draw the chart
OfficeExcel.background.Draw(this);
/**
* Draw any horizontal bars that have been specified
*/
if (this._otherProps._background_hbars && this._otherProps._background_hbars.length) {
OfficeExcel.DrawBars(this);
}
/**
* Draw any vertical bars that have been specified
*/
if (this._otherProps._background_vbars && this._otherProps._background_vbars.length) {
this.DrawVBars();
}
if (!this._otherProps._noaxes) {
this.DrawAxes(min,max,ymin,ymax);
}
this.DrawLabels(xScale,isFormatCell,isformatCellScOy);
i = 0;
for(var i=0; i<this.data.length; ++i) {
this.DrawMarks(i);
if(this._otherProps._type != 'burse2')
this.DrawLine(i);
}
if (this._otherProps._line) {
for (var i=0;i<this.data.length; ++i) {
this.DrawMarks(i); // Call this again so the tickmarks appear over the line
}
}
/**
* Draw the key if necessary
*/
if (this._otherProps._key && this._otherProps._key.length) {
OfficeExcel.DrawKey(this, this._otherProps._key, this._otherProps._colors);
}
/**
* Draw " above" labels if enabled
*/
if (this._otherProps._labels_above) {
this.DrawAboveLabels(isformatCellScOy);
}
}
/**
* Draws the axes of the scatter graph
*/
OfficeExcel.Scatter.prototype.DrawAxes = function (min,max,ymin,ymax)
{
var canvas = this.canvas;
var context = this.context;
var graphHeight = OfficeExcel.GetHeight(this) - this._chartGutter._top - this._chartGutter._bottom;
context.beginPath();
context.strokeStyle = this._otherProps._axis_color;
context.lineWidth = 1;
// Draw the Y axis
if(!this._otherProps._noyaxis)
{
if('auto' == this._otherProps._ylabels_count)
{
//определяем куда ставить ось
var numNull = this._otherProps._background_grid_autofit_numvlines;
/*var arrTemp = [];
var k = 0;
for (var j=0; j < this.data.length; j++) {
for (var i=0; i<this.data[j].length; i++)
{
arrTemp[k] = this.data[j][i][0];
k++;
}
}
min = Math.min.apply(null, arrTemp);
max = Math.max.apply(null, arrTemp);*/
if(min >= 0 && max >= 0)
{
numNull = this._otherProps._background_grid_autofit_numvlines;
}
else if(min <= 0 && max <= 0)
{
numNull = 0;
}
else
{
for (var i=0; i<this.xScale.length; i++)
{
if(this.xScale[i] == 0)
{
numNull = this._otherProps._background_grid_autofit_numvlines - i;
break;
}
}
}
var nullPosition;
if(this._otherProps._type == 'burse2')
nullPosition = (this.canvas.width - this._chartGutter._left - this._chartGutter._right)/(this._otherProps._background_grid_autofit_numvlines)*this._otherProps._background_grid_autofit_numvlines;
else if(0 == numNull)
nullPosition = 0;
else
nullPosition = (this.canvas.width - this._chartGutter._left - this._chartGutter._right)/(this._otherProps._background_grid_autofit_numvlines)*numNull;
context.moveTo(AA(this, OfficeExcel.GetWidth(this) - this._chartGutter._right - nullPosition), this._chartGutter._top);
context.lineTo(AA(this, OfficeExcel.GetWidth(this) - this._chartGutter._right - nullPosition), OfficeExcel.GetHeight(this) - this._chartGutter._bottom + 1);
this.nullPositionOX = OfficeExcel.GetWidth(this) - this._chartGutter._right - nullPosition;
//context.moveTo(this._chartGutter._left, AA(this, this.canvas.height - this._chartGutter._bottom - nullPosition));
//context.lineTo(this.canvas.width - this._chartGutter._right, AA(this, this.canvas.height - this._chartGutter._bottom - nullPosition));
}
}
// Draw the X axis
if(!this._otherProps._noxaxis)
{
if (this._otherProps._xaxis) {
if (this._otherProps._xaxispos == 'center') {
context.moveTo(this._chartGutter._left, AA(this, this._chartGutter._top + ((OfficeExcel.GetHeight(this) - this._chartGutter._top - this._chartGutter._bottom) / 2)));
context.lineTo(this.canvas.width - this._chartGutter._right, AA(this, this._chartGutter._top + ((this.canvas.height - this._chartGutter._top - this._chartGutter._bottom) / 2)));
}
else if('auto' == this._otherProps._ylabels_count)
{
//определяем куда ставить ось
var numNull = this._otherProps._background_grid_autofit_numhlines;
/*var arrTemp = []
var k = 0;
for (var j=0; j < this.data.length; j++) {
for (var i=0; i<this.data[j].length; i++)
{
arrTemp[k] = this.data[j][i][1];
k++;
}
}
min = Math.min.apply(null, arrTemp);
max = Math.max.apply(null, arrTemp);*/
if(this._otherProps._type == 'burse2')
{
ymin = min;
ymax = max;
}
if(ymin >= 0 && ymax >= 0)
{
numNull = 0;
}
else if(ymin <= 0 && ymax <= 0)
{
numNull = this._otherProps._background_grid_autofit_numhlines;
}
else
{
for (var i=0; i<this.scale.length; i++)
{
if(this.scale[i] == 0)
{
numNull = i;
break;
}
}
}
var nullPosition;
if(0 == numNull)
nullPosition = 0;
else
nullPosition = (this.canvas.height - this._chartGutter._bottom - this._chartGutter._top)/(this._otherProps._background_grid_autofit_numhlines)*numNull;
context.moveTo(this._chartGutter._left, AA(this, this.canvas.height - this._chartGutter._bottom - nullPosition));
context.lineTo(this.canvas.width - this._chartGutter._right, AA(this, this.canvas.height - this._chartGutter._bottom - nullPosition));
this.nullPositionOY = this.canvas.height - this._chartGutter._bottom - nullPosition;
}
}
}
/**
* Draw the Y tickmarks
*/
if(!this._otherProps._noyaxis)
{
var numyticks = this._otherProps._numyticks;
for (var y=this._chartGutter._top,countTick = 0; y <= this.canvas.height - this._chartGutter._bottom + 1 + (this._otherProps._xaxispos == 'center' ? 1 : 0) ; y+=(graphHeight / numyticks),countTick++) {
if(countTick == numyticks)
y = this.canvas.height - this._chartGutter._bottom;
context.moveTo(this.nullPositionOX, AA(this, y));
context.lineTo(this.nullPositionOX - 3, AA(this, y));
}
}
/**
* Draw the X tickmarks
*/
if(!this._otherProps._noxaxis)
{
var x = this._chartGutter._left;
var yStart = this.nullPositionOY;
var yEnd = this.nullPositionOY + 5;
for (var j=0; j <= this._otherProps._background_grid_autofit_numvlines; j++)
{
var newX = x + ((this.canvas.width - this._chartGutter._right - this._chartGutter._left)/(this._otherProps._background_grid_autofit_numvlines))*j;
if(j == this._otherProps._background_grid_autofit_numvlines)
newX = this.canvas.width - this._chartGutter._right;
this.context.moveTo(AA(this, newX), yStart);
this.context.lineTo(AA(this, newX), yEnd);
}
}
context.stroke();
}
/**
* Draws the labels on the scatter graph
*/
OfficeExcel.Scatter.prototype.DrawLabels = function (xScale,isFormatCell,isformatCellScOy)
{
this.context.fillStyle = this._otherProps._text_color;
var font = this._otherProps._ylabels_font;
var xMin = this._otherProps._xmin;
var text_size = this._otherProps._ylabels_size;
var units_pre = this._otherProps._units_pre;
var units_post = this._otherProps._units_post;
var numYLabels = this._otherProps._ylabels_count;
var context = this.context;
var boxed = false;
this.halfTextHeight = text_size / 2;
this.halfGraphHeight = (this.canvas.height - this._chartGutter._top - this._chartGutter._bottom) / 2;
/**
* Draw the Y yaxis labels, be it at the top or center
*/
if (this._otherProps._ylabels) {
var xPos = this._otherProps._yaxispos == 'left' ? this._chartGutter._left - 5 : OfficeExcel.GetWidth(this) - this._chartGutter._right + 5;
var align = this._otherProps._yaxispos == 'right' ? 'left' : 'right';
var bold = this._otherProps._ylabels_bold;
var textOptions =
{
color: this._otherProps._ylabels_color,
underline: this._otherProps._ylabels_underline,
italic: this._otherProps._ylabels_italic
}
if (this._otherProps._xaxispos == 'center') {
if('auto' == numYLabels)
{
for (var i=0; i<this.scale.length; ++i) {
OfficeExcel.Text(context,font,text_size,this.nullPositionOX - 10,this._chartGutter._top + this.halfTextHeight + ((i/this.scale.length) * (this.grapharea) ),OfficeExcel.numToFormatText(this.scale[this.scale.length -1 - i],isformatCellScOy),null,align,bounding,null,bgcolor, bold, null, textOptions);
}
}
}
else if (this._otherProps._xaxispos == 'top' && 'auto' == numYLabels)
{
var scale = OfficeExcel.array_reverse(this.scale);
/*var elemArr;
for (var i=0; i<this.scale.length; ++i) {
elemArr = (scale[scale.length - i])
if(0 == i)
elemArr = scale[scale.length - 1] - (scale[scale.length - 2] - scale[scale.length - 1])
OfficeExcel.Text(context,font,text_size,xpos,this._chartGutter._top + this.halfTextHeight + ((i/scale.length) * (this.grapharea) ),-elemArr,null,align,bounding,null,bgcolor);
}*/
//var xpos = this._otherProps._yaxispos == 'left' ? this._chartGutter._left - 5 : this.canvas.width - this._chartGutter._right + 5;
var xpos = 12;
var align = this._otherProps._yaxispos == 'left' ? 'right' : 'left';
align = 'right';
for (var i=0; i<this.scale.length; ++i) {
var elemArr;
elemArr = (scale[scale.length - i - 1])
//if(0 == i)
//elemArr = scale[scale.length - 1] - (scale[scale.length - 2] - scale[scale.length - 1])
if(elemArr == 0)
OfficeExcel.Text(context,font,text_size,this.nullPositionOX - xpos,this._chartGutter._top + this.halfTextHeight + ((i/(this.scale.length - 1)) * (this.grapharea) ),OfficeExcel.numToFormatText(elemArr.toString(),isformatCellScOy),null,align,null, boxed, null, bold, null, textOptions);
else
OfficeExcel.Text(context,font,text_size,this.nullPositionOX - xpos,this._chartGutter._top + this.halfTextHeight + ((i/(this.scale.length - 1)) * (this.grapharea) ),OfficeExcel.numToFormatText("-" + elemArr.toString(),isformatCellScOy),null,align,null, boxed, null, bold, null, textOptions);
}
}
else {
var xPos = this._otherProps._yaxispos == 'left' ? this._chartGutter._left - 5 : this.canvas.width - this._chartGutter._right + 5;
var align = this._otherProps._yaxispos == 'right' ? 'left' : 'right';
if('auto' == numYLabels)
{
align = 'right';
for (var i=0; i<this.scale.length; ++i) {
OfficeExcel.Text(context,font,text_size,this.nullPositionOX - 10,this._chartGutter._top + this.halfTextHeight + ((i/(this.scale.length - 1)) * (this.grapharea) ),OfficeExcel.numToFormatText(this.scale[this.scale.length -1 - i],isformatCellScOy),null,align,null,boxed, null, bold, null, textOptions);
//OfficeExcel.Text(context, font, text_size, xPos, this._chartGutter._top + ((this.canvas.height - this._chartGutter._top - this._chartGutter._bottom) * (4/5) ), this.scale[this.scale.length -1 - i], 'center', align, boxed);
}
}
}
}
/**
* Draw an X scale
*/
var bold = this._otherProps._xlabels_bold;
var textOptions =
{
color: this._otherProps._xlabels_color,
underline: this._otherProps._xlabels_underline,
italic: this._otherProps._xlabels_italic
}
var scaleFactor = 1;
if(OfficeExcel.drawingCtxCharts && OfficeExcel.drawingCtxCharts.scaleFactor)
scaleFactor = OfficeExcel.drawingCtxCharts.scaleFactor;
var offsetY = 15*scaleFactor;
font = this._otherProps._xlabels_font;
text_size = this._otherProps._xlabels_size;
if('auto' == this._otherProps._ylabels_count && this._otherProps._xlabels)
{
if(this._otherProps._yaxispos == 'right')
{
var scale = OfficeExcel.array_reverse(xScale);
var numXLabels = scale.length;
var interval = (this.canvas.width - this._chartGutter._left - this._chartGutter._right ) / (numXLabels - 1);
var y = this.canvas.height - this._chartGutter._bottom + 5 + (text_size / 2);
var units_pre_x = this._otherProps._scale_units_pre;
var units_post_x = this._otherProps._scale_units_post;
if (!this._otherProps._xmax) {
var xmax = 0;
for (var ds=0; ds<this.data.length; ++ds) {
for (var point=0; point<this.data[ds].length; ++point) {
xmax = Math.max(xmax, this.data[ds][point][0]);
}
}
//this._otherProps._xmax = OfficeExcel.getScale(xmax)[4];
}
for (var i=0; i<numXLabels; ++i) {
var num = ( (this._otherProps._xmax - this._otherProps._xmin) * ((i+1) / numXLabels)) + this._otherProps._xmin;
var x = this._chartGutter._left + ((i) * interval);
var text = scale[i];
if(text == 0)
OfficeExcel.Text(context, font, text_size, x, this.nullPositionOY + offsetY,OfficeExcel.numToFormatText(text.toString(),isFormatCell), 'center', 'center', false, null, null, bold, null, textOptions);
else
OfficeExcel.Text(context, font, text_size, x, this.nullPositionOY + offsetY, "-" + OfficeExcel.numToFormatText(text.toString(),isFormatCell), 'center', 'center', false, null, null, bold, null, textOptions);
}
}
else
{
var numXLabels = xScale.length - 1;
if(this._otherProps._type == 'burse2')
numXLabels = xScale.length;
var interval = (this.canvas.width - this._chartGutter._left - this._chartGutter._right) / numXLabels;
var y = this.canvas.height - this._chartGutter._bottom + 5 + (text_size / 2);
var units_pre_x = this._otherProps._xscale_units_pre;
var units_post_x = this._otherProps._xscale_units_post;
if (!this._otherProps._xmax) {
var xmax = 0;
for (var ds=0; ds<this.data.length; ++ds) {
for (var point=0; point<this.data[ds].length; ++point) {
xmax = Math.max(xmax, this.data[ds][point][0]);
}
}
this._otherProps._xmax = OfficeExcel.getScale(xmax)[4];
}
if(this._otherProps._type == 'burse2')
numXLabels = numXLabels - 1;
for (var i=0; i<=numXLabels; ++i) {
var num = ( (this._otherProps._xmax - this._otherProps._xmin) * ((i) / numXLabels)) + this._otherProps._xmin;
if(this._otherProps._type == 'burse2')
var x = this._chartGutter._left + ((this.canvas.width - this._chartGutter._left - this._chartGutter._right)/(this._otherProps._xmax*2)) + ((i) * interval);
else
var x = this._chartGutter._left + ((i) * interval);
var text = xScale[i];
OfficeExcel.Text(context, font, text_size, x, this.nullPositionOY + offsetY, OfficeExcel.numToFormatText(text.toString(),isFormatCell), 'center', 'center', false, null, null, bold, null, textOptions);
}
}
}
else if (this._otherProps._xscale && this._otherProps._xlabels) {
var numXLabels = this._otherProps._xscale_numlabels;
var interval = (this.canvas.width - this._chartGutter._left - this._chartGutter._right) / numXLabels;
var y = this.canvas.height - this._chartGutter._bottom + 5 + (text_size / 2);
var units_pre_x = this._otherProps._xscale_units_pre;
var units_post_x = this._otherProps._xscale_units_post;
if (!this._otherProps._xmax) {
var xmax = 0;
for (var ds=0; ds<this.data.length; ++ds) {
for (var point=0; point<this.data[ds].length; ++point) {
xmax = Math.max(xmax, this.data[ds][point][0]);
}
}
this._otherProps._xmax = OfficeExcel.getScale(xmax)[4];
}
for (var i=0; i<numXLabels; ++i) {
var num = ( (this._otherProps._xmax - this._otherProps._xmin) * ((i+1) / numXLabels)) + this._otherProps._xmin;
var x = this._chartGutter._left + ((i+1) * interval);
var text = OfficeExcel.number_format(this,
num.toFixed(this._otherProps._scale_decimals),
units_pre_x,
units_post_x);
OfficeExcel.Text(context, font, text_size, x, y, text, 'center', 'center', false, null, null, bold, null, textOptions);
}
/**
* Draw X labels
*/
} else if(this._otherProps._xlabels){
// Put the text on the X axis
var graphArea = this.canvas.width - this._chartGutter._left - this._chartGutter._right;
var xInterval = graphArea / this._otherProps._labels.length;
var xPos = this._chartGutter._left;
var yPos = (this.canvas.height - this._chartGutter._bottom) + 15;
var labels = this._otherProps._labels;
/**
* Text angle
*/
var angle = 0;
var valign = null;
var halign = 'center';
for (var i=0; i<labels.length; ++i) {
if (typeof(labels[i]) == 'object') {
var offset = 0;
OfficeExcel.Text(context,
font,
this._otherProps._text_size,
this._chartGutter._left + (graphArea * ((labels[i][1] - xMin + offset) / (this._otherProps._xmax - xMin))) + 5,
yPos,
String(labels[i][0]),
valign,
angle != 0 ? 'right' : 'left',
null,
angle, null, bold, null, textOptions
);
/**
* Draw the gray indicator line
*/
this.context.beginPath();
this.context.strokeStyle = '#bbb';
this.context.moveTo(AA(this, this._chartGutter._left + (graphArea * ((labels[i][1] - xMin)/ (this._otherProps._xmax - xMin)))), OfficeExcel.GetHeight(this) - this._chartGutter._bottom);
this.context.lineTo(AA(this, this._chartGutter._left + (graphArea * ((labels[i][1] - xMin)/ (this._otherProps._xmax - xMin)))), OfficeExcel.GetHeight(this) - this._chartGutter._bottom + 20);
this.context.stroke();
} else {
OfficeExcel.Text(context, font, this._otherProps._text_size, xPos + (this.xTickGap / 2), yPos, String(labels[i]), valign, halign, null, angle, null, bold, null, textOptions);
}
// Do this for the next time around
xPos += xInterval;
}
/**
* Draw the final indicator line
*/
if (typeof(labels[0]) == 'object') {
this.context.beginPath();
this.context.strokeStyle = '#bbb';
this.context.moveTo(this._chartGutter._left + graphArea, OfficeExcel.GetHeight(this) - this._chartGutter._bottom);
this.context.lineTo(this._chartGutter._left + graphArea, OfficeExcel.GetHeight(this) - this._chartGutter._bottom + 20);
this.context.stroke();
}
}
}
/**
* Draws the actual scatter graph marks
*
* @param i integer The dataset index
*/
OfficeExcel.Scatter.prototype.DrawMarks = function (i)
{
/**
* Reset the coords array
*/
this.coords[i] = [];
/**
* Plot the values
*/
var xmax = this._otherProps._xmax;
var default_color = this._otherProps._defaultcolor;
for (var j=0; j<this.data[i].length; ++j) {
/**
* This is here because tooltips are optional
*/
var data_point = this.data[i];
var xCoord = data_point[j][0];
var yCoord = data_point[j][1];
var color;
if(this._otherProps._colors[i])
color = this._otherProps._colors[i];
else
color = data_point[j][2] ? data_point[j][2] : default_color
var tooltip = (data_point[j] && data_point[j][3]) ? data_point[j][3] : null;
if(yCoord.toString() == "" || xCoord.toString() == "")
{
this.coords[i][j] = [];
this.coords[i][j][0] = '';
this.coords[i][j][1] = '';
this.coords[i][j][2] = null;
}
else if(!(this._otherProps._type == 'burse2' && this.data[i][j] != undefined && this.data[i][j][1] != undefined && this.data[i][j][1][0] == 0 && this.data[i][j][1][1] == 0 && this.data[i][j][1][2] == 0 && this.data[i][j][1][3] == 0))
this.DrawMark(
i,
xCoord,
yCoord,
xmax,
this.max,
color,
tooltip,
this.coords[i],
data_point
);
}
}
/**
* Draws a single scatter mark
*/
OfficeExcel.Scatter.prototype.DrawMark = function (index, x, y, xMax, yMax, color, tooltip, coords, data)
{
var tickmarks = this._otherProps._tickmarks;
var tickSize = this._otherProps._ticksize;
var xMin = this._otherProps._xmin;
var x = ((x - xMin) / (xMax - xMin)) * (this.canvas.width - this._chartGutter._left - this._chartGutter._right);
var originalX = x;
var originalY = y;
/**
* This allows tickmarks to be an array
*/
if (tickmarks && typeof(tickmarks) == 'object') {
tickmarks = tickmarks[index];
}
/**
* This allows ticksize to be an array
*/
if (typeof(tickSize) == 'object') {
var tickSize = tickSize[index];
var halfTickSize = tickSize / 2;
} else {
var halfTickSize = tickSize / 2;
}
/**
* This bit is for boxplots only
*/
if ( typeof(y) == 'object'
&& typeof(y[0]) == 'number'
&& typeof(y[1]) == 'number'
&& typeof(y[2]) == 'number'
&& typeof(y[3]) == 'number'
&& typeof(y[4]) == 'number'
) {
var yMin = this._otherProps._ymin ? this._otherProps._ymin : 0;
this._otherProps._boxplot = true;
this.graphheight = this.canvas.height - this._chartGutter._top - this._chartGutter._bottom;
if (this._otherProps._xaxispos == 'center') {
this.graphheight /= 2;
}
var y0 = (this.graphheight) - ((y[4] - yMin) / (yMax - yMin)) * (this.graphheight);
var y1 = (this.graphheight) - ((y[3] - yMin) / (yMax - yMin)) * (this.graphheight);
var y2 = (this.graphheight) - ((y[2] - yMin) / (yMax - yMin)) * (this.graphheight);
var y3 = (this.graphheight) - ((y[1] - yMin) / (yMax - yMin)) * (this.graphheight);
var y4 = (this.graphheight) - ((y[0] - yMin) / (yMax - yMin)) * (this.graphheight);
var col1 = y[5];
var col2 = y[5];
if(this._otherProps._type == 'burse2' && y[1] && y[3] && y[3] < y[1])
col2 = y[6];
// Override the boxWidth
if (typeof(y[7]) == 'number') {
var boxWidth = y[7];
}
var y = this.graphheight - y2;
} else {
var yMin = this._otherProps._ymin ? this._otherProps._ymin : 0;
var y = (( (y - yMin) / (yMax - yMin)) * (OfficeExcel.GetHeight(this) - this._chartGutter._top - this._chartGutter._bottom));
}
/**
* Account for the X axis being at the centre
*/
if (this._otherProps._xaxispos == 'center') {
y /= 2;
y += this.halfGraphHeight;
}
// This is so that points are on the graph, and not the gutter
x += this._chartGutter._left;
y = this.canvas.height - this._chartGutter._bottom - y;
this.context.beginPath();
// Color
this.context.strokeStyle = color;
/**
* Boxplots
*/
if ( this._otherProps._boxplot
&& typeof(y0) == 'number'
&& typeof(y1) == 'number'
&& typeof(y2) == 'number'
&& typeof(y3) == 'number'
&& typeof(y4) == 'number'
) {
var boxWidth = this._otherProps._boxplot_width;
// boxWidth is now a scale value, so convert it to a pixel vlue
boxWidth = (boxWidth / this._otherProps._xmax) * (this.canvas.width -this._chartGutter._left - this._chartGutter._right);
var halfBoxWidth = boxWidth / 2;
// Now draw the whiskers
this.context.beginPath();
if (this._otherProps._boxplot_capped) {
this.context.moveTo(x - halfBoxWidth, AA(this, y0 + this._chartGutter._top));
this.context.lineTo(x + halfBoxWidth, AA(this, y0 + this._chartGutter._top));
}
this.context.moveTo(AA(this, x), y0 + this._chartGutter._top);
this.context.lineTo(AA(this, x), y1 + this._chartGutter._top);
if (this._otherProps._boxplot_capped) {
this.context.moveTo(x - halfBoxWidth, AA(this, y4 + this._chartGutter._top));
this.context.lineTo(x + halfBoxWidth, AA(this, y4 + this._chartGutter._top));
}
this.context.moveTo(AA(this, x), y4 + this._chartGutter._top);
this.context.lineTo(AA(this, x), y3 + this._chartGutter._top);
this.context.stroke();
this.context.beginPath();
this.context.fillStyle = col2;
this.context.fillRect(x - halfBoxWidth, y1 + this._chartGutter._top, boxWidth, y3 - y1);
if(!g_bChartPreview)
this.context.strokeRect(x - halfBoxWidth, y1 + this._chartGutter._top, boxWidth, y3 - y1);
// Draw the upper coloured box if a value is specified
/*if (col1) {
this.context.fillStyle = col1;
this.context.fillRect(x - halfBoxWidth, y1 + this._chartGutter._top, boxWidth, y2 - y1);
}
// Draw the lower coloured box if a value is specified
if (col2) {
this.context.fillStyle = col2;
this.context.fillRect(x - halfBoxWidth, y2 + this._chartGutter._top, boxWidth, y3 - y2);
}*/
this.context.stroke();
}
/**
* Draw the tickmark, but not for boxplots
*/
if (!y0 && !y1 && !y2 && !y3 && !y4) {
this.graphheight = this.canvas.height - this._chartGutter._top - this._chartGutter._bottom;
if (tickmarks == 'circle') {
this.context.arc(x, y, halfTickSize, 0, 6.28, 0);
this.context.fillStyle = color;
this.context.fill();
} else if (tickmarks == 'plus') {
this.context.moveTo(x, y - halfTickSize);
this.context.lineTo(x, y + halfTickSize);
this.context.moveTo(x - halfTickSize, y);
this.context.lineTo(x + halfTickSize, y);
this.context.stroke();
} else if (tickmarks == 'square') {
this.context.strokeStyle = color;
this.context.fillStyle = color;
this.context.fillRect(
x - halfTickSize,
y - halfTickSize,
tickSize,
tickSize
);
//this.context.fill();
} else if (tickmarks == 'cross') {
this.context.moveTo(x - halfTickSize, y - halfTickSize);
this.context.lineTo(x + halfTickSize, y + halfTickSize);
this.context.moveTo(x + halfTickSize, y - halfTickSize);
this.context.lineTo(x - halfTickSize, y + halfTickSize);
this.context.stroke();
/**
* Diamond shape tickmarks
*/
} else if (tickmarks == 'diamond') {
this.context.fillStyle = this.context.strokeStyle;
this.context.moveTo(x, y - halfTickSize);
this.context.lineTo(x + halfTickSize, y);
this.context.lineTo(x, y + halfTickSize);
this.context.lineTo(x - halfTickSize, y);
this.context.lineTo(x, y - halfTickSize);
this.context.fill();
this.context.stroke();
/**
* Custom tickmark style
*/
} else if (typeof(tickmarks) == 'function') {
var graphWidth = OfficeExcel.GetWidth(this) - this._chartGutter._left - this._chartGutter._right
var xVal = ((x - this._chartGutter._left) / graphWidth) * xMax;
var yVal = ((this.graphheight - (y - this._chartGutter._top)) / this.graphheight) * yMax;
tickmarks(this, data, x, y, xVal, yVal, xMax, yMax, color)
/**
* No tickmarks
*/
} else if (tickmarks == null) {
/**
* Unknown tickmark type
*/
}
}
/**
* Add the tickmark to the coords array
*/
if ( this._otherProps._boxplot
&& typeof(y0) == 'number'
&& typeof(y1) == 'number'
&& typeof(y2) == 'number'
&& typeof(y3) == 'number'
&& typeof(y4) == 'number') {
x = [x - halfBoxWidth, x + halfBoxWidth];
y = [y0 + this._chartGutter._top, y1 + this._chartGutter._top, y2 + this._chartGutter._top, y3 + this._chartGutter._top, y4 + this._chartGutter._top];
}
coords.push([x, y, tooltip]);
}
/**
* Draws an optional line connecting the tick marks.
*
* @param i The index of the dataset to use
*/
OfficeExcel.Scatter.prototype.DrawLine = function (i)
{
if (this._otherProps._line && this.coords[i].length >= 2) {
this.context.lineCap = 'round';
this.context.lineJoin = 'round';
//this.context.lineWidth = this.GetLineWidth(i);// i is the index of the set of coordinates
this.context.lineWidth = 3;
this.context.strokeStyle = this._otherProps._colors[i];
this.context.beginPath();
var len = this.coords[i].length;
for (var j=0; j<this.coords[i].length; ++j) {
var xPos = this.coords[i][j][0];
var yPos = this.coords[i][j][1];
//для вычисления среднего
/*var summ = 0;
if(typeof this.coords[i][j][0] == "object")
{
for(var k = 0; k < this.coords[i][j][0].length; k++)
{
summ += this.coords[i][j][0][k];
}
if(summ != 0)
xPos = summ/this.coords[i][j][0].length;
}
var summ = 0;
if(typeof this.coords[i][j][1] == "object")
{
for(var k = 0; k < this.coords[i][j][1].length; k++)
{
summ += this.coords[i][j][1][k];
}
if(summ != 0)
yPos = summ/this.coords[i][j][1].length;
}*/
if (j == 0) {
this.context.moveTo(xPos, yPos);
} else {
// Stepped?
var stepped = this._otherProps._line_stepped;
if ( (typeof(stepped) == 'boolean' && stepped)
|| (typeof(stepped) == 'object' && stepped[i])
) {
this.context.lineTo(this.coords[i][j][0], this.coords[i][j - 1][1]);
}
if(xPos.toString() != "" && yPos.toString() != "" && this.coords[i][j - 1][0].toString() != "" && this.coords[i][j - 1][1].toString() != "")
{
this.context.lineTo(xPos, yPos);
}
else if(xPos.toString() != "" && yPos.toString() != "")
this.context.moveTo(xPos, yPos);
//else
//this.context.moveTo(xPos, yPos);
}
}
this.context.stroke();
}
/**
* Set the linewidth back to 1
*/
this.context.lineWidth = 1;
}
/**
* Returns the linewidth
*
* @param number i The index of the "line" (/set of coordinates)
*/
OfficeExcel.Scatter.prototype.GetLineWidth = function (i)
{
var linewidth = this._otherProps._line_linewidth;
if (typeof(linewidth) == 'number') {
return linewidth;
} else if (typeof(linewidth) == 'object') {
if (linewidth[i]) {
return linewidth[i];
} else {
return linewidth[0];
}
}
}
/**
* Draws vertical bars. Line chart doesn't use a horizontal scale, hence this function
* is not common
*/
OfficeExcel.Scatter.prototype.DrawVBars = function ()
{
var canvas = this.canvas;
var context = this.context;
var vbars = this._otherProps._background_vbars;
var graphWidth = OfficeExcel.GetWidth(this) - this._chartGutter._left - this._chartGutter._right;
if (vbars) {
var xmax = this._otherProps._xmax;
for (var i=0; i<vbars.length; ++i) {
var startX = ((vbars[i][0] / xmax) * graphWidth) + this._chartGutter._left;
var width = (vbars[i][1] / xmax) * graphWidth;
context.beginPath();
context.fillStyle = vbars[i][2];
context.fillRect(startX, this._chartGutter._top, width, (OfficeExcel.GetHeight(this) - this._chartGutter._top - this._chartGutter._bottom));
context.fill();
}
}
}
/**
* Draws the above line labels
*/
OfficeExcel.Scatter.prototype.DrawAboveLabels = function (format)
{
var context = this.context;
var size = this._otherProps._labels_above_size;
var font = this._otherProps._text_font;
var bold = this._otherProps._labels_above_bold;
var textOptions =
{
color: this._otherProps._labels_above_color,
underline: this._otherProps._labels_above_underline,
italic: this._otherProps._labels_above_italic
}
context.strokeStyle = 'black';
context.fillStyle = 'black';
for (var _set=0; _set<this.coords.length; ++_set) {
for (var point=0; point<this.coords[_set].length; ++point) {
var y_val = this.data[_set][point][1];
var formatTrue = format;
if(this.arrFormatAdobeLabels && this.arrFormatAdobeLabels[_set] && this.arrFormatAdobeLabels[_set][point] && this.arrFormatAdobeLabels[_set][point][1])
formatTrue = this.arrFormatAdobeLabels[_set][point][1];
var x_pos = this.coords[_set][point][0];
var y_pos = this.coords[_set][point][1];
OfficeExcel.Text(context,
font,
size,
x_pos,
y_pos - 5 - size,
OfficeExcel.numToFormatText(OfficeExcel.num_round(y_val),formatTrue),
'center',
'center',
false,//рамка
null,
'rgba(255, 255, 255, 0.7)', bold, null, textOptions);
}
}
}
\ No newline at end of file
......@@ -106,16 +106,6 @@
<!--for chart-->
<script type="text/javascript" src="../../Common/SerializeCommonWordExcel.js"></script>
<script type="text/javascript" src="../../Common/SerializeChart.js"></script>
<script src="../../Common/Charts/libraries/OfficeExcel.common.core.js"></script>
<script src="../../Common/Charts/libraries/OfficeExcel.common.key.js"></script>
<script src="../../Common/Charts/libraries/OfficeExcel.bar.js"></script>
<script src="../../Common/Charts/libraries/OfficeExcel.hbar.js"></script>
<script src="../../Common/Charts/libraries/OfficeExcel.line.js"></script>
<script src="../../Common/Charts/libraries/OfficeExcel.pie.js"></script>
<script src="../../Common/Charts/libraries/OfficeExcel.scatter.js"></script>
<script src="../../Common/Charts/libraries/OfficeExcel.chartProperties.js"></script>
<!--for shapes-->
<script src="../../Common/Drawings/Hit.js"></script>
......
......@@ -124,16 +124,6 @@
<!--for chart-->
<script type="text/javascript" src="../Common/SerializeCommonWordExcel.js"></script>
<script type="text/javascript" src="../Common/SerializeChart.js"></script>
<script src="../Common/Charts/libraries/OfficeExcel.common.core.js"></script>
<script src="../Common/Charts/libraries/OfficeExcel.common.key.js"></script>
<script src="../Common/Charts/libraries/OfficeExcel.bar.js"></script>
<script src="../Common/Charts/libraries/OfficeExcel.hbar.js"></script>
<script src="../Common/Charts/libraries/OfficeExcel.line.js"></script>
<script src="../Common/Charts/libraries/OfficeExcel.pie.js"></script>
<script src="../Common/Charts/libraries/OfficeExcel.scatter.js"></script>
<script src="../Common/Charts/libraries/OfficeExcel.chartProperties.js"></script>
<!--for shapes-->
<script src="../Common/Drawings/Hit.js"></script>
......
......@@ -113,16 +113,6 @@
<!--for chart-->
<script type="text/javascript" src="../Common/SerializeCommonWordExcel.js"></script>
<script src="../Common/Charts/libraries/OfficeExcel.common.core.js"></script>
<script src="../Common/Charts/libraries/OfficeExcel.common.key.js"></script>
<script src="../Common/Charts/libraries/OfficeExcel.bar.js"></script>
<script src="../Common/Charts/libraries/OfficeExcel.hbar.js"></script>
<script src="../Common/Charts/libraries/OfficeExcel.line.js"></script>
<script src="../Common/Charts/libraries/OfficeExcel.pie.js"></script>
<script src="../Common/Charts/libraries/OfficeExcel.scatter.js"></script>
<script src="../Common/Charts/libraries/OfficeExcel.chartProperties.js"></script>
<!--for shapes-->
<script src="../Common/Drawings/Hit.js"></script>
......
......@@ -165,16 +165,6 @@
<!--for chart-->
<script type="text/javascript" src="../../../../OfficeWeb/Common/SerializeCommonWordExcel.js"></script>
<script type="text/javascript" src="../../../../OfficeWeb/Common/SerializeChart.js"></script>
<script src="../../../../OfficeWeb/Common/Charts/libraries/OfficeExcel.common.core.js"></script>
<script src="../../../../OfficeWeb/Common/Charts/libraries/OfficeExcel.common.key.js"></script>
<script src="../../../../OfficeWeb/Common/Charts/libraries/OfficeExcel.bar.js"></script>
<script src="../../../../OfficeWeb/Common/Charts/libraries/OfficeExcel.hbar.js"></script>
<script src="../../../../OfficeWeb/Common/Charts/libraries/OfficeExcel.line.js"></script>
<script src="../../../../OfficeWeb/Common/Charts/libraries/OfficeExcel.pie.js"></script>
<script src="../../../../OfficeWeb/Common/Charts/libraries/OfficeExcel.scatter.js"></script>
<script src="../../../../OfficeWeb/Common/Charts/libraries/OfficeExcel.chartProperties.js"></script>
<!--for shapes-->
<script src="../../../../OfficeWeb/Common/Drawings/Hit.js"></script>
......
......@@ -156,16 +156,6 @@
<!--for chart-->
<script type="text/javascript" src="../../../../OfficeWeb/Common/SerializeCommonWordExcel.js"></script>
<script src="../../../../OfficeWeb/Common/Charts/libraries/OfficeExcel.common.core.js"></script>
<script src="../../../../OfficeWeb/Common/Charts/libraries/OfficeExcel.common.key.js"></script>
<script src="../../../../OfficeWeb/Common/Charts/libraries/OfficeExcel.bar.js"></script>
<script src="../../../../OfficeWeb/Common/Charts/libraries/OfficeExcel.hbar.js"></script>
<script src="../../../../OfficeWeb/Common/Charts/libraries/OfficeExcel.line.js"></script>
<script src="../../../../OfficeWeb/Common/Charts/libraries/OfficeExcel.pie.js"></script>
<script src="../../../../OfficeWeb/Common/Charts/libraries/OfficeExcel.scatter.js"></script>
<script src="../../../../OfficeWeb/Common/Charts/libraries/OfficeExcel.chartProperties.js"></script>
<!--for shapes-->
<script src="../../../../OfficeWeb/Common/Drawings/Hit.js"></script>
......
......@@ -71,17 +71,6 @@
<script src="../../OfficeWeb/Common/commonDefines.js"></script>
<script src="../../OfficeWeb/Common/Charts/libraries/OfficeExcel.common.core.js"></script>
<script src="../../OfficeWeb/Common/Charts/libraries/OfficeExcel.common.key.js"></script>
<script src="../../OfficeWeb/Common/Charts/libraries/OfficeExcel.bar.js"></script>
<script src="../../OfficeWeb/Common/Charts/libraries/OfficeExcel.hbar.js"></script>
<script src="../../OfficeWeb/Common/Charts/libraries/OfficeExcel.line.js"></script>
<script src="../../OfficeWeb/Common/Charts/libraries/OfficeExcel.pie.js"></script>
<script src="../../OfficeWeb/Common/Charts/libraries/OfficeExcel.scatter.js"></script>
<script src="../../OfficeWeb/Common/Charts/libraries/OfficeExcel.chartProperties.js"></script>
<script type="text/javascript" src="../../OfficeWeb/PowerPoint/Editor/Styles.js"></script>
<script type="text/javascript" src="../../OfficeWeb/Word/Drawing/Metafile.js"></script>
<script type="text/javascript" src="../../OfficeWeb/PowerPoint/Editor/Format/CollaborativeEditing.js"></script>
......
......@@ -145,17 +145,6 @@
<script src="../../../../OfficeWeb/Common/commonDefines.js"></script>
<script src="../../../../OfficeWeb/Common/Charts/libraries/OfficeExcel.common.core.js"></script>
<script src="../../../../OfficeWeb/Common/Charts/libraries/OfficeExcel.common.key.js"></script>
<script src="../../../../OfficeWeb/Common/Charts/libraries/OfficeExcel.bar.js"></script>
<script src="../../../../OfficeWeb/Common/Charts/libraries/OfficeExcel.hbar.js"></script>
<script src="../../../../OfficeWeb/Common/Charts/libraries/OfficeExcel.line.js"></script>
<script src="../../../../OfficeWeb/Common/Charts/libraries/OfficeExcel.pie.js"></script>
<script src="../../../../OfficeWeb/Common/Charts/libraries/OfficeExcel.scatter.js"></script>
<script src="../../../../OfficeWeb/Common/Charts/libraries/OfficeExcel.chartProperties.js"></script>
<script type="text/javascript" src="../../../../OfficeWeb/PowerPoint/Editor/Styles.js"></script>
<script type="text/javascript" src="../../../../OfficeWeb/Word/Drawing/Metafile.js"></script>
<script type="text/javascript" src="../../../../OfficeWeb/PowerPoint/Editor/Format/CollaborativeEditing.js"></script>
......
......@@ -30,19 +30,6 @@
<script type="text/javascript" src="../Common/Charts/DrawingObjects.js"></script>
<script type="text/javascript" src="../Common/Charts/charts.js"></script>
<script type="text/javascript" src="../Common/SerializeCommonWordExcel.js"></script>
<script src="../Common/Charts/libraries/OfficeExcel.common.core.js"></script>
<script src="../Common/Charts/libraries/OfficeExcel.common.annotate.js"></script>
<script src="../Common/Charts/libraries/OfficeExcel.common.context.js"></script>
<script src="../Common/Charts/libraries/OfficeExcel.common.effects.js"></script>
<script src="../Common/Charts/libraries/OfficeExcel.common.key.js"></script>
<script src="../Common/Charts/libraries/OfficeExcel.common.resizing.js"></script>
<script src="../Common/Charts/libraries/OfficeExcel.common.zoom.js"></script>
<script src="../Common/Charts/libraries/OfficeExcel.bar.js"></script>
<script src="../Common/Charts/libraries/OfficeExcel.hbar.js"></script>
<script src="../Common/Charts/libraries/OfficeExcel.line.js"></script>
<script src="../Common/Charts/libraries/OfficeExcel.pie.js"></script>
<script src="../Common/Charts/libraries/OfficeExcel.scatter.js"></script>
<script src="../Common/Charts/libraries/OfficeExcel.chartProperties.js"></script>
<script src="../Common/FontsFreeType/font_engine.js"></script>
......
......@@ -95,14 +95,6 @@
<script type="text/javascript" src="../../../../OfficeWeb/Common/SerializeCommonWordExcel.js"></script>
<script type="text/javascript" src="../../../../OfficeWeb/Common/Drawings/Format/Constants.js"></script>
<script type="text/javascript" src="../../../../OfficeWeb/Common/Drawings/Format/Format.js"></script>
<script type="text/javascript" src="../../../../OfficeWeb/Common/Charts/libraries/OfficeExcel.common.core.js"></script>
<script type="text/javascript" src="../../../../OfficeWeb/Common/Charts/libraries/OfficeExcel.common.key.js"></script>
<script type="text/javascript" src="../../../../OfficeWeb/Common/Charts/libraries/OfficeExcel.bar.js"></script>
<script type="text/javascript" src="../../../../OfficeWeb/Common/Charts/libraries/OfficeExcel.hbar.js"></script>
<script type="text/javascript" src="../../../../OfficeWeb/Common/Charts/libraries/OfficeExcel.line.js"></script>
<script type="text/javascript" src="../../../../OfficeWeb/Common/Charts/libraries/OfficeExcel.pie.js"></script>
<script type="text/javascript" src="../../../../OfficeWeb/Common/Charts/libraries/OfficeExcel.scatter.js"></script>
<script type="text/javascript" src="../../../../OfficeWeb/Common/Charts/libraries/OfficeExcel.chartProperties.js"></script>
<script type="text/javascript" src="../../../../OfficeWeb/Common/FontsFreeType/font_engine.js"></script>
......
......@@ -36,19 +36,6 @@
<script type="text/javascript" src="../../OfficeWeb/Common/Charts/charts.js"></script>
<script type="text/javascript" src="../../OfficeWeb/Common/commonDefines.js"></script>
<script type="text/javascript" src="../../OfficeWeb/Common/SerializeCommonWordExcel.js"></script>
<script type="text/javascript" src="../../OfficeWeb/Common/Charts/libraries/OfficeExcel.common.core.js"></script>
<script type="text/javascript" src="../../OfficeWeb/Common/Charts/libraries/OfficeExcel.common.annotate.js"></script>
<script type="text/javascript" src="../../OfficeWeb/Common/Charts/libraries/OfficeExcel.common.context.js"></script>
<script type="text/javascript" src="../../OfficeWeb/Common/Charts/libraries/OfficeExcel.common.effects.js"></script>
<script type="text/javascript" src="../../OfficeWeb/Common/Charts/libraries/OfficeExcel.common.key.js"></script>
<script type="text/javascript" src="../../OfficeWeb/Common/Charts/libraries/OfficeExcel.common.resizing.js"></script>
<script type="text/javascript" src="../../OfficeWeb/Common/Charts/libraries/OfficeExcel.common.zoom.js"></script>
<script type="text/javascript" src="../../OfficeWeb/Common/Charts/libraries/OfficeExcel.bar.js"></script>
<script type="text/javascript" src="../../OfficeWeb/Common/Charts/libraries/OfficeExcel.hbar.js"></script>
<script type="text/javascript" src="../../OfficeWeb/Common/Charts/libraries/OfficeExcel.line.js"></script>
<script type="text/javascript" src="../../OfficeWeb/Common/Charts/libraries/OfficeExcel.pie.js"></script>
<script type="text/javascript" src="../../OfficeWeb/Common/Charts/libraries/OfficeExcel.scatter.js"></script>
<script type="text/javascript" src="../../OfficeWeb/Common/Charts/libraries/OfficeExcel.chartProperties.js"></script>
<script type="text/javascript" src="../../OfficeWeb/Common/FontsFreeType/font_engine.js"></script>
......
......@@ -45,15 +45,6 @@
<script type="text/javascript" src="../Common/Charts/DrawingObjects.js"></script>
<script type="text/javascript" src="../Common/Charts/charts.js"></script>
<script type="text/javascript" src="../Common/SerializeCommonWordExcel.js"></script>
<script src="../Common/Charts/libraries/OfficeExcel.common.core.js"></script>
<script src="../Common/Charts/libraries/OfficeExcel.common.key.js"></script>
<script src="../Common/Charts/libraries/OfficeExcel.bar.js"></script>
<script src="../Common/Charts/libraries/OfficeExcel.hbar.js"></script>
<script src="../Common/Charts/libraries/OfficeExcel.line.js"></script>
<script src="../Common/Charts/libraries/OfficeExcel.pie.js"></script>
<script src="../Common/Charts/libraries/OfficeExcel.scatter.js"></script>
<script src="../Common/Charts/libraries/OfficeExcel.chartProperties.js"></script>
<script type="text/javascript" src="menu/main_menu.js"></script>
<script type="text/javascript" src="menu/Statusbar.js"></script>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment