first commit

This commit is contained in:
jefferyzhao
2025-07-31 17:44:12 +08:00
commit b9bdc8598b
42390 changed files with 4467935 additions and 0 deletions

View File

@ -0,0 +1,129 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var echarts = require("../../echarts");
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var AxisPointerModel = echarts.extendComponentModel({
type: 'axisPointer',
coordSysAxesInfo: null,
defaultOption: {
// 'auto' means that show when triggered by tooltip or handle.
show: 'auto',
// 'click' | 'mousemove' | 'none'
triggerOn: null,
// set default in AxisPonterView.js
zlevel: 0,
z: 50,
type: 'line',
// 'line' 'shadow' 'cross' 'none'.
// axispointer triggered by tootip determine snap automatically,
// see `modelHelper`.
snap: false,
triggerTooltip: true,
value: null,
status: null,
// Init value depends on whether handle is used.
// [group0, group1, ...]
// Each group can be: {
// mapper: function () {},
// singleTooltip: 'multiple', // 'multiple' or 'single'
// xAxisId: ...,
// yAxisName: ...,
// angleAxisIndex: ...
// }
// mapper: can be ignored.
// input: {axisInfo, value}
// output: {axisInfo, value}
link: [],
// Do not set 'auto' here, otherwise global animation: false
// will not effect at this axispointer.
animation: null,
animationDurationUpdate: 200,
lineStyle: {
color: '#aaa',
width: 1,
type: 'solid'
},
shadowStyle: {
color: 'rgba(150,150,150,0.3)'
},
label: {
show: true,
formatter: null,
// string | Function
precision: 'auto',
// Or a number like 0, 1, 2 ...
margin: 3,
color: '#fff',
padding: [5, 7, 5, 7],
backgroundColor: 'auto',
// default: axis line color
borderColor: null,
borderWidth: 0,
shadowBlur: 3,
shadowColor: '#aaa' // Considering applicability, common style should
// better not have shadowOffset.
// shadowOffsetX: 0,
// shadowOffsetY: 2
},
handle: {
show: false,
/* eslint-disable */
icon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4h1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7v-1.2h6.6z M13.3,22H6.7v-1.2h6.6z M13.3,19.6H6.7v-1.2h6.6z',
// jshint ignore:line
/* eslint-enable */
size: 45,
// handle margin is from symbol center to axis, which is stable when circular move.
margin: 50,
// color: '#1b8bbd'
// color: '#2f4554'
color: '#333',
shadowBlur: 3,
shadowColor: '#aaa',
shadowOffsetX: 0,
shadowOffsetY: 2,
// For mobile performance
throttle: 40
}
}
});
var _default = AxisPointerModel;
module.exports = _default;

View File

@ -0,0 +1,80 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var echarts = require("../../echarts");
var globalListener = require("./globalListener");
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var AxisPointerView = echarts.extendComponentView({
type: 'axisPointer',
render: function (globalAxisPointerModel, ecModel, api) {
var globalTooltipModel = ecModel.getComponent('tooltip');
var triggerOn = globalAxisPointerModel.get('triggerOn') || globalTooltipModel && globalTooltipModel.get('triggerOn') || 'mousemove|click'; // Register global listener in AxisPointerView to enable
// AxisPointerView to be independent to Tooltip.
globalListener.register('axisPointer', api, function (currTrigger, e, dispatchAction) {
// If 'none', it is not controlled by mouse totally.
if (triggerOn !== 'none' && (currTrigger === 'leave' || triggerOn.indexOf(currTrigger) >= 0)) {
dispatchAction({
type: 'updateAxisPointer',
currTrigger: currTrigger,
x: e && e.offsetX,
y: e && e.offsetY
});
}
});
},
/**
* @override
*/
remove: function (ecModel, api) {
globalListener.unregister(api.getZr(), 'axisPointer');
AxisPointerView.superApply(this._model, 'remove', arguments);
},
/**
* @override
*/
dispose: function (ecModel, api) {
globalListener.unregister('axisPointer', api);
AxisPointerView.superApply(this._model, 'dispose', arguments);
}
});
var _default = AxisPointerView;
module.exports = _default;

View File

@ -0,0 +1,527 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var zrUtil = require("zrender/lib/core/util");
var clazzUtil = require("../../util/clazz");
var graphic = require("../../util/graphic");
var axisPointerModelHelper = require("./modelHelper");
var eventTool = require("zrender/lib/core/event");
var throttleUtil = require("../../util/throttle");
var _model = require("../../util/model");
var makeInner = _model.makeInner;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var inner = makeInner();
var clone = zrUtil.clone;
var bind = zrUtil.bind;
/**
* Base axis pointer class in 2D.
* Implemenents {module:echarts/component/axis/IAxisPointer}.
*/
function BaseAxisPointer() {}
BaseAxisPointer.prototype = {
/**
* @private
*/
_group: null,
/**
* @private
*/
_lastGraphicKey: null,
/**
* @private
*/
_handle: null,
/**
* @private
*/
_dragging: false,
/**
* @private
*/
_lastValue: null,
/**
* @private
*/
_lastStatus: null,
/**
* @private
*/
_payloadInfo: null,
/**
* In px, arbitrary value. Do not set too small,
* no animation is ok for most cases.
* @protected
*/
animationThreshold: 15,
/**
* @implement
*/
render: function (axisModel, axisPointerModel, api, forceRender) {
var value = axisPointerModel.get('value');
var status = axisPointerModel.get('status'); // Bind them to `this`, not in closure, otherwise they will not
// be replaced when user calling setOption in not merge mode.
this._axisModel = axisModel;
this._axisPointerModel = axisPointerModel;
this._api = api; // Optimize: `render` will be called repeatly during mouse move.
// So it is power consuming if performing `render` each time,
// especially on mobile device.
if (!forceRender && this._lastValue === value && this._lastStatus === status) {
return;
}
this._lastValue = value;
this._lastStatus = status;
var group = this._group;
var handle = this._handle;
if (!status || status === 'hide') {
// Do not clear here, for animation better.
group && group.hide();
handle && handle.hide();
return;
}
group && group.show();
handle && handle.show(); // Otherwise status is 'show'
var elOption = {};
this.makeElOption(elOption, value, axisModel, axisPointerModel, api); // Enable change axis pointer type.
var graphicKey = elOption.graphicKey;
if (graphicKey !== this._lastGraphicKey) {
this.clear(api);
}
this._lastGraphicKey = graphicKey;
var moveAnimation = this._moveAnimation = this.determineAnimation(axisModel, axisPointerModel);
if (!group) {
group = this._group = new graphic.Group();
this.createPointerEl(group, elOption, axisModel, axisPointerModel);
this.createLabelEl(group, elOption, axisModel, axisPointerModel);
api.getZr().add(group);
} else {
var doUpdateProps = zrUtil.curry(updateProps, axisPointerModel, moveAnimation);
this.updatePointerEl(group, elOption, doUpdateProps, axisPointerModel);
this.updateLabelEl(group, elOption, doUpdateProps, axisPointerModel);
}
updateMandatoryProps(group, axisPointerModel, true);
this._renderHandle(value);
},
/**
* @implement
*/
remove: function (api) {
this.clear(api);
},
/**
* @implement
*/
dispose: function (api) {
this.clear(api);
},
/**
* @protected
*/
determineAnimation: function (axisModel, axisPointerModel) {
var animation = axisPointerModel.get('animation');
var axis = axisModel.axis;
var isCategoryAxis = axis.type === 'category';
var useSnap = axisPointerModel.get('snap'); // Value axis without snap always do not snap.
if (!useSnap && !isCategoryAxis) {
return false;
}
if (animation === 'auto' || animation == null) {
var animationThreshold = this.animationThreshold;
if (isCategoryAxis && axis.getBandWidth() > animationThreshold) {
return true;
} // It is important to auto animation when snap used. Consider if there is
// a dataZoom, animation will be disabled when too many points exist, while
// it will be enabled for better visual effect when little points exist.
if (useSnap) {
var seriesDataCount = axisPointerModelHelper.getAxisInfo(axisModel).seriesDataCount;
var axisExtent = axis.getExtent(); // Approximate band width
return Math.abs(axisExtent[0] - axisExtent[1]) / seriesDataCount > animationThreshold;
}
return false;
}
return animation === true;
},
/**
* add {pointer, label, graphicKey} to elOption
* @protected
*/
makeElOption: function (elOption, value, axisModel, axisPointerModel, api) {// Shoule be implemenented by sub-class.
},
/**
* @protected
*/
createPointerEl: function (group, elOption, axisModel, axisPointerModel) {
var pointerOption = elOption.pointer;
if (pointerOption) {
var pointerEl = inner(group).pointerEl = new graphic[pointerOption.type](clone(elOption.pointer));
group.add(pointerEl);
}
},
/**
* @protected
*/
createLabelEl: function (group, elOption, axisModel, axisPointerModel) {
if (elOption.label) {
var labelEl = inner(group).labelEl = new graphic.Rect(clone(elOption.label));
group.add(labelEl);
updateLabelShowHide(labelEl, axisPointerModel);
}
},
/**
* @protected
*/
updatePointerEl: function (group, elOption, updateProps) {
var pointerEl = inner(group).pointerEl;
if (pointerEl && elOption.pointer) {
pointerEl.setStyle(elOption.pointer.style);
updateProps(pointerEl, {
shape: elOption.pointer.shape
});
}
},
/**
* @protected
*/
updateLabelEl: function (group, elOption, updateProps, axisPointerModel) {
var labelEl = inner(group).labelEl;
if (labelEl) {
labelEl.setStyle(elOption.label.style);
updateProps(labelEl, {
// Consider text length change in vertical axis, animation should
// be used on shape, otherwise the effect will be weird.
shape: elOption.label.shape,
position: elOption.label.position
});
updateLabelShowHide(labelEl, axisPointerModel);
}
},
/**
* @private
*/
_renderHandle: function (value) {
if (this._dragging || !this.updateHandleTransform) {
return;
}
var axisPointerModel = this._axisPointerModel;
var zr = this._api.getZr();
var handle = this._handle;
var handleModel = axisPointerModel.getModel('handle');
var status = axisPointerModel.get('status');
if (!handleModel.get('show') || !status || status === 'hide') {
handle && zr.remove(handle);
this._handle = null;
return;
}
var isInit;
if (!this._handle) {
isInit = true;
handle = this._handle = graphic.createIcon(handleModel.get('icon'), {
cursor: 'move',
draggable: true,
onmousemove: function (e) {
// Fot mobile devicem, prevent screen slider on the button.
eventTool.stop(e.event);
},
onmousedown: bind(this._onHandleDragMove, this, 0, 0),
drift: bind(this._onHandleDragMove, this),
ondragend: bind(this._onHandleDragEnd, this)
});
zr.add(handle);
}
updateMandatoryProps(handle, axisPointerModel, false); // update style
var includeStyles = ['color', 'borderColor', 'borderWidth', 'opacity', 'shadowColor', 'shadowBlur', 'shadowOffsetX', 'shadowOffsetY'];
handle.setStyle(handleModel.getItemStyle(null, includeStyles)); // update position
var handleSize = handleModel.get('size');
if (!zrUtil.isArray(handleSize)) {
handleSize = [handleSize, handleSize];
}
handle.attr('scale', [handleSize[0] / 2, handleSize[1] / 2]);
throttleUtil.createOrUpdate(this, '_doDispatchAxisPointer', handleModel.get('throttle') || 0, 'fixRate');
this._moveHandleToValue(value, isInit);
},
/**
* @private
*/
_moveHandleToValue: function (value, isInit) {
updateProps(this._axisPointerModel, !isInit && this._moveAnimation, this._handle, getHandleTransProps(this.getHandleTransform(value, this._axisModel, this._axisPointerModel)));
},
/**
* @private
*/
_onHandleDragMove: function (dx, dy) {
var handle = this._handle;
if (!handle) {
return;
}
this._dragging = true; // Persistent for throttle.
var trans = this.updateHandleTransform(getHandleTransProps(handle), [dx, dy], this._axisModel, this._axisPointerModel);
this._payloadInfo = trans;
handle.stopAnimation();
handle.attr(getHandleTransProps(trans));
inner(handle).lastProp = null;
this._doDispatchAxisPointer();
},
/**
* Throttled method.
* @private
*/
_doDispatchAxisPointer: function () {
var handle = this._handle;
if (!handle) {
return;
}
var payloadInfo = this._payloadInfo;
var axisModel = this._axisModel;
this._api.dispatchAction({
type: 'updateAxisPointer',
x: payloadInfo.cursorPoint[0],
y: payloadInfo.cursorPoint[1],
tooltipOption: payloadInfo.tooltipOption,
axesInfo: [{
axisDim: axisModel.axis.dim,
axisIndex: axisModel.componentIndex
}]
});
},
/**
* @private
*/
_onHandleDragEnd: function (moveAnimation) {
this._dragging = false;
var handle = this._handle;
if (!handle) {
return;
}
var value = this._axisPointerModel.get('value'); // Consider snap or categroy axis, handle may be not consistent with
// axisPointer. So move handle to align the exact value position when
// drag ended.
this._moveHandleToValue(value); // For the effect: tooltip will be shown when finger holding on handle
// button, and will be hidden after finger left handle button.
this._api.dispatchAction({
type: 'hideTip'
});
},
/**
* 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: 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: null,
/**
* @private
*/
clear: function (api) {
this._lastValue = null;
this._lastStatus = null;
var zr = api.getZr();
var group = this._group;
var handle = this._handle;
if (zr && group) {
this._lastGraphicKey = null;
group && zr.remove(group);
handle && zr.remove(handle);
this._group = null;
this._handle = null;
this._payloadInfo = null;
}
},
/**
* @protected
*/
doClear: function () {// Implemented by sub-class if necessary.
},
/**
* @protected
* @param {Array.<number>} xy
* @param {Array.<number>} wh
* @param {number} [xDimIndex=0] or 1
*/
buildLabel: function (xy, wh, xDimIndex) {
xDimIndex = xDimIndex || 0;
return {
x: xy[xDimIndex],
y: xy[1 - xDimIndex],
width: wh[xDimIndex],
height: wh[1 - xDimIndex]
};
}
};
BaseAxisPointer.prototype.constructor = BaseAxisPointer;
function updateProps(animationModel, moveAnimation, el, props) {
// Animation optimize.
if (!propsEqual(inner(el).lastProp, props)) {
inner(el).lastProp = props;
moveAnimation ? graphic.updateProps(el, props, animationModel) : (el.stopAnimation(), el.attr(props));
}
}
function propsEqual(lastProps, newProps) {
if (zrUtil.isObject(lastProps) && zrUtil.isObject(newProps)) {
var equals = true;
zrUtil.each(newProps, function (item, key) {
equals = equals && propsEqual(lastProps[key], item);
});
return !!equals;
} else {
return lastProps === newProps;
}
}
function updateLabelShowHide(labelEl, axisPointerModel) {
labelEl[axisPointerModel.get('label.show') ? 'show' : 'hide']();
}
function getHandleTransProps(trans) {
return {
position: trans.position.slice(),
rotation: trans.rotation || 0
};
}
function updateMandatoryProps(group, axisPointerModel, silent) {
var z = axisPointerModel.get('z');
var zlevel = axisPointerModel.get('zlevel');
group && group.traverse(function (el) {
if (el.type !== 'group') {
z != null && (el.z = z);
zlevel != null && (el.zlevel = zlevel);
el.silent = silent;
}
});
}
clazzUtil.enableClassExtend(BaseAxisPointer);
var _default = BaseAxisPointer;
module.exports = _default;

View File

@ -0,0 +1,146 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var BaseAxisPointer = require("./BaseAxisPointer");
var viewHelper = require("./viewHelper");
var cartesianAxisHelper = require("../../coord/cartesian/cartesianAxisHelper");
var AxisView = require("../axis/AxisView");
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var CartesianAxisPointer = BaseAxisPointer.extend({
/**
* @override
*/
makeElOption: function (elOption, value, axisModel, axisPointerModel, api) {
var axis = axisModel.axis;
var grid = axis.grid;
var axisPointerType = axisPointerModel.get('type');
var otherExtent = getCartesian(grid, axis).getOtherAxis(axis).getGlobalExtent();
var pixelValue = axis.toGlobalCoord(axis.dataToCoord(value, true));
if (axisPointerType && axisPointerType !== 'none') {
var elStyle = viewHelper.buildElStyle(axisPointerModel);
var pointerOption = pointerShapeBuilder[axisPointerType](axis, pixelValue, otherExtent);
pointerOption.style = elStyle;
elOption.graphicKey = pointerOption.type;
elOption.pointer = pointerOption;
}
var layoutInfo = cartesianAxisHelper.layout(grid.model, axisModel);
viewHelper.buildCartesianSingleLabelElOption(value, elOption, layoutInfo, axisModel, axisPointerModel, api);
},
/**
* @override
*/
getHandleTransform: function (value, axisModel, axisPointerModel) {
var layoutInfo = cartesianAxisHelper.layout(axisModel.axis.grid.model, axisModel, {
labelInside: false
});
layoutInfo.labelMargin = axisPointerModel.get('handle.margin');
return {
position: viewHelper.getTransformedPosition(axisModel.axis, value, layoutInfo),
rotation: layoutInfo.rotation + (layoutInfo.labelDirection < 0 ? Math.PI : 0)
};
},
/**
* @override
*/
updateHandleTransform: function (transform, delta, axisModel, axisPointerModel) {
var axis = axisModel.axis;
var grid = axis.grid;
var axisExtent = axis.getGlobalExtent(true);
var otherExtent = getCartesian(grid, axis).getOtherAxis(axis).getGlobalExtent();
var dimIndex = axis.dim === 'x' ? 0 : 1;
var currPosition = transform.position;
currPosition[dimIndex] += delta[dimIndex];
currPosition[dimIndex] = Math.min(axisExtent[1], currPosition[dimIndex]);
currPosition[dimIndex] = Math.max(axisExtent[0], currPosition[dimIndex]);
var cursorOtherValue = (otherExtent[1] + otherExtent[0]) / 2;
var cursorPoint = [cursorOtherValue, cursorOtherValue];
cursorPoint[dimIndex] = currPosition[dimIndex]; // Make tooltip do not overlap axisPointer and in the middle of the grid.
var tooltipOptions = [{
verticalAlign: 'middle'
}, {
align: 'center'
}];
return {
position: currPosition,
rotation: transform.rotation,
cursorPoint: cursorPoint,
tooltipOption: tooltipOptions[dimIndex]
};
}
});
function getCartesian(grid, axis) {
var opt = {};
opt[axis.dim + 'AxisIndex'] = axis.index;
return grid.getCartesian(opt);
}
var pointerShapeBuilder = {
line: function (axis, pixelValue, otherExtent) {
var targetShape = viewHelper.makeLineShape([pixelValue, otherExtent[0]], [pixelValue, otherExtent[1]], getAxisDimIndex(axis));
return {
type: 'Line',
subPixelOptimize: true,
shape: targetShape
};
},
shadow: function (axis, pixelValue, otherExtent) {
var bandWidth = Math.max(1, axis.getBandWidth());
var span = otherExtent[1] - otherExtent[0];
return {
type: 'Rect',
shape: viewHelper.makeRectShape([pixelValue - bandWidth / 2, otherExtent[0]], [bandWidth, span], getAxisDimIndex(axis))
};
}
};
function getAxisDimIndex(axis) {
return axis.dim === 'x' ? 0 : 1;
}
AxisView.registerAxisPointerClass('CartesianAxisPointer', CartesianAxisPointer);
var _default = CartesianAxisPointer;
module.exports = _default;

View File

@ -0,0 +1,151 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var formatUtil = require("../../util/format");
var BaseAxisPointer = require("./BaseAxisPointer");
var graphic = require("../../util/graphic");
var viewHelper = require("./viewHelper");
var matrix = require("zrender/lib/core/matrix");
var AxisBuilder = require("../axis/AxisBuilder");
var AxisView = require("../axis/AxisView");
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var PolarAxisPointer = BaseAxisPointer.extend({
/**
* @override
*/
makeElOption: function (elOption, value, axisModel, axisPointerModel, api) {
var axis = axisModel.axis;
if (axis.dim === 'angle') {
this.animationThreshold = Math.PI / 18;
}
var polar = axis.polar;
var otherAxis = polar.getOtherAxis(axis);
var otherExtent = otherAxis.getExtent();
var coordValue;
coordValue = axis['dataTo' + formatUtil.capitalFirst(axis.dim)](value);
var axisPointerType = axisPointerModel.get('type');
if (axisPointerType && axisPointerType !== 'none') {
var elStyle = viewHelper.buildElStyle(axisPointerModel);
var pointerOption = pointerShapeBuilder[axisPointerType](axis, polar, coordValue, otherExtent, elStyle);
pointerOption.style = elStyle;
elOption.graphicKey = pointerOption.type;
elOption.pointer = pointerOption;
}
var labelMargin = axisPointerModel.get('label.margin');
var labelPos = getLabelPosition(value, axisModel, axisPointerModel, polar, labelMargin);
viewHelper.buildLabelElOption(elOption, axisModel, axisPointerModel, api, labelPos);
} // Do not support handle, utill any user requires it.
});
function getLabelPosition(value, axisModel, axisPointerModel, polar, labelMargin) {
var axis = axisModel.axis;
var coord = axis.dataToCoord(value);
var axisAngle = polar.getAngleAxis().getExtent()[0];
axisAngle = axisAngle / 180 * Math.PI;
var radiusExtent = polar.getRadiusAxis().getExtent();
var position;
var align;
var verticalAlign;
if (axis.dim === 'radius') {
var transform = matrix.create();
matrix.rotate(transform, transform, axisAngle);
matrix.translate(transform, transform, [polar.cx, polar.cy]);
position = graphic.applyTransform([coord, -labelMargin], transform);
var labelRotation = axisModel.getModel('axisLabel').get('rotate') || 0;
var labelLayout = AxisBuilder.innerTextLayout(axisAngle, labelRotation * Math.PI / 180, -1);
align = labelLayout.textAlign;
verticalAlign = labelLayout.textVerticalAlign;
} else {
// angle axis
var r = radiusExtent[1];
position = polar.coordToPoint([r + labelMargin, coord]);
var cx = polar.cx;
var cy = polar.cy;
align = Math.abs(position[0] - cx) / r < 0.3 ? 'center' : position[0] > cx ? 'left' : 'right';
verticalAlign = Math.abs(position[1] - cy) / r < 0.3 ? 'middle' : position[1] > cy ? 'top' : 'bottom';
}
return {
position: position,
align: align,
verticalAlign: verticalAlign
};
}
var pointerShapeBuilder = {
line: function (axis, polar, coordValue, otherExtent, elStyle) {
return axis.dim === 'angle' ? {
type: 'Line',
shape: viewHelper.makeLineShape(polar.coordToPoint([otherExtent[0], coordValue]), polar.coordToPoint([otherExtent[1], coordValue]))
} : {
type: 'Circle',
shape: {
cx: polar.cx,
cy: polar.cy,
r: coordValue
}
};
},
shadow: function (axis, polar, coordValue, otherExtent, elStyle) {
var bandWidth = Math.max(1, axis.getBandWidth());
var radian = Math.PI / 180;
return axis.dim === 'angle' ? {
type: 'Sector',
shape: viewHelper.makeSectorShape(polar.cx, polar.cy, otherExtent[0], otherExtent[1], // In ECharts y is negative if angle is positive
(-coordValue - bandWidth / 2) * radian, (-coordValue + bandWidth / 2) * radian)
} : {
type: 'Sector',
shape: viewHelper.makeSectorShape(polar.cx, polar.cy, coordValue - bandWidth / 2, coordValue + bandWidth / 2, 0, Math.PI * 2)
};
}
};
AxisView.registerAxisPointerClass('PolarAxisPointer', PolarAxisPointer);
var _default = PolarAxisPointer;
module.exports = _default;

View File

@ -0,0 +1,142 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var BaseAxisPointer = require("./BaseAxisPointer");
var viewHelper = require("./viewHelper");
var singleAxisHelper = require("../../coord/single/singleAxisHelper");
var AxisView = require("../axis/AxisView");
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var XY = ['x', 'y'];
var WH = ['width', 'height'];
var SingleAxisPointer = BaseAxisPointer.extend({
/**
* @override
*/
makeElOption: function (elOption, value, axisModel, axisPointerModel, api) {
var axis = axisModel.axis;
var coordSys = axis.coordinateSystem;
var otherExtent = getGlobalExtent(coordSys, 1 - getPointDimIndex(axis));
var pixelValue = coordSys.dataToPoint(value)[0];
var axisPointerType = axisPointerModel.get('type');
if (axisPointerType && axisPointerType !== 'none') {
var elStyle = viewHelper.buildElStyle(axisPointerModel);
var pointerOption = pointerShapeBuilder[axisPointerType](axis, pixelValue, otherExtent);
pointerOption.style = elStyle;
elOption.graphicKey = pointerOption.type;
elOption.pointer = pointerOption;
}
var layoutInfo = singleAxisHelper.layout(axisModel);
viewHelper.buildCartesianSingleLabelElOption(value, elOption, layoutInfo, axisModel, axisPointerModel, api);
},
/**
* @override
*/
getHandleTransform: function (value, axisModel, axisPointerModel) {
var layoutInfo = singleAxisHelper.layout(axisModel, {
labelInside: false
});
layoutInfo.labelMargin = axisPointerModel.get('handle.margin');
return {
position: viewHelper.getTransformedPosition(axisModel.axis, value, layoutInfo),
rotation: layoutInfo.rotation + (layoutInfo.labelDirection < 0 ? Math.PI : 0)
};
},
/**
* @override
*/
updateHandleTransform: function (transform, delta, axisModel, axisPointerModel) {
var axis = axisModel.axis;
var coordSys = axis.coordinateSystem;
var dimIndex = getPointDimIndex(axis);
var axisExtent = getGlobalExtent(coordSys, dimIndex);
var currPosition = transform.position;
currPosition[dimIndex] += delta[dimIndex];
currPosition[dimIndex] = Math.min(axisExtent[1], currPosition[dimIndex]);
currPosition[dimIndex] = Math.max(axisExtent[0], currPosition[dimIndex]);
var otherExtent = getGlobalExtent(coordSys, 1 - dimIndex);
var cursorOtherValue = (otherExtent[1] + otherExtent[0]) / 2;
var cursorPoint = [cursorOtherValue, cursorOtherValue];
cursorPoint[dimIndex] = currPosition[dimIndex];
return {
position: currPosition,
rotation: transform.rotation,
cursorPoint: cursorPoint,
tooltipOption: {
verticalAlign: 'middle'
}
};
}
});
var pointerShapeBuilder = {
line: function (axis, pixelValue, otherExtent) {
var targetShape = viewHelper.makeLineShape([pixelValue, otherExtent[0]], [pixelValue, otherExtent[1]], getPointDimIndex(axis));
return {
type: 'Line',
subPixelOptimize: true,
shape: targetShape
};
},
shadow: function (axis, pixelValue, otherExtent) {
var bandWidth = axis.getBandWidth();
var span = otherExtent[1] - otherExtent[0];
return {
type: 'Rect',
shape: viewHelper.makeRectShape([pixelValue - bandWidth / 2, otherExtent[0]], [bandWidth, span], getPointDimIndex(axis))
};
}
};
function getPointDimIndex(axis) {
return axis.isHorizontal() ? 0 : 1;
}
function getGlobalExtent(coordSys, dimIndex) {
var rect = coordSys.getRect();
return [rect[XY[dimIndex]], rect[XY[dimIndex]] + rect[WH[dimIndex]]];
}
AxisView.registerAxisPointerClass('SingleAxisPointer', SingleAxisPointer);
var _default = SingleAxisPointer;
module.exports = _default;

View File

@ -0,0 +1,431 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var zrUtil = require("zrender/lib/core/util");
var _model = require("../../util/model");
var makeInner = _model.makeInner;
var modelHelper = require("./modelHelper");
var findPointFromSeries = require("./findPointFromSeries");
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var each = zrUtil.each;
var curry = zrUtil.curry;
var inner = makeInner();
/**
* Basic logic: check all axis, if they do not demand show/highlight,
* then hide/downplay them.
*
* @param {Object} coordSysAxesInfo
* @param {Object} payload
* @param {string} [payload.currTrigger] 'click' | 'mousemove' | 'leave'
* @param {Array.<number>} [payload.x] x and y, which are mandatory, specify a point to
* trigger axisPointer and tooltip.
* @param {Array.<number>} [payload.y] x and y, which are mandatory, specify a point to
* trigger axisPointer and tooltip.
* @param {Object} [payload.seriesIndex] finder, optional, restrict target axes.
* @param {Object} [payload.dataIndex] finder, restrict target axes.
* @param {Object} [payload.axesInfo] finder, restrict target axes.
* [{
* axisDim: 'x'|'y'|'angle'|...,
* axisIndex: ...,
* value: ...
* }, ...]
* @param {Function} [payload.dispatchAction]
* @param {Object} [payload.tooltipOption]
* @param {Object|Array.<number>|Function} [payload.position] Tooltip position,
* which can be specified in dispatchAction
* @param {module:echarts/model/Global} ecModel
* @param {module:echarts/ExtensionAPI} api
* @return {Object} content of event obj for echarts.connect.
*/
function _default(payload, ecModel, api) {
var currTrigger = payload.currTrigger;
var point = [payload.x, payload.y];
var finder = payload;
var dispatchAction = payload.dispatchAction || zrUtil.bind(api.dispatchAction, api);
var coordSysAxesInfo = ecModel.getComponent('axisPointer').coordSysAxesInfo; // Pending
// See #6121. But we are not able to reproduce it yet.
if (!coordSysAxesInfo) {
return;
}
if (illegalPoint(point)) {
// Used in the default behavior of `connection`: use the sample seriesIndex
// and dataIndex. And also used in the tooltipView trigger.
point = findPointFromSeries({
seriesIndex: finder.seriesIndex,
// Do not use dataIndexInside from other ec instance.
// FIXME: auto detect it?
dataIndex: finder.dataIndex
}, ecModel).point;
}
var isIllegalPoint = illegalPoint(point); // Axis and value can be specified when calling dispatchAction({type: 'updateAxisPointer'}).
// Notice: In this case, it is difficult to get the `point` (which is necessary to show
// tooltip, so if point is not given, we just use the point found by sample seriesIndex
// and dataIndex.
var inputAxesInfo = finder.axesInfo;
var axesInfo = coordSysAxesInfo.axesInfo;
var shouldHide = currTrigger === 'leave' || illegalPoint(point);
var outputFinder = {};
var showValueMap = {};
var dataByCoordSys = {
list: [],
map: {}
};
var updaters = {
showPointer: curry(showPointer, showValueMap),
showTooltip: curry(showTooltip, dataByCoordSys)
}; // Process for triggered axes.
each(coordSysAxesInfo.coordSysMap, function (coordSys, coordSysKey) {
// If a point given, it must be contained by the coordinate system.
var coordSysContainsPoint = isIllegalPoint || coordSys.containPoint(point);
each(coordSysAxesInfo.coordSysAxesInfo[coordSysKey], function (axisInfo, key) {
var axis = axisInfo.axis;
var inputAxisInfo = findInputAxisInfo(inputAxesInfo, axisInfo); // If no inputAxesInfo, no axis is restricted.
if (!shouldHide && coordSysContainsPoint && (!inputAxesInfo || inputAxisInfo)) {
var val = inputAxisInfo && inputAxisInfo.value;
if (val == null && !isIllegalPoint) {
val = axis.pointToData(point);
}
val != null && processOnAxis(axisInfo, val, updaters, false, outputFinder);
}
});
}); // Process for linked axes.
var linkTriggers = {};
each(axesInfo, function (tarAxisInfo, tarKey) {
var linkGroup = tarAxisInfo.linkGroup; // If axis has been triggered in the previous stage, it should not be triggered by link.
if (linkGroup && !showValueMap[tarKey]) {
each(linkGroup.axesInfo, function (srcAxisInfo, srcKey) {
var srcValItem = showValueMap[srcKey]; // If srcValItem exist, source axis is triggered, so link to target axis.
if (srcAxisInfo !== tarAxisInfo && srcValItem) {
var val = srcValItem.value;
linkGroup.mapper && (val = tarAxisInfo.axis.scale.parse(linkGroup.mapper(val, makeMapperParam(srcAxisInfo), makeMapperParam(tarAxisInfo))));
linkTriggers[tarAxisInfo.key] = val;
}
});
}
});
each(linkTriggers, function (val, tarKey) {
processOnAxis(axesInfo[tarKey], val, updaters, true, outputFinder);
});
updateModelActually(showValueMap, axesInfo, outputFinder);
dispatchTooltipActually(dataByCoordSys, point, payload, dispatchAction);
dispatchHighDownActually(axesInfo, dispatchAction, api);
return outputFinder;
}
function processOnAxis(axisInfo, newValue, updaters, dontSnap, outputFinder) {
var axis = axisInfo.axis;
if (axis.scale.isBlank() || !axis.containData(newValue)) {
return;
}
if (!axisInfo.involveSeries) {
updaters.showPointer(axisInfo, newValue);
return;
} // Heavy calculation. So put it after axis.containData checking.
var payloadInfo = buildPayloadsBySeries(newValue, axisInfo);
var payloadBatch = payloadInfo.payloadBatch;
var snapToValue = payloadInfo.snapToValue; // Fill content of event obj for echarts.connect.
// By default use the first involved series data as a sample to connect.
if (payloadBatch[0] && outputFinder.seriesIndex == null) {
zrUtil.extend(outputFinder, payloadBatch[0]);
} // If no linkSource input, this process is for collecting link
// target, where snap should not be accepted.
if (!dontSnap && axisInfo.snap) {
if (axis.containData(snapToValue) && snapToValue != null) {
newValue = snapToValue;
}
}
updaters.showPointer(axisInfo, newValue, payloadBatch, outputFinder); // Tooltip should always be snapToValue, otherwise there will be
// incorrect "axis value ~ series value" mapping displayed in tooltip.
updaters.showTooltip(axisInfo, payloadInfo, snapToValue);
}
function buildPayloadsBySeries(value, axisInfo) {
var axis = axisInfo.axis;
var dim = axis.dim;
var snapToValue = value;
var payloadBatch = [];
var minDist = Number.MAX_VALUE;
var minDiff = -1;
each(axisInfo.seriesModels, function (series, idx) {
var dataDim = series.getData().mapDimension(dim, true);
var seriesNestestValue;
var dataIndices;
if (series.getAxisTooltipData) {
var result = series.getAxisTooltipData(dataDim, value, axis);
dataIndices = result.dataIndices;
seriesNestestValue = result.nestestValue;
} else {
dataIndices = series.getData().indicesOfNearest(dataDim[0], value, // Add a threshold to avoid find the wrong dataIndex
// when data length is not same.
// false,
axis.type === 'category' ? 0.5 : null);
if (!dataIndices.length) {
return;
}
seriesNestestValue = series.getData().get(dataDim[0], dataIndices[0]);
}
if (seriesNestestValue == null || !isFinite(seriesNestestValue)) {
return;
}
var diff = value - seriesNestestValue;
var dist = Math.abs(diff); // Consider category case
if (dist <= minDist) {
if (dist < minDist || diff >= 0 && minDiff < 0) {
minDist = dist;
minDiff = diff;
snapToValue = seriesNestestValue;
payloadBatch.length = 0;
}
each(dataIndices, function (dataIndex) {
payloadBatch.push({
seriesIndex: series.seriesIndex,
dataIndexInside: dataIndex,
dataIndex: series.getData().getRawIndex(dataIndex)
});
});
}
});
return {
payloadBatch: payloadBatch,
snapToValue: snapToValue
};
}
function showPointer(showValueMap, axisInfo, value, payloadBatch) {
showValueMap[axisInfo.key] = {
value: value,
payloadBatch: payloadBatch
};
}
function showTooltip(dataByCoordSys, axisInfo, payloadInfo, value) {
var payloadBatch = payloadInfo.payloadBatch;
var axis = axisInfo.axis;
var axisModel = axis.model;
var axisPointerModel = axisInfo.axisPointerModel; // If no data, do not create anything in dataByCoordSys,
// whose length will be used to judge whether dispatch action.
if (!axisInfo.triggerTooltip || !payloadBatch.length) {
return;
}
var coordSysModel = axisInfo.coordSys.model;
var coordSysKey = modelHelper.makeKey(coordSysModel);
var coordSysItem = dataByCoordSys.map[coordSysKey];
if (!coordSysItem) {
coordSysItem = dataByCoordSys.map[coordSysKey] = {
coordSysId: coordSysModel.id,
coordSysIndex: coordSysModel.componentIndex,
coordSysType: coordSysModel.type,
coordSysMainType: coordSysModel.mainType,
dataByAxis: []
};
dataByCoordSys.list.push(coordSysItem);
}
coordSysItem.dataByAxis.push({
axisDim: axis.dim,
axisIndex: axisModel.componentIndex,
axisType: axisModel.type,
axisId: axisModel.id,
value: value,
// Caustion: viewHelper.getValueLabel is actually on "view stage", which
// depends that all models have been updated. So it should not be performed
// here. Considering axisPointerModel used here is volatile, which is hard
// to be retrieve in TooltipView, we prepare parameters here.
valueLabelOpt: {
precision: axisPointerModel.get('label.precision'),
formatter: axisPointerModel.get('label.formatter')
},
seriesDataIndices: payloadBatch.slice()
});
}
function updateModelActually(showValueMap, axesInfo, outputFinder) {
var outputAxesInfo = outputFinder.axesInfo = []; // Basic logic: If no 'show' required, 'hide' this axisPointer.
each(axesInfo, function (axisInfo, key) {
var option = axisInfo.axisPointerModel.option;
var valItem = showValueMap[key];
if (valItem) {
!axisInfo.useHandle && (option.status = 'show');
option.value = valItem.value; // For label formatter param and highlight.
option.seriesDataIndices = (valItem.payloadBatch || []).slice();
} // When always show (e.g., handle used), remain
// original value and status.
else {
// If hide, value still need to be set, consider
// click legend to toggle axis blank.
!axisInfo.useHandle && (option.status = 'hide');
} // If status is 'hide', should be no info in payload.
option.status === 'show' && outputAxesInfo.push({
axisDim: axisInfo.axis.dim,
axisIndex: axisInfo.axis.model.componentIndex,
value: option.value
});
});
}
function dispatchTooltipActually(dataByCoordSys, point, payload, dispatchAction) {
// Basic logic: If no showTip required, hideTip will be dispatched.
if (illegalPoint(point) || !dataByCoordSys.list.length) {
dispatchAction({
type: 'hideTip'
});
return;
} // In most case only one axis (or event one series is used). It is
// convinient to fetch payload.seriesIndex and payload.dataIndex
// dirtectly. So put the first seriesIndex and dataIndex of the first
// axis on the payload.
var sampleItem = ((dataByCoordSys.list[0].dataByAxis[0] || {}).seriesDataIndices || [])[0] || {};
dispatchAction({
type: 'showTip',
escapeConnect: true,
x: point[0],
y: point[1],
tooltipOption: payload.tooltipOption,
position: payload.position,
dataIndexInside: sampleItem.dataIndexInside,
dataIndex: sampleItem.dataIndex,
seriesIndex: sampleItem.seriesIndex,
dataByCoordSys: dataByCoordSys.list
});
}
function dispatchHighDownActually(axesInfo, dispatchAction, api) {
// FIXME
// highlight status modification shoule be a stage of main process?
// (Consider confilct (e.g., legend and axisPointer) and setOption)
var zr = api.getZr();
var highDownKey = 'axisPointerLastHighlights';
var lastHighlights = inner(zr)[highDownKey] || {};
var newHighlights = inner(zr)[highDownKey] = {}; // Update highlight/downplay status according to axisPointer model.
// Build hash map and remove duplicate incidentally.
each(axesInfo, function (axisInfo, key) {
var option = axisInfo.axisPointerModel.option;
option.status === 'show' && each(option.seriesDataIndices, function (batchItem) {
var key = batchItem.seriesIndex + ' | ' + batchItem.dataIndex;
newHighlights[key] = batchItem;
});
}); // Diff.
var toHighlight = [];
var toDownplay = [];
zrUtil.each(lastHighlights, function (batchItem, key) {
!newHighlights[key] && toDownplay.push(batchItem);
});
zrUtil.each(newHighlights, function (batchItem, key) {
!lastHighlights[key] && toHighlight.push(batchItem);
});
toDownplay.length && api.dispatchAction({
type: 'downplay',
escapeConnect: true,
batch: toDownplay
});
toHighlight.length && api.dispatchAction({
type: 'highlight',
escapeConnect: true,
batch: toHighlight
});
}
function findInputAxisInfo(inputAxesInfo, axisInfo) {
for (var i = 0; i < (inputAxesInfo || []).length; i++) {
var inputAxisInfo = inputAxesInfo[i];
if (axisInfo.axis.dim === inputAxisInfo.axisDim && axisInfo.axis.model.componentIndex === inputAxisInfo.axisIndex) {
return inputAxisInfo;
}
}
}
function makeMapperParam(axisInfo) {
var axisModel = axisInfo.axis.model;
var item = {};
var dim = item.axisDim = axisInfo.axis.dim;
item.axisIndex = item[dim + 'AxisIndex'] = axisModel.componentIndex;
item.axisName = item[dim + 'AxisName'] = axisModel.name;
item.axisId = item[dim + 'AxisId'] = axisModel.id;
return item;
}
function illegalPoint(point) {
return !point || point[0] == null || isNaN(point[0]) || point[1] == null || isNaN(point[1]);
}
module.exports = _default;

View File

@ -0,0 +1,91 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var zrUtil = require("zrender/lib/core/util");
var modelUtil = require("../../util/model");
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* @param {Object} finder contains {seriesIndex, dataIndex, dataIndexInside}
* @param {module:echarts/model/Global} ecModel
* @return {Object} {point: [x, y], el: ...} point Will not be null.
*/
function _default(finder, ecModel) {
var point = [];
var seriesIndex = finder.seriesIndex;
var seriesModel;
if (seriesIndex == null || !(seriesModel = ecModel.getSeriesByIndex(seriesIndex))) {
return {
point: []
};
}
var data = seriesModel.getData();
var dataIndex = modelUtil.queryDataIndex(data, finder);
if (dataIndex == null || dataIndex < 0 || zrUtil.isArray(dataIndex)) {
return {
point: []
};
}
var el = data.getItemGraphicEl(dataIndex);
var coordSys = seriesModel.coordinateSystem;
if (seriesModel.getTooltipPosition) {
point = seriesModel.getTooltipPosition(dataIndex) || [];
} else if (coordSys && coordSys.dataToPoint) {
point = coordSys.dataToPoint(data.getValues(zrUtil.map(coordSys.dimensions, function (dim) {
return data.mapDimension(dim);
}), dataIndex, true)) || [];
} else if (el) {
// Use graphic bounding rect
var rect = el.getBoundingRect().clone();
rect.applyTransform(el.transform);
point = [rect.x + rect.width / 2, rect.y + rect.height / 2];
}
return {
point: point,
el: el
};
}
module.exports = _default;

View File

@ -0,0 +1,162 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var zrUtil = require("zrender/lib/core/util");
var env = require("zrender/lib/core/env");
var _model = require("../../util/model");
var makeInner = _model.makeInner;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var inner = makeInner();
var each = zrUtil.each;
/**
* @param {string} key
* @param {module:echarts/ExtensionAPI} api
* @param {Function} handler
* param: {string} currTrigger
* param: {Array.<number>} point
*/
function register(key, api, handler) {
if (env.node) {
return;
}
var zr = api.getZr();
inner(zr).records || (inner(zr).records = {});
initGlobalListeners(zr, api);
var record = inner(zr).records[key] || (inner(zr).records[key] = {});
record.handler = handler;
}
function initGlobalListeners(zr, api) {
if (inner(zr).initialized) {
return;
}
inner(zr).initialized = true;
useHandler('click', zrUtil.curry(doEnter, 'click'));
useHandler('mousemove', zrUtil.curry(doEnter, 'mousemove')); // useHandler('mouseout', onLeave);
useHandler('globalout', onLeave);
function useHandler(eventType, cb) {
zr.on(eventType, function (e) {
var dis = makeDispatchAction(api);
each(inner(zr).records, function (record) {
record && cb(record, e, dis.dispatchAction);
});
dispatchTooltipFinally(dis.pendings, api);
});
}
}
function dispatchTooltipFinally(pendings, api) {
var showLen = pendings.showTip.length;
var hideLen = pendings.hideTip.length;
var actuallyPayload;
if (showLen) {
actuallyPayload = pendings.showTip[showLen - 1];
} else if (hideLen) {
actuallyPayload = pendings.hideTip[hideLen - 1];
}
if (actuallyPayload) {
actuallyPayload.dispatchAction = null;
api.dispatchAction(actuallyPayload);
}
}
function onLeave(record, e, dispatchAction) {
record.handler('leave', null, dispatchAction);
}
function doEnter(currTrigger, record, e, dispatchAction) {
record.handler(currTrigger, e, dispatchAction);
}
function makeDispatchAction(api) {
var pendings = {
showTip: [],
hideTip: []
}; // FIXME
// better approach?
// 'showTip' and 'hideTip' can be triggered by axisPointer and tooltip,
// which may be conflict, (axisPointer call showTip but tooltip call hideTip);
// So we have to add "final stage" to merge those dispatched actions.
var dispatchAction = function (payload) {
var pendingList = pendings[payload.type];
if (pendingList) {
pendingList.push(payload);
} else {
payload.dispatchAction = dispatchAction;
api.dispatchAction(payload);
}
};
return {
dispatchAction: dispatchAction,
pendings: pendings
};
}
/**
* @param {string} key
* @param {module:echarts/ExtensionAPI} api
*/
function unregister(key, api) {
if (env.node) {
return;
}
var zr = api.getZr();
var record = (inner(zr).records || {})[key];
if (record) {
inner(zr).records[key] = null;
}
}
exports.register = register;
exports.unregister = unregister;

View File

@ -0,0 +1,329 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var zrUtil = require("zrender/lib/core/util");
var Model = require("../../model/Model");
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var each = zrUtil.each;
var curry = zrUtil.curry; // Build axisPointerModel, mergin tooltip.axisPointer model for each axis.
// allAxesInfo should be updated when setOption performed.
function collect(ecModel, api) {
var result = {
/**
* key: makeKey(axis.model)
* value: {
* axis,
* coordSys,
* axisPointerModel,
* triggerTooltip,
* involveSeries,
* snap,
* seriesModels,
* seriesDataCount
* }
*/
axesInfo: {},
seriesInvolved: false,
/**
* key: makeKey(coordSys.model)
* value: Object: key makeKey(axis.model), value: axisInfo
*/
coordSysAxesInfo: {},
coordSysMap: {}
};
collectAxesInfo(result, ecModel, api); // Check seriesInvolved for performance, in case too many series in some chart.
result.seriesInvolved && collectSeriesInfo(result, ecModel);
return result;
}
function collectAxesInfo(result, ecModel, api) {
var globalTooltipModel = ecModel.getComponent('tooltip');
var globalAxisPointerModel = ecModel.getComponent('axisPointer'); // links can only be set on global.
var linksOption = globalAxisPointerModel.get('link', true) || [];
var linkGroups = []; // Collect axes info.
each(api.getCoordinateSystems(), function (coordSys) {
// Some coordinate system do not support axes, like geo.
if (!coordSys.axisPointerEnabled) {
return;
}
var coordSysKey = makeKey(coordSys.model);
var axesInfoInCoordSys = result.coordSysAxesInfo[coordSysKey] = {};
result.coordSysMap[coordSysKey] = coordSys; // Set tooltip (like 'cross') is a convienent way to show axisPointer
// for user. So we enable seting tooltip on coordSys model.
var coordSysModel = coordSys.model;
var baseTooltipModel = coordSysModel.getModel('tooltip', globalTooltipModel);
each(coordSys.getAxes(), curry(saveTooltipAxisInfo, false, null)); // If axis tooltip used, choose tooltip axis for each coordSys.
// Notice this case: coordSys is `grid` but not `cartesian2D` here.
if (coordSys.getTooltipAxes && globalTooltipModel // If tooltip.showContent is set as false, tooltip will not
// show but axisPointer will show as normal.
&& baseTooltipModel.get('show')) {
// Compatible with previous logic. But series.tooltip.trigger: 'axis'
// or series.data[n].tooltip.trigger: 'axis' are not support any more.
var triggerAxis = baseTooltipModel.get('trigger') === 'axis';
var cross = baseTooltipModel.get('axisPointer.type') === 'cross';
var tooltipAxes = coordSys.getTooltipAxes(baseTooltipModel.get('axisPointer.axis'));
if (triggerAxis || cross) {
each(tooltipAxes.baseAxes, curry(saveTooltipAxisInfo, cross ? 'cross' : true, triggerAxis));
}
if (cross) {
each(tooltipAxes.otherAxes, curry(saveTooltipAxisInfo, 'cross', false));
}
} // fromTooltip: true | false | 'cross'
// triggerTooltip: true | false | null
function saveTooltipAxisInfo(fromTooltip, triggerTooltip, axis) {
var axisPointerModel = axis.model.getModel('axisPointer', globalAxisPointerModel);
var axisPointerShow = axisPointerModel.get('show');
if (!axisPointerShow || axisPointerShow === 'auto' && !fromTooltip && !isHandleTrigger(axisPointerModel)) {
return;
}
if (triggerTooltip == null) {
triggerTooltip = axisPointerModel.get('triggerTooltip');
}
axisPointerModel = fromTooltip ? makeAxisPointerModel(axis, baseTooltipModel, globalAxisPointerModel, ecModel, fromTooltip, triggerTooltip) : axisPointerModel;
var snap = axisPointerModel.get('snap');
var key = makeKey(axis.model);
var involveSeries = triggerTooltip || snap || axis.type === 'category'; // If result.axesInfo[key] exist, override it (tooltip has higher priority).
var axisInfo = result.axesInfo[key] = {
key: key,
axis: axis,
coordSys: coordSys,
axisPointerModel: axisPointerModel,
triggerTooltip: triggerTooltip,
involveSeries: involveSeries,
snap: snap,
useHandle: isHandleTrigger(axisPointerModel),
seriesModels: []
};
axesInfoInCoordSys[key] = axisInfo;
result.seriesInvolved |= involveSeries;
var groupIndex = getLinkGroupIndex(linksOption, axis);
if (groupIndex != null) {
var linkGroup = linkGroups[groupIndex] || (linkGroups[groupIndex] = {
axesInfo: {}
});
linkGroup.axesInfo[key] = axisInfo;
linkGroup.mapper = linksOption[groupIndex].mapper;
axisInfo.linkGroup = linkGroup;
}
}
});
}
function makeAxisPointerModel(axis, baseTooltipModel, globalAxisPointerModel, ecModel, fromTooltip, triggerTooltip) {
var tooltipAxisPointerModel = baseTooltipModel.getModel('axisPointer');
var volatileOption = {};
each(['type', 'snap', 'lineStyle', 'shadowStyle', 'label', 'animation', 'animationDurationUpdate', 'animationEasingUpdate', 'z'], function (field) {
volatileOption[field] = zrUtil.clone(tooltipAxisPointerModel.get(field));
}); // category axis do not auto snap, otherwise some tick that do not
// has value can not be hovered. value/time/log axis default snap if
// triggered from tooltip and trigger tooltip.
volatileOption.snap = axis.type !== 'category' && !!triggerTooltip; // Compatibel with previous behavior, tooltip axis do not show label by default.
// Only these properties can be overrided from tooltip to axisPointer.
if (tooltipAxisPointerModel.get('type') === 'cross') {
volatileOption.type = 'line';
}
var labelOption = volatileOption.label || (volatileOption.label = {}); // Follow the convention, do not show label when triggered by tooltip by default.
labelOption.show == null && (labelOption.show = false);
if (fromTooltip === 'cross') {
// When 'cross', both axes show labels.
var tooltipAxisPointerLabelShow = tooltipAxisPointerModel.get('label.show');
labelOption.show = tooltipAxisPointerLabelShow != null ? tooltipAxisPointerLabelShow : true; // If triggerTooltip, this is a base axis, which should better not use cross style
// (cross style is dashed by default)
if (!triggerTooltip) {
var crossStyle = volatileOption.lineStyle = tooltipAxisPointerModel.get('crossStyle');
crossStyle && zrUtil.defaults(labelOption, crossStyle.textStyle);
}
}
return axis.model.getModel('axisPointer', new Model(volatileOption, globalAxisPointerModel, ecModel));
}
function collectSeriesInfo(result, ecModel) {
// Prepare data for axis trigger
ecModel.eachSeries(function (seriesModel) {
// Notice this case: this coordSys is `cartesian2D` but not `grid`.
var coordSys = seriesModel.coordinateSystem;
var seriesTooltipTrigger = seriesModel.get('tooltip.trigger', true);
var seriesTooltipShow = seriesModel.get('tooltip.show', true);
if (!coordSys || seriesTooltipTrigger === 'none' || seriesTooltipTrigger === false || seriesTooltipTrigger === 'item' || seriesTooltipShow === false || seriesModel.get('axisPointer.show', true) === false) {
return;
}
each(result.coordSysAxesInfo[makeKey(coordSys.model)], function (axisInfo) {
var axis = axisInfo.axis;
if (coordSys.getAxis(axis.dim) === axis) {
axisInfo.seriesModels.push(seriesModel);
axisInfo.seriesDataCount == null && (axisInfo.seriesDataCount = 0);
axisInfo.seriesDataCount += seriesModel.getData().count();
}
});
}, this);
}
/**
* For example:
* {
* axisPointer: {
* links: [{
* xAxisIndex: [2, 4],
* yAxisIndex: 'all'
* }, {
* xAxisId: ['a5', 'a7'],
* xAxisName: 'xxx'
* }]
* }
* }
*/
function getLinkGroupIndex(linksOption, axis) {
var axisModel = axis.model;
var dim = axis.dim;
for (var i = 0; i < linksOption.length; i++) {
var linkOption = linksOption[i] || {};
if (checkPropInLink(linkOption[dim + 'AxisId'], axisModel.id) || checkPropInLink(linkOption[dim + 'AxisIndex'], axisModel.componentIndex) || checkPropInLink(linkOption[dim + 'AxisName'], axisModel.name)) {
return i;
}
}
}
function checkPropInLink(linkPropValue, axisPropValue) {
return linkPropValue === 'all' || zrUtil.isArray(linkPropValue) && zrUtil.indexOf(linkPropValue, axisPropValue) >= 0 || linkPropValue === axisPropValue;
}
function fixValue(axisModel) {
var axisInfo = getAxisInfo(axisModel);
if (!axisInfo) {
return;
}
var axisPointerModel = axisInfo.axisPointerModel;
var scale = axisInfo.axis.scale;
var option = axisPointerModel.option;
var status = axisPointerModel.get('status');
var value = axisPointerModel.get('value'); // Parse init value for category and time axis.
if (value != null) {
value = scale.parse(value);
}
var useHandle = isHandleTrigger(axisPointerModel); // If `handle` used, `axisPointer` will always be displayed, so value
// and status should be initialized.
if (status == null) {
option.status = useHandle ? 'show' : 'hide';
}
var extent = scale.getExtent().slice();
extent[0] > extent[1] && extent.reverse();
if ( // Pick a value on axis when initializing.
value == null // If both `handle` and `dataZoom` are used, value may be out of axis extent,
// where we should re-pick a value to keep `handle` displaying normally.
|| value > extent[1]) {
// Make handle displayed on the end of the axis when init, which looks better.
value = extent[1];
}
if (value < extent[0]) {
value = extent[0];
}
option.value = value;
if (useHandle) {
option.status = axisInfo.axis.scale.isBlank() ? 'hide' : 'show';
}
}
function getAxisInfo(axisModel) {
var coordSysAxesInfo = (axisModel.ecModel.getComponent('axisPointer') || {}).coordSysAxesInfo;
return coordSysAxesInfo && coordSysAxesInfo.axesInfo[makeKey(axisModel)];
}
function getAxisPointerModel(axisModel) {
var axisInfo = getAxisInfo(axisModel);
return axisInfo && axisInfo.axisPointerModel;
}
function isHandleTrigger(axisPointerModel) {
return !!axisPointerModel.get('handle.show');
}
/**
* @param {module:echarts/model/Model} model
* @return {string} unique key
*/
function makeKey(model) {
return model.type + '||' + model.id;
}
exports.collect = collect;
exports.fixValue = fixValue;
exports.getAxisInfo = getAxisInfo;
exports.getAxisPointerModel = getAxisPointerModel;
exports.makeKey = makeKey;

View File

@ -0,0 +1,263 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var zrUtil = require("zrender/lib/core/util");
var graphic = require("../../util/graphic");
var textContain = require("zrender/lib/contain/text");
var formatUtil = require("../../util/format");
var matrix = require("zrender/lib/core/matrix");
var axisHelper = require("../../coord/axisHelper");
var AxisBuilder = require("../axis/AxisBuilder");
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* @param {module:echarts/model/Model} axisPointerModel
*/
function buildElStyle(axisPointerModel) {
var axisPointerType = axisPointerModel.get('type');
var styleModel = axisPointerModel.getModel(axisPointerType + 'Style');
var style;
if (axisPointerType === 'line') {
style = styleModel.getLineStyle();
style.fill = null;
} else if (axisPointerType === 'shadow') {
style = styleModel.getAreaStyle();
style.stroke = null;
}
return style;
}
/**
* @param {Function} labelPos {align, verticalAlign, position}
*/
function buildLabelElOption(elOption, axisModel, axisPointerModel, api, labelPos) {
var value = axisPointerModel.get('value');
var text = getValueLabel(value, axisModel.axis, axisModel.ecModel, axisPointerModel.get('seriesDataIndices'), {
precision: axisPointerModel.get('label.precision'),
formatter: axisPointerModel.get('label.formatter')
});
var labelModel = axisPointerModel.getModel('label');
var paddings = formatUtil.normalizeCssArray(labelModel.get('padding') || 0);
var font = labelModel.getFont();
var textRect = textContain.getBoundingRect(text, font);
var position = labelPos.position;
var width = textRect.width + paddings[1] + paddings[3];
var height = textRect.height + paddings[0] + paddings[2]; // Adjust by align.
var align = labelPos.align;
align === 'right' && (position[0] -= width);
align === 'center' && (position[0] -= width / 2);
var verticalAlign = labelPos.verticalAlign;
verticalAlign === 'bottom' && (position[1] -= height);
verticalAlign === 'middle' && (position[1] -= height / 2); // Not overflow ec container
confineInContainer(position, width, height, api);
var bgColor = labelModel.get('backgroundColor');
if (!bgColor || bgColor === 'auto') {
bgColor = axisModel.get('axisLine.lineStyle.color');
}
elOption.label = {
shape: {
x: 0,
y: 0,
width: width,
height: height,
r: labelModel.get('borderRadius')
},
position: position.slice(),
// TODO: rich
style: {
text: text,
textFont: font,
textFill: labelModel.getTextColor(),
textPosition: 'inside',
textPadding: paddings,
fill: bgColor,
stroke: labelModel.get('borderColor') || 'transparent',
lineWidth: labelModel.get('borderWidth') || 0,
shadowBlur: labelModel.get('shadowBlur'),
shadowColor: labelModel.get('shadowColor'),
shadowOffsetX: labelModel.get('shadowOffsetX'),
shadowOffsetY: labelModel.get('shadowOffsetY')
},
// Lable should be over axisPointer.
z2: 10
};
} // Do not overflow ec container
function confineInContainer(position, width, height, api) {
var viewWidth = api.getWidth();
var viewHeight = api.getHeight();
position[0] = Math.min(position[0] + width, viewWidth) - width;
position[1] = Math.min(position[1] + height, viewHeight) - height;
position[0] = Math.max(position[0], 0);
position[1] = Math.max(position[1], 0);
}
/**
* @param {number} value
* @param {module:echarts/coord/Axis} axis
* @param {module:echarts/model/Global} ecModel
* @param {Object} opt
* @param {Array.<Object>} seriesDataIndices
* @param {number|string} opt.precision 'auto' or a number
* @param {string|Function} opt.formatter label formatter
*/
function getValueLabel(value, axis, ecModel, seriesDataIndices, opt) {
value = axis.scale.parse(value);
var text = axis.scale.getLabel( // If `precision` is set, width can be fixed (like '12.00500'), which
// helps to debounce when when moving label.
value, {
precision: opt.precision
});
var formatter = opt.formatter;
if (formatter) {
var params = {
value: axisHelper.getAxisRawValue(axis, value),
axisDimension: axis.dim,
axisIndex: axis.index,
seriesData: []
};
zrUtil.each(seriesDataIndices, function (idxItem) {
var series = ecModel.getSeriesByIndex(idxItem.seriesIndex);
var dataIndex = idxItem.dataIndexInside;
var dataParams = series && series.getDataParams(dataIndex);
dataParams && params.seriesData.push(dataParams);
});
if (zrUtil.isString(formatter)) {
text = formatter.replace('{value}', text);
} else if (zrUtil.isFunction(formatter)) {
text = formatter(params);
}
}
return text;
}
/**
* @param {module:echarts/coord/Axis} axis
* @param {number} value
* @param {Object} layoutInfo {
* rotation, position, labelOffset, labelDirection, labelMargin
* }
*/
function getTransformedPosition(axis, value, layoutInfo) {
var transform = matrix.create();
matrix.rotate(transform, transform, layoutInfo.rotation);
matrix.translate(transform, transform, layoutInfo.position);
return graphic.applyTransform([axis.dataToCoord(value), (layoutInfo.labelOffset || 0) + (layoutInfo.labelDirection || 1) * (layoutInfo.labelMargin || 0)], transform);
}
function buildCartesianSingleLabelElOption(value, elOption, layoutInfo, axisModel, axisPointerModel, api) {
var textLayout = AxisBuilder.innerTextLayout(layoutInfo.rotation, 0, layoutInfo.labelDirection);
layoutInfo.labelMargin = axisPointerModel.get('label.margin');
buildLabelElOption(elOption, axisModel, axisPointerModel, api, {
position: getTransformedPosition(axisModel.axis, value, layoutInfo),
align: textLayout.textAlign,
verticalAlign: textLayout.textVerticalAlign
});
}
/**
* @param {Array.<number>} p1
* @param {Array.<number>} p2
* @param {number} [xDimIndex=0] or 1
*/
function makeLineShape(p1, p2, xDimIndex) {
xDimIndex = xDimIndex || 0;
return {
x1: p1[xDimIndex],
y1: p1[1 - xDimIndex],
x2: p2[xDimIndex],
y2: p2[1 - xDimIndex]
};
}
/**
* @param {Array.<number>} xy
* @param {Array.<number>} wh
* @param {number} [xDimIndex=0] or 1
*/
function makeRectShape(xy, wh, xDimIndex) {
xDimIndex = xDimIndex || 0;
return {
x: xy[xDimIndex],
y: xy[1 - xDimIndex],
width: wh[xDimIndex],
height: wh[1 - xDimIndex]
};
}
function makeSectorShape(cx, cy, r0, r, startAngle, endAngle) {
return {
cx: cx,
cy: cy,
r0: r0,
r: r,
startAngle: startAngle,
endAngle: endAngle,
clockwise: true
};
}
exports.buildElStyle = buildElStyle;
exports.buildLabelElOption = buildLabelElOption;
exports.getValueLabel = getValueLabel;
exports.getTransformedPosition = getTransformedPosition;
exports.buildCartesianSingleLabelElOption = buildCartesianSingleLabelElOption;
exports.makeLineShape = makeLineShape;
exports.makeRectShape = makeRectShape;
exports.makeSectorShape = makeSectorShape;