提交 32c35e58 编写于 作者: S sushuang

Enable triggerEvent for angleAxis label. Fix #9765

上级 856a2856
......@@ -21,6 +21,7 @@ import * as zrUtil from 'zrender/src/core/util';
import * as graphic from '../../util/graphic';
import Model from '../../model/Model';
import AxisView from './AxisView';
import AxisBuilder from './AxisBuilder';
var elementList = ['axisLine', 'axisLabel', 'axisTick', 'splitLine', 'splitArea'];
......@@ -145,6 +146,7 @@ export default AxisView.extend({
var commonLabelModel = angleAxisModel.getModel('axisLabel');
var labelMargin = commonLabelModel.get('margin');
var triggerEvent = angleAxisModel.get('triggerEvent');
// Use length of ticksAngles because it may remove the last tick to avoid overlapping
zrUtil.each(labels, function (labelItem, idx) {
......@@ -167,7 +169,9 @@ export default AxisView.extend({
);
}
var textEl = new graphic.Text({silent: true});
var textEl = new graphic.Text({
silent: AxisBuilder.isLabelSilent(angleAxisModel)
});
this.group.add(textEl);
graphic.setTextStyle(textEl.style, labelModel, {
x: p[0],
......@@ -177,6 +181,14 @@ export default AxisView.extend({
textAlign: labelTextAlign,
textVerticalAlign: labelTextVerticalAlign
});
// Pack data for mouse event
if (triggerEvent) {
textEl.eventData = AxisBuilder.makeAxisEventDataBase(angleAxisModel);
textEl.eventData.targetType = 'axisLabel';
textEl.eventData.value = labelItem.rawLabel;
}
}, this);
},
......
......@@ -30,15 +30,6 @@ import {shouldShowAllLabels} from '../../coord/axisHelper';
var PI = Math.PI;
function makeAxisEventDataBase(axisModel) {
var eventData = {
componentType: axisModel.mainType,
componentIndex: axisModel.componentIndex
};
eventData[axisModel.mainType + 'Index'] = axisModel.componentIndex;
return eventData;
}
/**
* A final axis is translated and rotated from a "standard axis".
* So opt.position and opt.rotation is required.
......@@ -354,7 +345,7 @@ var builders = {
position: pos,
rotation: labelLayout.rotation,
silent: isSilent(axisModel),
silent: isLabelSilent(axisModel),
z2: 1,
tooltip: (tooltipOpt && tooltipOpt.show)
? extend({
......@@ -393,6 +384,15 @@ var builders = {
};
var makeAxisEventDataBase = AxisBuilder.makeAxisEventDataBase = function (axisModel) {
var eventData = {
componentType: axisModel.mainType,
componentIndex: axisModel.componentIndex
};
eventData[axisModel.mainType + 'Index'] = axisModel.componentIndex;
return eventData;
};
/**
* @public
* @static
......@@ -470,14 +470,14 @@ function endTextLayout(opt, textPosition, textRotate, extent) {
};
}
function isSilent(axisModel) {
var isLabelSilent = AxisBuilder.isLabelSilent = function (axisModel) {
var tooltipOpt = axisModel.get('tooltip');
return axisModel.get('silent')
// Consider mouse cursor, add these restrictions.
|| !(
axisModel.get('triggerEvent') || (tooltipOpt && tooltipOpt.show)
);
}
};
function fixMinMaxLabelShow(axisModel, labelEls, tickEls) {
if (shouldShowAllLabels(axisModel.axis)) {
......@@ -645,7 +645,7 @@ function buildAxisLabel(axisBuilder, axisModel, opt) {
var rawCategoryData = axisModel.getCategories(true);
var labelEls = [];
var silent = isSilent(axisModel);
var silent = isLabelSilent(axisModel);
var triggerEvent = axisModel.get('triggerEvent');
each(labels, function (labelItem, index) {
......
......@@ -36,6 +36,7 @@ under the License.
background: #fff;
}
</style>
<h3>click axis labe should console log</h3>
<div id="main"></div>
<script>
......@@ -50,11 +51,13 @@ under the License.
chart.setOption({
angleAxis: {
triggerEvent: true
},
radiusAxis: {
type: 'category',
data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
z: 10
z: 10,
triggerEvent: true
},
polar: {
},
......
......@@ -42,14 +42,22 @@ describe('component/helper/sliderMove', function () {
// normalize by maxSpec
expect(sliderMove(0, [20, 42], [20, 50], 0, null, 10)).toEqual([20, 30]);
// Do not move
expect(sliderMove(0, [-10, 70], [20, 50], 'all')).toEqual([20, 50]);
// minSpan bigger than extent
expect(sliderMove(4, [20, 25], [10, 50], 0, 300)).toEqual([10, 50]);
// maxSpan smaller than minSpan
expect(sliderMove(4, [20, 25], [10, 50], 0, 6, 3)).toEqual([24, 30]);
// extent small then input range
expect(sliderMove(0, [-10, 70], [20, 50], 'all')).toEqual([20, 50]);
expect(sliderMove(0, [-10, 14], [1, 101], 'all')).toEqual([1, 25]);
expect(sliderMove(0, [99, 110], [1, 101], 'all')).toEqual([90, 101]);
expect(sliderMove(0, [-10, 14], [1, 101], 'all', null, 16)).toEqual([1, 17]);
expect(sliderMove(0, [-10, 14], [1, 101], 'all', 15, 16)).toEqual([1, 17]);
expect(sliderMove(0, [-10, 14], [1, 101], 'all', 50, null)).toEqual([1, 51]);
expect(sliderMove(0, [-10, 14], [1, 101], 'all', 50, 55)).toEqual([1, 51]);
expect(sliderMove(0, [-10, 14], [1, 101], 'all', 10, 55)).toEqual([1, 25]);
});
testCase('rigid_move', function (sliderMove) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册