提交 ec6e366f 编写于 作者: L lang

Rename axis mapData, unmapData to dataToCoord, coordToData

上级 e8fe8870
......@@ -42,7 +42,7 @@ define(function(require) {
var cx = polar.cx;
var cy = polar.cy;
var radiusExtent = polar.getRadiusAxis().getExtent();
var ticksAngles = angleAxis.getTicksPositions();
var ticksAngles = angleAxis.getTicksCoords();
if (angleAxis.type !== 'category') {
// Remove the last tick which will overlap the first tick
......@@ -107,7 +107,7 @@ define(function(require) {
var labels = angleAxisModel.formatLabels(axis.scale.getTicksLabels());
var labelMargin = labelModel.get('margin');
var labelsAngles = axis.getLabelsPositions();
var labelsAngles = axis.getLabelsCoords();
// Use length of ticksAngles because it may remove the last tick to avoid overlapping
for (var i = 0; i < ticksAngles.length; i++) {
......
......@@ -129,7 +129,7 @@ define(function(require) {
}
var axisPosition = axis.position;
var ticksCoords = axis.getTicksPositions();
var ticksCoords = axis.getTicksCoords();
var tickLines = [];
for (var i = 0; i < ticksCoords.length; i++) {
......@@ -325,7 +325,7 @@ define(function(require) {
var splitLines = [];
var lineCount = 0;
var ticksCoords = axis.getTicksPositions();
var ticksCoords = axis.getTicksCoords();
var p1 = [];
var p2 = [];
......@@ -390,7 +390,7 @@ define(function(require) {
var areaColors = splitAreaModel.get('areaStyle.color');
var gridRect = gridModel.coordinateSystem.getRect();
var ticksCoords = axis.getTicksPositions();
var ticksCoords = axis.getTicksCoords();
var prevX = ticksCoords[0];
var prevY = ticksCoords[0];
......
......@@ -48,10 +48,10 @@ define(function(require) {
var cx = polar.cx;
var cy = polar.cy;
var angleExtent = polar.getAngleAxis().getExtent();
var ticksPositions = radiusAxis.getTicksPositions();
var ticksCoords = radiusAxis.getTicksCoords();
zrUtil.each(elementList, function (name) {
if (radiusAxisModel.get(name +'.show')) {
this['_' + name](radiusAxisModel, ticksPositions, angleExtent, cx, cy, api);
this['_' + name](radiusAxisModel, ticksCoords, angleExtent, cx, cy, api);
}
}, this);
......@@ -64,7 +64,7 @@ define(function(require) {
/**
* @private
*/
_axisLine: function (radiusAxisModel, ticksPositions, angleExtent, cx, cy, api) {
_axisLine: function (radiusAxisModel, ticksCoords, angleExtent, cx, cy, api) {
var arc = new api.Line({
shape: getAxisLineShape(radiusAxisModel, cx, cy),
style: radiusAxisModel.getModel('axisLine.lineStyle').getLineStyle()
......@@ -76,7 +76,7 @@ define(function(require) {
/**
* @private
*/
_axisTick: function (radiusAxisModel, ticksPositions, angleExtent, cx, cy, api) {
_axisTick: function (radiusAxisModel, ticksCoords, angleExtent, cx, cy, api) {
var tickModel = radiusAxisModel.getModel('axisTick');
var lineShape = getAxisLineShape(radiusAxisModel, cx, cy);
......@@ -93,7 +93,7 @@ define(function(require) {
var p1 = [];
var p2 = [];
var tickLen = tickModel.get('length');
var lines = zrUtil.map(ticksPositions, function (tickPosition) {
var lines = zrUtil.map(ticksCoords, function (tickPosition) {
// Get point on axis
vector.lerp(p1, start, end, tickPosition / len);
vector.scaleAndAdd(p2, p1, direction, tickLen);
......@@ -117,7 +117,7 @@ define(function(require) {
/**
* @private
*/
_axisLabel: function (radiusAxisModel, ticksPositions, angleExtent, cx, cy, api) {
_axisLabel: function (radiusAxisModel, ticksCoords, angleExtent, cx, cy, api) {
var axis = radiusAxisModel.axis;
var labelModel = radiusAxisModel.getModel('axisLabel');
var textStyleModel = labelModel.getModel('textStyle');
......@@ -137,7 +137,7 @@ define(function(require) {
var p = [];
var labelMargin = labelModel.get('margin');
var labelsPositions = axis.getLabelsPositions();
var labelsPositions = axis.getLabelsCoords();
// FIXME Text align and text baseline when axis angle is 90 degree
for (var i = 0; i < labelsPositions.length; i++) {
......@@ -161,7 +161,7 @@ define(function(require) {
/**
* @private
*/
_splitLine: function (radiusAxisModel, ticksPositions, angleExtent, cx, cy, api) {
_splitLine: function (radiusAxisModel, ticksCoords, angleExtent, cx, cy, api) {
var splitLineModel = radiusAxisModel.getModel('splitLine');
var lineStyleModel = splitLineModel.getModel('lineStyle');
var lineColors = lineStyleModel.get('color');
......@@ -172,14 +172,14 @@ define(function(require) {
var splitLines = [];
for (var i = 0; i < ticksPositions.length; i++) {
for (var i = 0; i < ticksCoords.length; i++) {
var colorIndex = (lineCount++) % lineColors.length;
splitLines[colorIndex] = splitLines[colorIndex] || [];
splitLines[colorIndex].push(new api.Circle({
shape: {
cx: cx,
cy: cy,
r: ticksPositions[i]
r: ticksCoords[i]
},
silent: true
}))
......@@ -203,7 +203,7 @@ define(function(require) {
/**
* @private
*/
_splitArea: function (radiusAxisModel, ticksPositions, angleExtent, cx, cy, api) {
_splitArea: function (radiusAxisModel, ticksCoords, angleExtent, cx, cy, api) {
}
});
......
......@@ -50,6 +50,15 @@ define(function (require) {
constructor: Axis,
/**
* If axis extent contain give coord
* @param {number}
*/
contain: function (coord) {
var extent = this._extent;
return coord >= extent[0] && coord <= extent[1];
},
/**
* Get coord extent
* @return {Array.<number>}
......@@ -74,12 +83,12 @@ define(function (require) {
},
/**
* Map a data to extent. Data is the rank if it has a ordinal scale
* Convert data to coord. Data is the rank if it has a ordinal scale
* @param {number} data
* @param {boolean} clamp
* @return {number}
*/
mapData: function (data, clamp) {
dataToCoord: function (data, clamp) {
// PENDING
if (data == null || data === '-') {
return NaN;
......@@ -95,12 +104,12 @@ define(function (require) {
},
/**
* Unmap a data. Data is the rank if it has a ordinal scale
* Convert coord to data. Data is the rank if it has a ordinal scale
* @param {number} mapped
* @param {boolean} clamp
* @return {number}
*/
unmapData: function (mapped, clamp) {
coordToData: function (mapped, clamp) {
var extent = this.getExtent();
if (this.onBand) {
......@@ -114,40 +123,40 @@ define(function (require) {
/**
* @return {Array.<number>}
*/
getTicksPositions: function () {
getTicksCoords: function () {
if (this.onBand) {
var bands = this.getBands();
var positions = [];
var coords = [];
for (var i = 0; i < bands.length; i++) {
positions.push(bands[i][0]);
coords.push(bands[i][0]);
}
if (bands[i - 1]) {
positions.push(bands[i - 1][1]);
coords.push(bands[i - 1][1]);
}
return positions;
return coords;
}
else {
return zrUtil.map(this.scale.getTicks(), this.mapData, this);
return zrUtil.map(this.scale.getTicks(), this.dataToCoord, this);
}
},
/**
* Positions of labels are on the ticks or on the middle of bands
* Coords of labels are on the ticks or on the middle of bands
* @return {Array.<number>}
*/
getLabelsPositions: function () {
getLabelsCoords: function () {
if (this.onBand) {
var bands = this.getBands();
var positions = [];
var coords = [];
var band;
for (var i = 0; i < bands.length; i++) {
band = bands[i];
positions.push((band[0] + band[1]) / 2);
coords.push((band[0] + band[1]) / 2);
}
return positions;
return coords;
}
else {
return zrUtil.map(this.scale.getTicks(), this.mapData, this);
return zrUtil.map(this.scale.getTicks(), this.dataToCoord, this);
}
},
......
......@@ -42,11 +42,7 @@ define(function (require) {
isHorizontal: function () {
var position = this.position;
return position === 'top' || position === 'bottom';
},
dataToCoord: Axis.prototype.mapData,
coordToData: Axis.prototype.unmapData
}
};
zrUtil.inherits(Axis2D, Axis);
......
......@@ -14,6 +14,14 @@ define(function(require) {
type: 'cartesian2d',
/**
* If contain coord
*/
containPoint: function (x, y) {
return this.getAxis('x').contain(x)
&& this.getAxis('y').contain(y);
},
/**
* Convert series data to coorindates
* @param {module:echarts/data/List} data
......@@ -25,12 +33,10 @@ define(function(require) {
var xAxis = this.getAxis('x');
var yAxis = this.getAxis('y');
var xIndex = xAxis.isHorizontal() ? 0 : 1;
return data.map(function (dataItem) {
var coord = [];
coord[xIndex] = xAxis.dataToCoord(dataItem.getX(true));
coord[1 - xIndex] = yAxis.dataToCoord(dataItem.getY(true));
coord[0] = xAxis.dataToCoord(dataItem.getX(true));
coord[1] = yAxis.dataToCoord(dataItem.getY(true));
return coord;
}, this);
},
......
......@@ -25,9 +25,9 @@ define(function(require) {
constructor: AngleAxis,
dataToAngle: Axis.prototype.mapData,
dataToAngle: Axis.prototype.dataToCoord,
angleToData: Axis.prototype.unmapData
angleToData: Axis.prototype.coordToData
};
zrUtil.inherits(AngleAxis, Axis);
......
......@@ -23,9 +23,9 @@ define(function (require) {
constructor: RadiusAxis,
dataToRadius: Axis.prototype.mapData,
dataToRadius: Axis.prototype.dataToCoord,
radiusToData: Axis.prototype.unmapData
radiusToData: Axis.prototype.coordToData
};
zrUtil.inherits(RadiusAxis, Axis);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册