Skip to content

Commit

Permalink
fix: bar start when multiple axes. fix apache#8747.
Browse files Browse the repository at this point in the history
  • Loading branch information
100pah committed Sep 3, 2018
1 parent ba7a252 commit 0a5282b
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/component/tooltip/TooltipRichContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import * as zrUtil from 'zrender/src/core/util';
import Group from 'zrender/src/container/Group';
// import Group from 'zrender/src/container/Group';
import Text from 'zrender/src/graphic/Text';

/**
Expand All @@ -28,7 +28,7 @@ import Text from 'zrender/src/graphic/Text';
function TooltipRichContent(api) {
// this.el = new Group();

var zr = this._zr = api.getZr();
// var zr = this._zr = api.getZr();
// zr.add(this.el);

this._show = false;
Expand Down
24 changes: 18 additions & 6 deletions src/layout/barGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,11 +420,23 @@ function isInLargeMode(seriesModel) {
return seriesModel.pipelineContext && seriesModel.pipelineContext.large;
}

// See cases in `test/bar-start.html` and `#7412`, `#8747`.
function getValueAxisStart(baseAxis, valueAxis, stacked) {
return (
zrUtil.indexOf(baseAxis.getAxesOnZeroOf(), valueAxis) >= 0
|| stacked
)
? valueAxis.toGlobalCoord(valueAxis.dataToCoord(0))
: valueAxis.getGlobalExtent()[0];
var extent = valueAxis.getGlobalExtent();
var min;
var max;
if (extent[0] > extent[1]) {
min = extent[1];
max = extent[0];
}
else {
min = extent[0];
max = extent[1];
}

var valueStart = valueAxis.toGlobalCoord(valueAxis.dataToCoord(0));
valueStart < min && (valueStart = min);
valueStart > max && (valueStart = max);

return valueStart;
}
73 changes: 72 additions & 1 deletion test/bar-start.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@


<div id="main0"></div>
<div id="main1"></div>


<script>
Expand All @@ -64,6 +65,9 @@
min: 5000000
}, {
}],
grid: {
left: 100
},
series: [{
name: 'bar',
type: 'bar',
Expand All @@ -72,7 +76,7 @@
}, {
name: 'line',
type: 'line',
yAxisIndex:1,
yAxisIndex: 1,
data: [1.1496899,0.9420012,0.6743367,0.47701207,0.67934614,0.37843546]
}]
};
Expand All @@ -85,5 +89,72 @@
});

</script>








<script>

// See <https://github.com/apache/incubator-echarts/issues/8747>
// Thanks to <https://github.com/kuky121>

var chart;
var myChart;
var option;

require([
'echarts'/*, 'map/js/china' */
], function (echarts) {

var option = {
xAxis : [
{
type : 'category',
data : ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
axisTick: {
alignWithLabel: true
}
}
],
yAxis : [
{
type : 'value'
},
{
type : 'value'
}
],
series : [
{
yAxisIndex:0,
name:'数据1',
type:'bar',
data:[10, -52]
},
{
yAxisIndex:1,
name:'数据2',
type:'bar',
data:[10, -52]
}
]
};

chart = myChart = testHelper.create(echarts, 'main1', {
title: 'bar start should be correct when two Y axes exists',
option: option,
info: option
});
});

</script>




</body>
</html>

0 comments on commit 0a5282b

Please sign in to comment.