Skip to content

Commit

Permalink
Series can provide custom marker position calculation. Fix #2623
Browse files Browse the repository at this point in the history
  • Loading branch information
pissang committed Feb 21, 2016
1 parent a5c6eb3 commit 5af04da
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/chart/bar/BarSeries.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ define(function(require) {
return createListFromArray(option.data, this, ecModel);
},

getMarkerPosition: function (value) {
var coordSys = this.coordinateSystem;
if (coordSys) {
var pt = coordSys.dataToPoint(value);
var data = this.getData();
var offset = data.getLayout('offset');
var size = data.getLayout('size');
var offsetIndex = coordSys.getBaseAxis().isHorizontal() ? 0 : 1;
pt[offsetIndex] += offset + size / 2;
return pt;
}
return [NaN, NaN];
},

defaultOption: {
zlevel: 0, // 一级层叠
z: 2, // 二级层叠
Expand Down
7 changes: 7 additions & 0 deletions src/component/marker/MarkLineView.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,13 @@ define(function (require) {
numberUtil.parsePercent(yPx, api.getHeight())
];
}
// Chart like bar may have there own marker positioning logic
else if (seriesModel.getMarkerPosition) {
// Use the getMarkerPoisition
point = seriesModel.getMarkerPosition(
data.getValues(data.dimensions, idx)
);
}
else {
var x = data.get(dims[0], idx);
var y = data.get(dims[1], idx);
Expand Down
7 changes: 7 additions & 0 deletions src/component/marker/MarkPointView.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ define(function (require) {
numberUtil.parsePercent(yPx, api.getHeight())
];
}
// Chart like bar may have there own marker positioning logic
else if (seriesModel.getMarkerPosition) {
// Use the getMarkerPoisition
point = seriesModel.getMarkerPosition(
mpData.getValues(mpData.dimensions, idx)
);
}
else if (coordSys) {
var x = mpData.get(dims[0], idx);
var y = mpData.get(dims[1], idx);
Expand Down
10 changes: 9 additions & 1 deletion src/data/List.js
Original file line number Diff line number Diff line change
Expand Up @@ -800,9 +800,17 @@ define(function (require) {
/**
* Set layout property.
* @param {string} key
* @param {*} val
* @param {*} [val]
*/
listProto.setLayout = function (key, val) {
if (isObject(key)) {
for (var name in key) {
if (key.hasOwnProperty(name)) {
this.setLayout(name, key[name]);
}
}
return;
}
this._layout[key] = val;
};

Expand Down
5 changes: 5 additions & 0 deletions src/layout/barGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ define(function(require) {
var coords = cartesian.dataToPoints(data, true);
lastStackCoords[stackId] = lastStackCoords[stackId] || [];

data.setLayout({
offset: columnOffset,
size: columnWidth
});
data.each(valueAxis.dim, function (value, idx) {
// 空数据
if (isNaN(value)) {
Expand Down Expand Up @@ -205,6 +209,7 @@ define(function(require) {
height: height
});
}, true);

}, this);
}

Expand Down

0 comments on commit 5af04da

Please sign in to comment.