Skip to content

Commit

Permalink
Enable triggerEvent for angleAxis label. Fix #9765
Browse files Browse the repository at this point in the history
  • Loading branch information
100pah committed Jan 16, 2019
1 parent 856a285 commit 32c35e5
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 18 deletions.
14 changes: 13 additions & 1 deletion src/component/axis/AngleAxisView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'];

Expand Down Expand Up @@ -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) {
Expand All @@ -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],
Expand All @@ -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);
},

Expand Down
26 changes: 13 additions & 13 deletions src/component/axis/AxisBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -354,7 +345,7 @@ var builders = {

position: pos,
rotation: labelLayout.rotation,
silent: isSilent(axisModel),
silent: isLabelSilent(axisModel),
z2: 1,
tooltip: (tooltipOpt && tooltipOpt.show)
? extend({
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion test/bar-polar-basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
background: #fff;
}
</style>
<h3>click axis labe should console log</h3>
<div id="main"></div>
<script>

Expand All @@ -50,11 +51,13 @@

chart.setOption({
angleAxis: {
triggerEvent: true
},
radiusAxis: {
type: 'category',
data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
z: 10
z: 10,
triggerEvent: true
},
polar: {
},
Expand Down
14 changes: 11 additions & 3 deletions test/ut/spec/component/helper/sliderMove.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 32c35e5

Please sign in to comment.