Skip to content

Commit

Permalink
fix single axis, theme river, tweak label position, rotation, trigger…
Browse files Browse the repository at this point in the history
… logic.
  • Loading branch information
100pah committed Mar 19, 2017
1 parent 7ba19c3 commit 3426bd0
Show file tree
Hide file tree
Showing 32 changed files with 958 additions and 341 deletions.
49 changes: 16 additions & 33 deletions src/chart/themeRiver/ThemeRiverSeries.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,70 +223,53 @@ define(function (require) {
* Get data indices for show tooltip content
*
* @param {Array.<string>|string} dim single coordinate dimension
* @param {Array.<number>} value coordinate value
* @param {number} value axis value
* @param {module:echarts/coord/single/SingleAxis} baseAxis single Axis used
* the themeRiver.
* @return {Array.<number>}
* @return {Object} {dataIndices, nestestValue}
*/
getAxisTooltipDataIndex: function (dim, value, baseAxis) {
getAxisTooltipData: function (dim, value, baseAxis) {
if (!zrUtil.isArray(dim)) {
dim = dim ? [dim] : [];
}

var data = this.getData();

if (baseAxis.orient === 'horizontal') {
value = value[0];
}
else {
value = value[1];
}

var layerSeries = this.getLayerSeries();
var indices = [];
var layerNum = layerSeries.length;
var nestestValue;

for (var i = 0; i < layerNum; ++i) {
var minDist = Number.MAX_VALUE;
var nearestIdx = -1;
var pointNum = layerSeries[i].indices.length;
for (var j = 0; j < pointNum; ++j) {
var dist = Math.abs(data.get(dim[0], layerSeries[i].indices[j]) - value);
var theValue = data.get(dim[0], layerSeries[i].indices[j]);
var dist = Math.abs(theValue - value);
if (dist <= minDist) {
nestestValue = theValue;
minDist = dist;
nearestIdx = layerSeries[i].indices[j];
}
}
indices.push(nearestIdx);
}
return indices;

return {dataIndices: indices, nestestValue: nestestValue};
},

/**
* @override
* @param {Array.<number>} dataIndexs index of data
* @param {number} dataIndex index of data
*/
formatTooltip: function (dataIndexs) {
formatTooltip: function (dataIndex) {
var data = this.getData();
var len = dataIndexs.length;
var time = data.get('time', dataIndexs[0]);
var single = this.coordinateSystem;
var axis = single.getAxis();

if (axis.scale.type === 'time') {
time = formatUtil.formatTime('yyyy-MM-dd', time);
}

var html = encodeHTML(time) + '<br />';
for (var i = 0; i < len; ++i) {
var htmlName = data.get('name', dataIndexs[i]);
var htmlValue = data.get('value', dataIndexs[i]);
if (isNaN(htmlValue) || htmlValue == null) {
htmlValue = '-';
}
html += encodeHTML(htmlName + ' : ' + htmlValue) + '<br />';
var htmlName = data.get('name', dataIndex);
var htmlValue = data.get('value', dataIndex);
if (isNaN(htmlValue) || htmlValue == null) {
htmlValue = '-';
}
return html;
return encodeHTML(htmlName + ' : ' + htmlValue);
},

defaultOption: {
Expand Down
13 changes: 9 additions & 4 deletions src/component/axis/AxisBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ define(function (require) {
* @param {string} [opt.axisLabelShow] default get from axisModel.
* @param {string} [opt.axisName] default get from axisModel.
* @param {number} [opt.axisNameAvailableWidth]
* @param {number} [opt.labelRotation] by degree, default get from axisModel.
* @param {number} [opt.labelRotate] by degree, default get from axisModel.
* @param {number} [opt.labelInterval] Default label interval when label
* interval from model is null or 'auto'.
* @param {number} [opt.strokeContainThreshold] Default label interval when label
Expand Down Expand Up @@ -254,9 +254,9 @@ define(function (require) {
var labels = axisModel.getFormattedLabels();

// Special label rotate.
var labelRotation = retrieve(opt.labelRotation, labelModel.get('rotate')) || 0;
// To radian.
labelRotation = labelRotation * PI / 180;
var labelRotation = (
retrieve(opt.labelRotate, labelModel.get('rotate')) || 0
) * PI / 180;

var labelLayout = innerTextLayout(opt.rotation, labelRotation, opt.labelDirection);
var categoryData = axisModel.get('data');
Expand Down Expand Up @@ -497,6 +497,11 @@ define(function (require) {
* @param {number} axisRotation in radian
* @param {number} textRotation in radian
* @param {number} direction
* @return {Object} {
* rotation, // according to axis
* textAlign,
* textVerticalAlign
* }
*/
var innerTextLayout = AxisBuilder.innerTextLayout = function (axisRotation, textRotation, direction) {
var rotationDiff = remRadian(textRotation - axisRotation);
Expand Down
2 changes: 1 addition & 1 deletion src/component/axis/RadiusAxisView.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ define(function (require) {
labelDirection: -1,
tickDirection: -1,
nameDirection: 1,
labelRotation: radiusAxisModel.getModel('axisLabel').get('rotate'),
labelRotate: radiusAxisModel.getModel('axisLabel').get('rotate'),
// Over splitLine and splitArea
z2: 1
};
Expand Down
8 changes: 5 additions & 3 deletions src/component/axis/SingleAxisView.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ define(function (require) {

var selfBuilderAttr = 'splitLine';

var AxisView = require('./AxisView').extend({
var SingleAxisView = require('./AxisView').extend({

type: 'singleAxis',

axisPointerClass: SingleAxisPointer,

render: function (axisModel, ecModel) {
render: function (axisModel, ecModel, api, payload) {

var group = this.group;

Expand All @@ -37,6 +37,8 @@ define(function (require) {
if (axisModel.get(selfBuilderAttr + '.show')) {
this['_' + selfBuilderAttr](axisModel, layout.labelInterval);
}

SingleAxisView.superCall(this, 'render', axisModel, ecModel, api, payload);
},

_splitLine: function(axisModel, labelInterval) {
Expand Down Expand Up @@ -112,6 +114,6 @@ define(function (require) {
}
});

return AxisView;
return SingleAxisView;

});
20 changes: 15 additions & 5 deletions src/component/axis/cartesianAxisHelper.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
define(function (require) {

var zrUtil = require('zrender/core/util');

var helper = {};

helper.layout = function (gridModel, axisModel) {
/**
* @param {Object} opt {labelInside}
* @return {Object} {
* position, rotation, labelDirection, labelOffset,
* tickDirection, labelRotate, labelInterval, z2
* }
*/
helper.layout = function (gridModel, axisModel, opt) {
opt = opt || {};
var grid = gridModel.coordinateSystem;
var axis = axisModel.axis;
var layout = {};
Expand Down Expand Up @@ -45,16 +55,16 @@ define(function (require) {
layout.labelDirection = layout.tickDirection = layout.nameDirection = dirMap[rawAxisPosition];
layout.labelOffset = axis.onZero ? posMap[axisDim][rawAxisPosition] - posMap[axisDim].onZero : 0;

if (axisModel.getModel('axisTick').get('inside')) {
if (axisModel.get('axisTick.inside')) {
layout.tickDirection = -layout.tickDirection;
}
if (axisModel.getModel('axisLabel').get('inside')) {
if (zrUtil.retrieve(opt.labelInside, axisModel.get('axisLabel.inside'))) {
layout.labelDirection = -layout.labelDirection;
}

// Special label rotation
var labelRotation = axisModel.getModel('axisLabel').get('rotate');
layout.labelRotation = axisPosition === 'top' ? -labelRotation : labelRotation;
var labelRotate = axisModel.get('axisLabel.rotate');
layout.labelRotate = axisPosition === 'top' ? -labelRotate : labelRotate;

// label interval when auto mode.
layout.labelInterval = axis.getLabelInterval();
Expand Down
19 changes: 15 additions & 4 deletions src/component/axis/singleAxisHelper.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
define(function (require) {

var zrUtil = require('zrender/core/util');

var helper = {};

helper.layout = function (axisModel) {
/**
* @param {Object} opt {labelInside}
* @return {Object} {
* position, rotation, labelDirection, labelOffset,
* tickDirection, labelRotate, labelInterval, z2
* }
*/
helper.layout = function (axisModel, opt) {
opt = opt || {};
var single = axisModel.coordinateSystem;
var axis = axisModel.axis;
var layout = {};
Expand Down Expand Up @@ -36,15 +46,16 @@ define(function (require) {
= layout.nameDirection
= directionMap[axisPosition];

if (axisModel.getModel('axisTick').get('inside')) {
if (axisModel.get('axisTick.inside')) {
layout.tickDirection = -layout.tickDirection;
}

if (axisModel.getModel('axisLabel').get('inside')) {
if (zrUtil.retrieve(opt.labelInside, axisModel.get('axisLabel.inside'))) {
layout.labelDirection = -layout.labelDirection;
}

var labelRotation = axisModel.getModel('axisLabel').get('rotate');
var labelRotation = opt.rotate;
labelRotation == null && (labelRotation = axisModel.get('axisLabel.rotate'));
layout.labelRotation = axisPosition === 'top' ? -labelRotation : labelRotation;

layout.labelInterval = axis.getLabelInterval();
Expand Down
3 changes: 2 additions & 1 deletion src/component/axisPointer/AxisPointerModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ define(function(require) {
// 'auto' means that show when triggered by tooltip or handle.
show: 'auto',
// 'auto' | 'click' | 'mousemove' | 'handle' | 'none'
triggerOn: 'mousemove',
triggerOn: ['mousemove', 'click'],

zlevel: 0,
z: 50,
Expand Down Expand Up @@ -50,6 +50,7 @@ define(function(require) {
formatter: null, // string | Function
precision: 'auto', // Or a number like 0, 1, 2 ...
margin: 3,
rotate: 0, // in degree.
textStyle: {
color: '#fff',
fontSize: 12
Expand Down
6 changes: 0 additions & 6 deletions src/component/axisPointer/AxisPointerView.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,11 @@ define(function (require) {
type: 'axisPointer',

render: function (globalAxisPointerModel, ecModel, api) {
var tooltipModel = ecModel.getComponent('tooltip');
var showDelay = (
tooltipModel && tooltipModel.get('showDelay')
) || globalAxisPointerModel.get('showDelay') || 0;

// Register global listener in AxisPointerView to enable
// AxisPointerView to be independent to Tooltip.
globalListener.register(
'axisPointer',
api,
{delay: showDelay},
function (currTrigger, e, dispatchAction) {
dispatchAction({
type: 'updateAxisPointer',
Expand Down
17 changes: 8 additions & 9 deletions src/component/axisPointer/BaseAxisPointer.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ define(function(require) {

// Otherwise status is 'show'
var elOption = {};
this.makeElOption(elOption, value, axisModel, axisPointerModel);
this.makeElOption(elOption, value, axisModel, axisPointerModel, api);

// Enable change axis pointer type.
var graphicKey = elOption.graphicKey;
Expand Down Expand Up @@ -160,7 +160,7 @@ define(function(require) {
* add {pointer, label, graphicKey} to elOption
* @protected
*/
makeElOption: function (elOption, value, axisModel, axisPointerModel) {
makeElOption: function (elOption, value, axisModel, axisPointerModel, api) {
// Shoule be implemenented by sub-class.
},

Expand Down Expand Up @@ -196,6 +196,7 @@ define(function(require) {
var labelEl = get(group).labelEl = new graphic.Rect(
extend(clone(basicOpt), elOption.label)
);

group.add(labelEl);
updateLabelShowHide(labelEl, axisPointerModel);
},
Expand Down Expand Up @@ -244,7 +245,7 @@ define(function(require) {
* @private
*/
_renderHandle: function (value, moveAnimation, axisModel, axisPointerModel, api) {
if (this._dragging) {
if (this._dragging || !this.updateHandleTransform) {
return;
}

Expand Down Expand Up @@ -374,27 +375,25 @@ define(function(require) {
},

/**
* Should be implemenented by sub-class if support `handle`.
* @protected
* @param {number} value
* @param {module:echarts/model/Model} axisModel
* @param {module:echarts/model/Model} axisPointerModel
* @return {Object} {position: [x, y], rotation: 0}
*/
getHandleTransform: function () {
// Should be implemenented by sub-class.
},
getHandleTransform: null,

/**
* * Should be implemenented by sub-class if support `handle`.
* @protected
* @param {Object} transform {position, rotation}
* @param {Array.<number>} delta [dx, dy]
* @param {module:echarts/model/Model} axisModel
* @param {module:echarts/model/Model} axisPointerModel
* @return {Object} {position: [x, y], rotation: 0, cursorPoint: [x, y]}
*/
updateHandleTransform: function () {
// Should be implemenented by sub-class.
},
updateHandleTransform: null,

/**
* @private
Expand Down
Loading

0 comments on commit 3426bd0

Please sign in to comment.