提交 2fcdde6e 编写于 作者: L lang

Improve polar to support startAngle and clockwise

上级 75b33832
...@@ -173,7 +173,8 @@ define(function(require) { ...@@ -173,7 +173,8 @@ define(function(require) {
group.add(polygon); group.add(polygon);
} }
polyline.setStyle(zrUtil.extend( polyline.setStyle(zrUtil.defaults(
// Use color in lineStyle first
lineStyleModel.getLineStyle(), lineStyleModel.getLineStyle(),
{ {
stroke: data.getVisual('color'), stroke: data.getVisual('color'),
...@@ -408,12 +409,13 @@ define(function(require) { ...@@ -408,12 +409,13 @@ define(function(require) {
}, },
_createPolarClipShape: function (polar, animation) { _createPolarClipShape: function (polar, animation) {
// var angleAxis = polar.getAngleAxis(); var angleAxis = polar.getAngleAxis();
var radiusAxis = polar.getRadiusAxis(); var radiusAxis = polar.getRadiusAxis();
var radiusExtent = radiusAxis.getExtent(); var radiusExtent = radiusAxis.getExtent();
var angleExtent = angleAxis.getExtent();
var PI2 = Math.PI * 2; var RADIAN = Math.PI / 180;
var clipPath = new graphic.Sector({ var clipPath = new graphic.Sector({
shape: { shape: {
...@@ -421,16 +423,17 @@ define(function(require) { ...@@ -421,16 +423,17 @@ define(function(require) {
cy: polar.cy, cy: polar.cy,
r0: radiusExtent[0], r0: radiusExtent[0],
r: radiusExtent[1], r: radiusExtent[1],
startAngle: 0, startAngle: -angleExtent[0] * RADIAN,
endAngle: PI2 endAngle: -angleExtent[1] * RADIAN,
clockwise: angleAxis.inverse
} }
}); });
if (animation) { if (animation) {
clipPath.shape.endAngle = 0; clipPath.shape.endAngle = -angleExtent[0] * RADIAN;
clipPath.animateTo({ clipPath.animateTo({
shape: { shape: {
endAngle: PI2 endAngle: -angleExtent[1] * RADIAN
} }
}, 1500, animation); }, 1500, animation);
} }
......
...@@ -119,7 +119,7 @@ define(function (require) { ...@@ -119,7 +119,7 @@ define(function (require) {
textFont: textStyleModel.getFont() textFont: textStyleModel.getFont()
}, },
silent: true silent: true
})) }));
} }
}, },
...@@ -141,7 +141,7 @@ define(function (require) { ...@@ -141,7 +141,7 @@ define(function (require) {
splitLines[colorIndex] = splitLines[colorIndex] || []; splitLines[colorIndex] = splitLines[colorIndex] || [];
splitLines[colorIndex].push(new graphic.Line({ splitLines[colorIndex].push(new graphic.Line({
shape: getAxisLineShape(polar, radiusExtent[0], radiusExtent[1], ticksAngles[i]) shape: getAxisLineShape(polar, radiusExtent[0], radiusExtent[1], ticksAngles[i])
})) }));
} }
// Simple optimization // Simple optimization
......
...@@ -16,10 +16,11 @@ define(function (require) { ...@@ -16,10 +16,11 @@ define(function (require) {
this.group.removeAll(); this.group.removeAll();
var polarModel = ecModel.getComponent('polar', radiusAxisModel.get('polarIndex')); var polarModel = ecModel.getComponent('polar', radiusAxisModel.get('polarIndex'));
var angleAxis = polarModel.coordinateSystem.getAngleAxis();
var radiusAxis = radiusAxisModel.axis; var radiusAxis = radiusAxisModel.axis;
var polar = polarModel.coordinateSystem; var polar = polarModel.coordinateSystem;
var ticksCoords = radiusAxis.getTicksCoords(); var ticksCoords = radiusAxis.getTicksCoords();
var axisAngle = radiusAxisModel.get('axisAngle'); var axisAngle = angleAxis.getExtent()[0];
var radiusExtent = radiusAxis.getExtent(); var radiusExtent = radiusAxis.getExtent();
zrUtil.each(elementList, function (name) { zrUtil.each(elementList, function (name) {
if (radiusAxisModel.get(name +'.show')) { if (radiusAxisModel.get(name +'.show')) {
...@@ -95,6 +96,7 @@ define(function (require) { ...@@ -95,6 +96,7 @@ define(function (require) {
var axis = radiusAxisModel.axis; var axis = radiusAxisModel.axis;
var labelModel = radiusAxisModel.getModel('axisLabel'); var labelModel = radiusAxisModel.getModel('axisLabel');
var textStyleModel = labelModel.getModel('textStyle'); var textStyleModel = labelModel.getModel('textStyle');
var tickModel = radiusAxisModel.getModel('axisTick');
var labels = radiusAxisModel.formatLabels(axis.scale.getTicksLabels()); var labels = radiusAxisModel.formatLabels(axis.scale.getTicksLabels());
...@@ -102,34 +104,42 @@ define(function (require) { ...@@ -102,34 +104,42 @@ define(function (require) {
var end = polar.coordToPoint([radiusExtent[1], axisAngle]); var end = polar.coordToPoint([radiusExtent[1], axisAngle]);
var len = vector.dist(end, start); var len = vector.dist(end, start);
var direction = [ var dir = [
end[1] - start[1], end[1] - start[1],
start[0] - end[0] start[0] - end[0]
]; ];
vector.normalize(direction, direction); vector.normalize(dir, dir);
var p = []; var p = [];
var tickLen = tickModel.get('length');
var labelMargin = labelModel.get('margin'); var labelMargin = labelModel.get('margin');
var labelsPositions = axis.getLabelsCoords(); var labelsPositions = axis.getLabelsCoords();
var labelRotate = labelModel.get('rotate'); var labelRotate = labelModel.get('rotate');
var labelTextAlign = 'center'; var labelTextAlign = 'center';
if (labelRotate) { if (labelRotate) {
labelTextAlign = labelRotate > 0 ? 'left' : 'right' labelTextAlign = labelRotate > 0 ? 'left' : 'right';
}
// Point to top
if (dir[0] > -0.3 && dir[0] <= 0) {
labelTextAlign = 'right';
}
else if (dir[0] < 0.3 && dir[0] >= 0) {
labelTextAlign = 'left';
} }
// FIXME Text align and text baseline when axis angle is 90 degree // FIXME Text align and text baseline when axis angle is 90 degree
for (var i = 0; i < labelsPositions.length; i++) { for (var i = 0; i < labelsPositions.length; i++) {
// Get point on axis // Get point on axis
vector.lerp(p, start, end, labelsPositions[i] / len); vector.lerp(p, start, end, labelsPositions[i] / len);
vector.scaleAndAdd(p, p, direction, labelMargin); vector.scaleAndAdd(p, p, dir, labelMargin + tickLen);
this.group.add(new graphic.Text({ this.group.add(new graphic.Text({
style: { style: {
x: p[0], x: p[0],
y: p[1], y: p[1],
text: labels[i], text: labels[i],
textAlign: labelTextAlign, textAlign: labelTextAlign,
textBaseline: 'bottom', textBaseline: dir[1] > 0.4 ? 'bottom' : (dir[1] < -0.4 ? 'top' : 'middle'),
textFont: textStyleModel.getFont() textFont: textStyleModel.getFont()
}, },
rotation: labelRotate * Math.PI / 180, rotation: labelRotate * Math.PI / 180,
......
...@@ -491,8 +491,9 @@ define(function (require) { ...@@ -491,8 +491,9 @@ define(function (require) {
targetShape = makeSectorShape( targetShape = makeSectorShape(
polar.cx, polar.cy, polar.cx, polar.cy,
otherExtent[0], otherExtent[1], otherExtent[0], otherExtent[1],
(mouseCoord[1] - bandWidth / 2) * radian, // In ECharts y is negative if angle is positive
(mouseCoord[1] + bandWidth / 2) * radian (-mouseCoord[1] - bandWidth / 2) * radian,
(-mouseCoord[1] + bandWidth / 2) * radian
); );
} }
else { else {
......
...@@ -104,13 +104,14 @@ define(function (require) { ...@@ -104,13 +104,14 @@ define(function (require) {
/** /**
* Set coord extent * Set coord extent
* @param {number} min * @param {number} start
* @param {number} max * @param {number} end
*/ */
setExtent: function (min, max) { setExtent: function (start, end) {
var extent = this._extent; var extent = this._extent;
extent[0] = min; var inverse = this.inverse;
extent[1] = max; extent[0] = inverse ? end : start;
extent[1] = inverse ? start : end;
}, },
/** /**
...@@ -197,17 +198,17 @@ define(function (require) { ...@@ -197,17 +198,17 @@ define(function (require) {
*/ */
// FIXME Situation when labels is on ticks // FIXME Situation when labels is on ticks
getBands: function () { getBands: function () {
var extent = this._extent; var extent = this.getExtent();
var bands = []; var bands = [];
var len = this.scale.count(); var len = this.scale.count();
var start = extent[0]; var start = extent[0];
var end = extent[1]; var end = extent[1];
var size = end - start; var span = end - start;
for (var i = 0; i < len; i++) { for (var i = 0; i < len; i++) {
bands.push([ bands.push([
size * i / len + start, span * i / len + start,
size * (i + 1) / len + start span * (i + 1) / len + start
]); ]);
} }
return bands; return bands;
......
...@@ -34,7 +34,6 @@ define(function(require) { ...@@ -34,7 +34,6 @@ define(function(require) {
zrUtil.merge(AxisModel.prototype, require('../axisModelCommonMixin')); zrUtil.merge(AxisModel.prototype, require('../axisModelCommonMixin'));
// x axis // x axis
AxisModel.extend({ AxisModel.extend({
......
...@@ -19,7 +19,7 @@ define(function(require) { ...@@ -19,7 +19,7 @@ define(function(require) {
* @type {string} * @type {string}
*/ */
this.type = 'category'; this.type = 'category';
}; }
AngleAxis.prototype = { AngleAxis.prototype = {
......
...@@ -47,8 +47,6 @@ define(function(require) { ...@@ -47,8 +47,6 @@ define(function(require) {
polarIndex: 0, polarIndex: 0,
axisAngle: 0,
splitNumber: 5 splitNumber: 5
} }
}); });
...@@ -75,7 +73,9 @@ define(function(require) { ...@@ -75,7 +73,9 @@ define(function(require) {
polarIndex: 0, polarIndex: 0,
clockWise: true, startAngle: 90,
clockwise: true,
splitNumber: 12, splitNumber: 12,
......
...@@ -159,7 +159,7 @@ define(function(require) { ...@@ -159,7 +159,7 @@ define(function(require) {
return this.coordToPoint([ return this.coordToPoint([
this._radiusAxis.dataToRadius(data[0], clamp), this._radiusAxis.dataToRadius(data[0], clamp),
this._angleAxis.dataToAngle(data[1], clamp) this._angleAxis.dataToAngle(data[1], clamp)
]) ]);
}, },
/** /**
...@@ -184,20 +184,24 @@ define(function(require) { ...@@ -184,20 +184,24 @@ define(function(require) {
pointToCoord: function (point) { pointToCoord: function (point) {
var dx = point[0] - this.cx; var dx = point[0] - this.cx;
var dy = point[1] - this.cy; var dy = point[1] - this.cy;
var angleAxis = this.getAngleAxis();
var extent = angleAxis.getExtent();
var minAngle = Math.min(extent[0], extent[1]);
var maxAngle = Math.max(extent[0], extent[1]);
var radius = Math.sqrt(dx * dx + dy * dy); var radius = Math.sqrt(dx * dx + dy * dy);
dx /= radius; dx /= radius;
dy /= radius; dy /= radius;
var radian = Math.atan2(dy, dx); var radian = Math.atan2(-dy, dx) / Math.PI * 180;
// Threshold to 0 - 360 // move to angleExtent
// FIXME Angle Extent ? var dir = radian < minAngle ? 1 : -1;
if (radian < 0) { while (radian < minAngle || radian > maxAngle) {
radian += Math.PI * 2; radian += dir * 360;
} }
return [radius, radian / Math.PI * 180]; return [radius, radian];
}, },
/** /**
...@@ -209,11 +213,12 @@ define(function(require) { ...@@ -209,11 +213,12 @@ define(function(require) {
var radius = coord[0]; var radius = coord[0];
var radian = coord[1] / 180 * Math.PI; var radian = coord[1] / 180 * Math.PI;
var x = Math.cos(radian) * radius + this.cx; var x = Math.cos(radian) * radius + this.cx;
var y = Math.sin(radian) * radius + this.cy; // Inverse the y
var y = -Math.sin(radian) * radius + this.cy;
return [x, y]; return [x, y];
} }
} };
return Polar; return Polar;
}); });
\ No newline at end of file
...@@ -46,6 +46,12 @@ define(function (require) { ...@@ -46,6 +46,12 @@ define(function (require) {
axis.onBand = axisModel.get('boundaryGap') && axis.type === 'category'; axis.onBand = axisModel.get('boundaryGap') && axis.type === 'category';
axis.inverse = axisModel.get('inverse'); axis.inverse = axisModel.get('inverse');
if (axisModel.type === 'angleAxis') {
var startAngle = axisModel.get('startAngle');
axis.setExtent(startAngle, startAngle + 360);
axis.inverse = axisModel.get('clockwise');
}
// Inject axis instance // Inject axis instance
axisModel.axis = axis; axisModel.axis = axis;
axis.model = axisModel; axis.model = axisModel;
...@@ -118,8 +124,10 @@ define(function (require) { ...@@ -118,8 +124,10 @@ define(function (require) {
zrUtil.each(polarList, function (polar) { zrUtil.each(polarList, function (polar) {
var angleAxis = polar.getAngleAxis(); var angleAxis = polar.getAngleAxis();
if (angleAxis.type === 'category' && !angleAxis.onBand) { if (angleAxis.type === 'category' && !angleAxis.onBand) {
var angle = 360 - 360 / (angleAxis.scale.count() + 1); var extent = angleAxis.getExtent();
angleAxis.setExtent(0, angle); var diff = 360 / (angleAxis.scale.count() + 1);
angleAxis.inverse ? (extent[1] += diff) : (extent[1] -= diff);
angleAxis.setExtent(extent[0], extent[1]);
} }
}); });
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册