Commit 5fe639ee authored by Igor.Zotov's avatar Igor.Zotov Committed by Alexander.Trofimov

сглаженная линия для точечной диаграммы

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@55293 954022d7-b5bf-4e40-9824-e11837661b57
parent 5f285802
......@@ -3420,6 +3420,105 @@ CChartsDrawer.prototype =
val = val / numPow;
return {val: val, numPow: numPow};
},
//***spline functions***
calculate_Bezier: function(x, y, x1, y1, x2, y2, x3, y3, t)
{
var pts = [], bz = [];
pts[0] = {x: x, y: y};
pts[1] = {x: x1, y: y1};
pts[2] = {x: x2, y: y2};
pts[3] = {x: x3, y: y3};
var d01 = this.XYZDist(pts[0], pts[1]);
var d12 = this.XYZDist(pts[1], pts[2]);
var d23 = this.XYZDist(pts[2], pts[3]);
var d02 = this.XYZDist(pts[0], pts[2]);
var d13 = this.XYZDist(pts[1], pts[3]);
bz[0] = pts[1];
if ((d02 / 6 < d12 / 2) && (d13 / 6 < d12 / 2))
{
var f;
if (x != x1)
f = 1 / 6;
else
f = 1 / 3;
bz[1] = this.XYZAdd(pts[1], this.XYZMult(this.XYZSub(pts[2], pts[0]), f));
if (x2 != x3)
f = 1 / 6;
else
f = 1 / 3;
bz[2] = this.XYZAdd(pts[2], this.XYZMult(this.XYZSub(pts[1], pts[3]), f))
}
else if ((d02 / 6 >= d12 / 2) && (d13 / 6 >= d12 / 2))
{
bz[1] = this.XYZAdd(pts[1], this.XYZMult(this.XYZSub(pts[2], pts[0]), d12 / 2 / d02))
bz[2] = this.XYZAdd(pts[2], this.XYZMult(this.XYZSub(pts[1], pts[3]), d12 / 2 / d13))
}
else if((d02 / 6 >= d12 / 2))
{
bz[1] = this.XYZAdd(pts[1], this.XYZMult(this.XYZSub(pts[2], pts[0]), d12 / 2 / d02))
bz[2] = this.XYZAdd(pts[2], this.XYZMult(this.XYZSub(pts[1], pts[3]), d12 / 2 / d13 * (d13 / d02)))
}
else
{
bz[1] = this.XYZAdd(pts[1], this.XYZMult(this.XYZSub(pts[2], pts[0]), d12 / 2 / d02 * (d02 / d13)))
bz[2] = this.XYZAdd(pts[2], this.XYZMult(this.XYZSub(pts[1], pts[3]), d12 / 2 / d13))
}
bz[3] = pts[2];
var pt = this._bezier4(bz[0], bz[1], bz[2], bz[3], t);
return [pt.x, pt.y];
},
_bezier4: function(p1, p2, p3, p4, t)
{
var mum1, mum13, t3, mum12, t2;
var p = {};
mum1 = 1 - t;
mum13 = mum1 * mum1 * mum1;
mum12 = mum1 * mum1;
t2 = t * t
t3 = t * t * t;
p.x = mum13 * p1.x + 3 * t * mum12 * p2.x + 3 * t2 * mum1 * p3.x + t3 * p4.x;
p.y = mum13 * p1.y + 3 * t * mum12 * p2.y + 3 * t2 * mum1 * p3.y + t3 * p4.y;
return p;
},
XYZAdd: function(a, b)
{
return {x: a.x + b.x, y: a.y + b.y};
},
XYZSub: function(a, b)
{
return {x: a.x - b.x, y: a.y - b.y};
},
XYZMult: function(a, b)
{
return {x: a.x * b, y: a.y * b};
},
XYZDist: function(a, b)
{
return Math.pow((Math.pow((a.x - b.x), 2) + Math.pow((a.y - b.y), 2)), 0.5);
}
}
......@@ -5649,6 +5748,7 @@ drawScatterChart.prototype =
var xPoints = this.cShapeDrawer.chart.plotArea.catAx.xPoints;
//соответствует подписям оси значений(OY)
var yPoints = this.cShapeDrawer.chart.plotArea.valAx.yPoints;
var isSplineLine = true;
var trueHeight = this.chartProp.trueHeight;
var trueWidth = this.chartProp.trueWidth;
......@@ -5696,27 +5796,35 @@ drawScatterChart.prototype =
for(var k = 0; k < points.length; k++)
{
if(k == points.length - 1)
if(!this.paths.series)
this.paths.series = [];
if(!this.paths.series[i])
this.paths.series[i] = [];
if(isSplineLine)
{
y = this.cChartDrawer.getYPosition(points[k].y, yPoints);
x = this.cChartDrawer.getYPosition(points[k].x, xPoints, true);
this.paths.series[i][k] = this._calculateSplineLine(points, k, xPoints, yPoints);
}
else
{
y = this.cChartDrawer.getYPosition(points[k].y, yPoints);
y1 = this.cChartDrawer.getYPosition(points[k + 1].y, yPoints);
x = this.cChartDrawer.getYPosition(points[k].x, xPoints, true);
x1 = this.cChartDrawer.getYPosition(points[k + 1].x, xPoints, true);
if(!this.paths.series)
this.paths.series = [];
if(!this.paths.series[i])
this.paths.series[i] = [];
if(k == points.length - 1)
{
y = this.cChartDrawer.getYPosition(points[k].y, yPoints);
x = this.cChartDrawer.getYPosition(points[k].x, xPoints, true);
}
else
{
y = this.cChartDrawer.getYPosition(points[k].y, yPoints);
y1 = this.cChartDrawer.getYPosition(points[k + 1].y, yPoints);
this.paths.series[i][k] = this._calculateLine(x, y, x1, y1);
x = this.cChartDrawer.getYPosition(points[k].x, xPoints, true);
x1 = this.cChartDrawer.getYPosition(points[k + 1].x, xPoints, true);
this.paths.series[i][k] = this._calculateLine(x, y, x1, y1);
}
}
if(!this.paths.points)
this.paths.points = [];
if(!this.paths.points[i])
......@@ -5939,6 +6047,62 @@ drawScatterChart.prototype =
cGeometry.AddPath(path);
this.cShapeDrawer.draw(cGeometry);
},
_calculateSplineLine : function(points, k, xPoints, yPoints)
{
var path = new Path();
var splineCoords;
var pathH = this.chartProp.pathH;
var pathW = this.chartProp.pathW;
var gdLst = [];
path.pathH = pathH;
path.pathW = pathW;
gdLst["w"] = 1;
gdLst["h"] = 1;
var startCoords;
var endCoords;
var x = points[k - 1] ? points[k - 1].x : points[k].x;
var y = points[k - 1] ? points[k - 1].y : points[k].y;
var x1 = points[k].x;
var y1 = points[k].y;
var x2 = points[k + 1] ? points[k + 1].x : points[k].x;
var y2 = points[k + 1] ? points[k + 1].y : points[k].y;
var x3 = points[k + 2] ? points[k + 2].x : points[k].x;
var y3 = points[k + 2] ? points[k + 2].y : points[k].y;
for(var i = 0; i <= 1;)
{
splineCoords = this.cChartDrawer.calculate_Bezier(x, y, x1, y1, x2, y2, x3, y3, i);
if(i == 0)
{
startCoords = {x: this.cChartDrawer.getYPosition(splineCoords[0], xPoints, true), y: this.cChartDrawer.getYPosition(splineCoords[1], yPoints)};
}
endCoords = {x: this.cChartDrawer.getYPosition(splineCoords[0], xPoints, true), y: this.cChartDrawer.getYPosition(splineCoords[1], yPoints)};
if(i == 0)
path.moveTo(startCoords.x * pathW, startCoords.y * pathH);
path.lnTo(endCoords.x * pathW, endCoords.y * pathH);
i = i + 0.1;
};
path.recalculate(gdLst);
return path;
}
};
......
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