提交 0b63ce41 编写于 作者: P pah100

dataZoom polar try ...

上级 66125488
......@@ -125,7 +125,7 @@ define(function (require) {
var width;
var height;
// If some of x/y/width/height are not specified, auto-adapt according to target grid.
var gridRect = this._findGridRectForLocating();
var gridRect = this._findCoordRectForLocating();
if (this._orient === 'horizontal') { // Horizontal layout
width = retrieveValue(dataZoomModel.get('width'), gridRect.width);
......@@ -151,7 +151,7 @@ define(function (require) {
/**
* @private
*/
_findGridRectForLocating: function () {
_findCoordRectForLocating: function () {
// Find the grid coresponding to the first axis referred by dataZoom.
var axisModel;
var dataZoomModel = this.dataZoomModel;
......@@ -163,10 +163,31 @@ define(function (require) {
axisModel = ecModel.getComponent(dimNames.axis, axisIndices[0]);
}
});
return ecModel
// FIXME
// 判断是catesian还是polar
var rect;
var gridIndex = axisModel.get('gridIndex');
if (gridIndex != null) {
rect = ecModel
.getComponent('grid', axisModel.get('gridIndex'))
.coordinateSystem
.getRect();
}
else { // Polar
// FIXME
// 暂时随便写的
var width = this.api.getWidth();
var height = this.api.getHeight();
rect = {
x: width * 0.2,
y: height * 0.2,
width: width * 0.6,
height: height * 0.6
};
}
return rect;
},
/**
......
......@@ -12,7 +12,7 @@ define(function(require) {
type: 'dataZoom',
dependencies: ['xAxis', 'yAxis', 'series'],
dependencies: ['xAxis', 'yAxis', 'zAxis', 'radiusAxis', 'angleAxis', 'series'],
/**
* @protected
......
......@@ -231,8 +231,8 @@ define(function (require) {
this.api.dispatch({
type: 'dataZoom',
from: this.uid,
dataZoomRange: this._layout.normalizeToRange(),
dataZoomModel: this.dataZoomModel
dataZoomModelId: this.dataZoomModel.uid,
dataZoomRange: this._layout.normalizeToRange()
});
}
......
......@@ -9,12 +9,18 @@ define(function(require) {
var helper = require('./helper');
echarts.registerAction('dataZoom', function (event, ecModel) {
var fromDataZoomModel = ecModel.getComponentById(event.dataZoomModelId);
if (!fromDataZoomModel) {
return;
}
var linkSet = helper.findLinkSet(
zrUtil.bind(ecModel.eachComponent, ecModel, 'dataZoom'),
function (model, dimNames) {
return model.get(dimNames.axisIndex);
},
event.dataZoomModel
fromDataZoomModel
);
var dataZoomRange = event.dataZoomRange;
......
......@@ -75,7 +75,7 @@ define(function (require) {
zrUtil.each(seriesModels, function (seriesModel) {
var seriesData = seriesModel.getData();
if (seriesData) {
var seriesExtent = seriesData['getExtent' + dimNames.dim.toUpperCase()]();
var seriesExtent = seriesData[dimNames.extentGetter]();
seriesExtent[0] < dataExtent[0] && (dataExtent[0] = seriesExtent[0]);
seriesExtent[1] > dataExtent[1] && (dataExtent[1] = seriesExtent[1]);
}
......
......@@ -7,18 +7,21 @@ define(function(require) {
var helper = {};
var AXIS_DIMS = ['x', 'y'];
var AXIS_DIMS = ['x', 'y', 'z', 'radius', 'angle'];
// FIXME
// 公用?
helper.eachAxisDim = function (callback, context) {
zrUtil.each(AXIS_DIMS, function (axisDim) {
var capital = axisDim[0].toUpperCase() + axisDim.substr(1);
var names = {
axisIndex: axisDim + 'AxisIndex',
axis: axisDim + 'Axis',
dim: axisDim,
capital: capital,
index: axisDim + 'Index',
getter: 'get' + axisDim.toUpperCase()
getter: 'get' + capital,
extentGetter: 'getExtent' + capital
};
callback.call(context, names);
});
......
......@@ -3,8 +3,8 @@ define(function(require) {
'use strict';
var axisDefault = require('../axisDefault');
var zrUtil = require('zrender/core/util');
var ComponentModel = require('../../model/Component');
function mergeDefault(axisOption, ecModel) {
var axisType = axisOption.type + 'Axis';
......@@ -14,12 +14,60 @@ define(function(require) {
zrUtil.merge(axisOption, axisDefault[axisType]);
}
var PolarAxisModel = require('../../model/Component').extend({
var PolarAxisModel = ComponentModel.extend({
type: 'polarAxis',
/**
* @type {module:echarts/coord/polar/AngleAxis|module:echarts/coord/polar/RadiusAxis}
*/
axis: null
axis: null,
/**
* @override
*/
init: function () {
ComponentModel.prototype.init.call(this);
var data = this.getData();
if (data) {
// FIXME
// clone?
/**
* @type {Array}
* @private
*/
this._dataBeforeProcessing = data.slice();
}
},
/**
* @public
* @return {Array=} data Can be null
*/
getData: function () {
return this.get('data');
},
/**
* @public
* @param {number} start 0-100, null means remain current value.
* @param {number} end 0-100, null means remain current value.
*/
setDataZoomRange: function (start, end) {
var option = this.option;
start != null && (option.dataZoomStart = start);
end != null && (option.dataZoomEnd = end);
},
/**
* @override
*/
restoreData: function () {
// FIXME
// clone?
if (this._dataBeforeProcessing) {
this.option.data = this._dataBeforeProcessing.slice();
}
}
});
zrUtil.merge(PolarAxisModel.prototype, require('../axisModelCommonMixin'));
......
<html>
<head>
<meta charset="utf-8">
<script src="esl.js"></script>
<script src="config.js"></script>
</head>
<body>
<style>
html, body, #main {
width: 100%;
height: 100%;
}
</style>
<div id="main"></div>
<script>
require([
'echarts',
'echarts/chart/scatter',
'echarts/component/legend',
'echarts/component/polar',
'echarts/component/dataZoom'
], function (echarts) {
var chart = echarts.init(document.getElementById('main'), null, {
renderer: 'canvas'
});
var data1 = [];
var data2 = [];
var data3 = [];
for (var i = 0; i < 100; i++) {
data1.push([Math.random() * 5, Math.random() * 360]);
data2.push([Math.random() * 5, Math.random() * 360]);
data3.push([Math.random() * 10, Math.random() * 360]);
}
chart.setOption({
legend: {
data: ['scatter', 'scatter2', 'scatter3']
},
polar: {
},
angleAxis: {
type: 'value'
},
radiusAxis: {
axisAngle: 0
},
dataZoom: [
{
show: true,
orient: 'vertical',
angleAxisIndex: [0]
},
{
show: true,
orient: 'horizontal',
radiusAxisIndex: [0]
}
],
series: [{
coordinateSystem: 'polar',
// FIXME
// 现在必须得设置这个,能不能polar和catesian一样,要不然很多特殊处理。
angleAxisIndex: 0,
radiusAxisIndex: 0,
name: 'scatter',
type: 'scatter',
symbolSize: 10,
data: data1
}, {
coordinateSystem: 'polar',
angleAxisIndex: 0,
radiusAxisIndex: 0,
name: 'scatter2',
type: 'scatter',
symbolSize: 10,
data: data2
}, {
coordinateSystem: 'polar',
angleAxisIndex: 0,
radiusAxisIndex: 0,
name: 'scatter3',
type: 'scatter',
symbolSize: 10,
data: data3
}]
});
})
</script>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册