提交 6b8f9e52 编写于 作者: L lang

Unshaped log scale

上级 5fc5500e
......@@ -103,10 +103,13 @@ define(function (require) {
}, defaultOption);
var timeAxis = zrUtil.merge({}, valueAxis);
var logAxis = zrUtil.merge({}, valueAxis);
logAxis.scale = true;
return {
categoryAxis: categoryAxis,
valueAxis: valueAxis,
timeAxis: timeAxis
timeAxis: timeAxis,
logAxis: logAxis
};
});
\ No newline at end of file
......@@ -8,6 +8,20 @@ define(function (require) {
return val;
}
// function getName(obj) {
// if (typeof obj === 'string') {
// return obj;
// }
// return obj.name;
// }
/**
* Get categories
*/
// function getCategories() {
// return this.get('type') === 'category'
// && zrUtil.map()
// }
/**
* Format labels
* @param {Array.<string>} labels
......@@ -24,10 +38,7 @@ define(function (require) {
case 'time':
labelFormatter = function (time) {
return time;
}
break;
case 'log':
// TODO
};
break;
default:
labelFormatter = function (val) {
......
/**
* Interval scale
* @module echarts/coord/scale/Interval
* @module echarts/scale/Interval
*/
define(function (require) {
......@@ -108,7 +108,7 @@ define(function (require) {
* Get interval
*/
getInterval: function () {
if (! this._interval) {
if (!this._interval) {
this.niceTicks();
}
return this._interval;
......
/**
* Log scale
* @module echarts/scale/Log
*/
define(function (require) {
var zrUtil = require('zrender/core/util');
var IntervalScale = require('./Interval');
var intervalScaleProto = IntervalScale.prototype;
var numberUtil = require('../util/number');
var mathFloor = Math.floor;
var mathCeil = Math.ceil;
var LOG_BASE = 10;
var mathLog = Math.log;
function LogScale(logBase) {
IntervalScale.call(this);
}
var logScaleProto = LogScale.prototype;
logScaleProto.type = 'log';
zrUtil.each(['contain', 'normalize'], function (methodName) {
logScaleProto[methodName] = function (val) {
val = mathLog(val) / mathLog(LOG_BASE);
return intervalScaleProto[methodName].call(this, val);
};
});
logScaleProto.getTicks = function () {
var ticks = intervalScaleProto.getTicks.call(this);
return zrUtil.map(ticks, function (tick) {
return Math.pow(LOG_BASE, tick);
});
};
/**
* @param {number} val
* @return {number}
*/
logScaleProto.scale = function (val) {
val = intervalScaleProto.scale.call(this, val);
return Math.pow(LOG_BASE, val);
};
/**
* @param {number} start
* @param {number} end
*/
logScaleProto.setExtent = function (start, end) {
start = mathLog(start) / mathLog(LOG_BASE);
end = mathLog(end) / mathLog(LOG_BASE);
intervalScaleProto.setExtent.call(this, start, end);
};
/**
* @return {number} end
*/
logScaleProto.getExtent = function () {
var extent = intervalScaleProto.getExtent.call(this);
extent[0] = Math.pow(LOG_BASE, extent[0]);
extent[1] = Math.pow(LOG_BASE, extent[1]);
return extent;
};
logScaleProto.niceTicks = function (approxTickNum) {
approxTickNum = approxTickNum || 10;
var extent = this._extent;
var span = extent[1] - extent[0];
if (span === Infinity || span <= 0) {
return;
}
var interval = Math.pow(10, Math.floor(Math.log(span / approxTickNum) / Math.LN10));
var err = approxTickNum / span * interval;
// Filter ticks to get closer to the desired count.
if (err <= 0.5) {
interval *= 10;
}
var niceExtent = [
numberUtil.round(mathCeil(extent[0] / interval) * interval),
numberUtil.round(mathFloor(extent[1] / interval) * interval)
];
this._interval = interval;
this._niceExtent = niceExtent;
};
/**
* @param {Array.<number>} extent
*/
logScaleProto.unionExtent = function (extent) {
extent[0] = mathLog(extent[0]) / mathLog(LOG_BASE);
extent[1] = mathLog(extent[1]) / mathLog(LOG_BASE);
intervalScaleProto.unionExtent.call(this, extent);
};
zrUtil.inherits(LogScale, IntervalScale);
LogScale.create = function () {
return new LogScale();
};
require('./scale').register(LogScale);
return LogScale;
});
\ No newline at end of file
......@@ -90,10 +90,10 @@ define(function (require) {
* @alias module:echarts/coord/scale/Time
* @constructor
*/
var TimeScale = function () {
function TimeScale() {
IntervalScale.call(this);
};
}
TimeScale.prototype = {
......
<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/line',
'echarts/component/legend',
'echarts/component/grid',
'echarts/component/tooltip',
'echarts/component/title',
'echarts/component/dataZoom',
'echarts/scale/Log'
], function (echarts) {
var chart = echarts.init(document.getElementById('main'));
chart.setOption({
title: {
text: '对数轴示例',
x: 'center'
},
tooltip: {
trigger: 'item',
formatter: '{a} <br/>{b} : {c}'
},
legend: {
x: 'left',
data: ['2的指数', '3的指数']
},
xAxis: [{
type: 'category',
name: 'x',
splitLine: {show: false},
data: ['', '', '', '', '', '', '', '', '']
}],
yAxis: [{
type: 'log',
name: 'y'
}],
calculable: true,
series: [
{
name: '3的指数',
type: 'line',
data: [1, 3, 9, 27, 81, 247, 741, 2223, 6669]
},
{
name: '2的指数',
type: 'line',
data: [1, 2, 4, 8, 16, 32, 64, 128, 256]
}
]
});
});
</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.
先完成此消息的编辑!
想要评论请 注册