Skip to content

Commit

Permalink
[visualMap] Fix #4845 (support end text and label at the same time)
Browse files Browse the repository at this point in the history
  • Loading branch information
100pah committed Jan 8, 2017
1 parent 901893e commit d9514b6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
7 changes: 6 additions & 1 deletion src/component/visualMap/PiecewiseModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ define(function(require) {
// compatibility, see echarts/component/visualMap/typeDefaulter)
selectedMode: 'multiple', // Can be 'multiple' or 'single'.
itemGap: 10, // The gap between two items, in px.
hoverLink: true // Enable hover highlight.
hoverLink: true, // Enable hover highlight.

showLabel: null // By default, when text is used, label will hide (the logic
// is remained for compatibility reason)
},

/**
Expand Down Expand Up @@ -104,6 +107,8 @@ define(function(require) {
mappingOption.pieceList = zrUtil.map(this._pieceList, function (piece) {
var piece = zrUtil.clone(piece);
if (state !== 'inRange') {
// FIXME
// outOfRange do not support special visual in pieces.
piece.visual = null;
}
return piece;
Expand Down
19 changes: 11 additions & 8 deletions src/component/visualMap/PiecewiseView.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,19 @@ define(function(require) {
var textFill = textStyleModel.getTextColor();
var itemAlign = this._getItemAlign();
var itemSize = visualMapModel.itemSize;

var viewData = this._getViewData();
var showLabel = !viewData.endsText;
var showEndsText = !showLabel;
var endsText = viewData.endsText;
var showLabel = zrUtil.retrieve(visualMapModel.get('showLabel', true), !endsText);

showEndsText && this._renderEndsText(thisGroup, viewData.endsText[0], itemSize);
endsText && this._renderEndsText(
thisGroup, endsText[0], itemSize, showLabel, itemAlign
);

zrUtil.each(viewData.viewPieceList, renderItem, this);

showEndsText && this._renderEndsText(thisGroup, viewData.endsText[1], itemSize);
endsText && this._renderEndsText(
thisGroup, endsText[1], itemSize, showLabel, itemAlign
);

layout.box(
visualMapModel.get('orient'), thisGroup, visualMapModel.get('itemGap')
Expand Down Expand Up @@ -125,7 +128,7 @@ define(function(require) {
/**
* @private
*/
_renderEndsText: function (group, text, itemSize) {
_renderEndsText: function (group, text, itemSize, showLabel, itemAlign) {
if (!text) {
return;
}
Expand All @@ -135,10 +138,10 @@ define(function(require) {

itemGroup.add(new graphic.Text({
style: {
x: itemSize[0] / 2,
x: showLabel ? (itemAlign === 'right' ? itemSize[0] : 0) : itemSize[0] / 2,
y: itemSize[1] / 2,
textVerticalAlign: 'middle',
textAlign: 'center',
textAlign: showLabel ? itemAlign : 'center',
text: text,
textFont: textStyleModel.getFont(),
fill: textStyleModel.getTextColor()
Expand Down
3 changes: 3 additions & 0 deletions test/visualMap-pieces.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
},
visualMap: {
// selectedMode: 'single',
text: ['Map Result'],
showLabel: true,
right: 20,
pieces: [
{min: 1500},
{min: 900, max: 1500},
Expand Down

0 comments on commit d9514b6

Please sign in to comment.