You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by sh...@apache.org on 2019/09/18 16:36:24 UTC
[incubator-echarts] branch feature/clip updated: feat(clip): clip
bar on grid.
This is an automated email from the ASF dual-hosted git repository.
shenyi pushed a commit to branch feature/clip
in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git
The following commit(s) were added to refs/heads/feature/clip by this push:
new de98ef6 feat(clip): clip bar on grid.
de98ef6 is described below
commit de98ef690ddfc0e608c7a0e9af4d6f7b30beb0fd
Author: pissang <bm...@gmail.com>
AuthorDate: Thu Sep 19 00:35:57 2019 +0800
feat(clip): clip bar on grid.
---
src/chart/bar/BarView.js | 70 +++++++++++
src/chart/bar/BaseBarSeries.js | 3 +
src/coord/cartesian/Cartesian2D.js | 4 +-
src/layout/barGrid.js | 18 +--
test/clip.html | 250 +++++++++++++++++++++++++++++++++++--
5 files changed, 319 insertions(+), 26 deletions(-)
diff --git a/src/chart/bar/BarView.js b/src/chart/bar/BarView.js
index 3d9db41..5cbcf86 100644
--- a/src/chart/bar/BarView.js
+++ b/src/chart/bar/BarView.js
@@ -93,6 +93,10 @@ export default echarts.extendChartView({
var animationModel = seriesModel.isAnimationEnabled() ? seriesModel : null;
+ var coordSysClipArea = coord.getArea && coord.getArea();
+
+ var needsClip = seriesModel.get('clip');
+
data.diff(oldData)
.add(function (dataIndex) {
if (!data.hasValue(dataIndex)) {
@@ -101,6 +105,17 @@ export default echarts.extendChartView({
var itemModel = data.getItemModel(dataIndex);
var layout = getLayout[coord.type](data, dataIndex, itemModel);
+
+ if (needsClip) {
+ // Clip will modify the layout params.
+ // And return a boolean to determine if the shape are fully clipped.
+ var isClipped = clip[coord.type](coordSysClipArea, layout);
+ if (isClipped) {
+ group.remove(el);
+ return;
+ }
+ }
+
var el = elementCreator[coord.type](
data, dataIndex, itemModel, layout, isHorizontalOrRadial, animationModel
);
@@ -123,6 +138,14 @@ export default echarts.extendChartView({
var itemModel = data.getItemModel(newIndex);
var layout = getLayout[coord.type](data, newIndex, itemModel);
+ if (needsClip) {
+ var isClipped = clip[coord.type](coordSysClipArea, layout);
+ if (isClipped) {
+ group.remove(el);
+ return;
+ }
+ }
+
if (el) {
graphic.updateProps(el, {shape: layout}, animationModel, newIndex);
}
@@ -191,6 +214,53 @@ export default echarts.extendChartView({
});
+var mathMax = Math.max;
+var mathMin = Math.min;
+
+var clip = {
+ cartesian2d: function (coordSysBoundingRect, layout) {
+ var signWidth = layout.width < 0 ? -1 : 1;
+ var signHeight = layout.height < 0 ? -1 : 1;
+ // Needs positive width and height
+ if (signWidth < 0) {
+ layout.x += layout.width;
+ layout.width = -layout.width;
+ }
+ if (signHeight < 0) {
+ layout.y += layout.height;
+ layout.height = -layout.height;
+ }
+
+ var x = mathMax(layout.x, coordSysBoundingRect.x);
+ var x2 = mathMin(layout.x + layout.width, coordSysBoundingRect.x + coordSysBoundingRect.width);
+ var y = mathMax(layout.y, coordSysBoundingRect.y);
+ var y2 = mathMin(layout.y + layout.height, coordSysBoundingRect.y + coordSysBoundingRect.height);
+
+ layout.x = x;
+ layout.y = y;
+ layout.width = x2 - x;
+ layout.height = y2 - y;
+
+ var clipped = layout.width < 0 || layout.height < 0;;
+
+ // Reverse back
+ if (signWidth < 0) {
+ layout.x += layout.width;
+ layout.width = -layout.width;
+ }
+ if (signHeight < 0) {
+ layout.y += layout.height;
+ layout.height = -layout.height;
+ }
+
+ return clipped;
+ },
+
+ polar: function (coordSysClipArea) {
+ return false;
+ }
+};
+
var elementCreator = {
cartesian2d: function (
diff --git a/src/chart/bar/BaseBarSeries.js b/src/chart/bar/BaseBarSeries.js
index 7c8b603..7916c4c 100644
--- a/src/chart/bar/BaseBarSeries.js
+++ b/src/chart/bar/BaseBarSeries.js
@@ -65,6 +65,9 @@ export default SeriesModel.extend({
progressive: 3e3,
progressiveChunkMode: 'mod',
+ // If clipped
+ // Only available on cartesian2d
+ clip: true,
// barMaxWidth: null,
// 默认自适应
// barWidth: null,
diff --git a/src/coord/cartesian/Cartesian2D.js b/src/coord/cartesian/Cartesian2D.js
index 511ddf1..55ae631 100644
--- a/src/coord/cartesian/Cartesian2D.js
+++ b/src/coord/cartesian/Cartesian2D.js
@@ -152,8 +152,8 @@ Cartesian2D.prototype = {
* @return {BoundingRect}
*/
getArea: function () {
- var xExtent = getAxisExtentWithGap(this.getAxis('x'));
- var yExtent = getAxisExtentWithGap(this.getAxis('y'));
+ var xExtent = this.getAxis('x').getGlobalExtent();
+ var yExtent = this.getAxis('y').getGlobalExtent();
var x = Math.min(xExtent[0], xExtent[1]);
var y = Math.min(yExtent[0], yExtent[1]);
var width = Math.max(xExtent[0], xExtent[1]) - x;
diff --git a/src/layout/barGrid.js b/src/layout/barGrid.js
index 94d8333..5d211d8 100644
--- a/src/layout/barGrid.js
+++ b/src/layout/barGrid.js
@@ -431,21 +431,5 @@ function isInLargeMode(seriesModel) {
// See cases in `test/bar-start.html` and `#7412`, `#8747`.
function getValueAxisStart(baseAxis, valueAxis, stacked) {
- 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;
+ return valueAxis.toGlobalCoord(valueAxis.dataToCoord(0));
}
diff --git a/test/clip.html b/test/clip.html
index d08e89d..f21eefa 100644
--- a/test/clip.html
+++ b/test/clip.html
@@ -49,7 +49,8 @@ under the License.
<div class="chart" id="scatter-clip-incremental"></div> -->
<div class="chart" id="large-scatter-clip"></div>
<div class="chart" id="lines-clip"></div>
- <div class="chart" id="line-dataZoom"></div>
+ <div class="chart" id="line-dataZoom-time"></div>
+ <div class="chart" id="line-dataZoom-category"></div>
<div class="chart" id="bar-clip"></div>
<div class="chart" id="custom-clip"></div>
<div class="chart" id="candlestick-clip"></div>
@@ -355,7 +356,13 @@ under the License.
title: 'Lines Clip,(case from #10748). Should not overflow after zoomed in',
option: option,
height: 400,
- buttons: makeToggleChartButtons()
+ buttons: makeToggleChartButtons(function (clip) {
+ chart.setOption({
+ series: [{
+ clip: clip
+ }]
+ })
+ })
});
})
</script>
@@ -389,10 +396,6 @@ under the License.
option = {
animation: false,
- legend: {
- top: 'bottom',
- data:['意向']
- },
tooltip: {
triggerOn: 'none',
position: function (pt) {
@@ -512,7 +515,7 @@ under the License.
});
}
- var chart = testHelper.create(echarts, 'line-dataZoom', {
+ var chart = testHelper.create(echarts, 'line-dataZoom-time', {
title: 'Line with dataZoom,(#10224). Should not be blank when selected a small area',
option: option,
height: 400,
@@ -531,5 +534,238 @@ under the License.
})
</script>
+
+
+ <script>
+ require([
+ 'echarts'
+ ], function (echarts) {
+ option = {
+ animation: false,
+ toolbox: {
+ left: 'center',
+ itemSize: 25,
+ top: 55,
+ feature: {
+ dataZoom: {
+ // Not filter the data.
+ // filterMode: 'none',
+ yAxisIndex: 'none'
+ },
+ restore: {}
+ }
+ },
+ grid: {
+ top: 100
+ },
+ xAxis : [
+ {
+ type : 'category',
+ boundaryGap : false,
+ data : ['周一','周二','周三','周四','周五','周六','周日']
+ }
+ ],
+ yAxis : [
+ {
+ type : 'value'
+ }
+ ],
+ series : [
+ {
+ name:'邮件营销',
+ type:'line',
+ stack: '总量',
+ areaStyle: {},
+ data:[120, 132, 101, 134, 90, 230, 210]
+ },
+ {
+ name:'联盟广告',
+ type:'line',
+ stack: '总量',
+ areaStyle: {},
+ data:[220, 182, 191, 234, 290, 330, 310]
+ },
+ {
+ name:'视频广告',
+ type:'line',
+ stack: '总量',
+ areaStyle: {},
+ data:[150, 232, 201, 154, 190, 330, 410]
+ },
+ {
+ name:'直接访问',
+ type:'line',
+ stack: '总量',
+ areaStyle: {normal: {}},
+ data:[320, 332, 301, 334, 390, 330, 320]
+ },
+ {
+ name:'搜索引擎',
+ type:'line',
+ stack: '总量',
+ label: {
+ normal: {
+ show: true,
+ position: 'top'
+ }
+ },
+ areaStyle: {normal: {}},
+ data:[820, 932, 901, 934, 1290, 1330, 1320]
+ }
+ ]
+ };
+
+ function setFilterMode(mode) {
+ chart.setOption({
+ toolbox: {
+ feature: {
+ dataZoom: {
+ filterMode: mode
+ }
+ }
+ }
+ });
+ }
+
+ var chart = testHelper.create(echarts, 'line-dataZoom-category', {
+ title: 'Line with dataZoom (category axis)',
+ option: option,
+ height: 400,
+ buttons: [{
+ text: 'Set filter all',
+ onclick: function () {
+ setFilterMode('filter');
+ }
+ }, {
+ text: 'Set filter none',
+ onclick: function () {
+ setFilterMode('none')
+ }
+ }]
+ });
+ })
+ </script>
+
+
+ <script>
+
+ require([
+ 'echarts'
+ ], function (echarts) {
+
+ var xInversed = false;
+
+ option = {
+ tooltip : {
+ trigger: 'axis',
+ axisPointer : { // 坐标轴指示器,坐标轴触发有效
+ type : 'shadow' // 默认为直线,可选为:'line' | 'shadow'
+ }
+ },
+ legend: {
+ data: ['直接访问', '邮件营销','联盟广告','视频广告','搜索引擎']
+ },
+ grid: {
+ left: '3%',
+ right: '4%',
+ bottom: '3%',
+ containLabel: true
+ },
+ xAxis: {
+ type: 'value',
+ min: 200
+ },
+ yAxis: {
+ type: 'category',
+ data: ['周一','周二','周三','周四','周五','周六','周日']
+ },
+ series: [
+ {
+ name: '直接访问',
+ type: 'bar',
+ stack: '总量',
+ label: {
+ normal: {
+ show: true,
+ position: 'insideRight'
+ }
+ },
+ data: [320, 302, 301, 334, 390, 330, 320]
+ },
+ {
+ name: '邮件营销',
+ type: 'bar',
+ stack: '总量',
+ label: {
+ normal: {
+ show: true,
+ position: 'insideRight'
+ }
+ },
+ data: [120, 132, 101, 134, 90, 230, 210]
+ },
+ {
+ name: '联盟广告',
+ type: 'bar',
+ stack: '总量',
+ label: {
+ normal: {
+ show: true,
+ position: 'insideRight'
+ }
+ },
+ data: [220, 182, 191, 234, 290, 330, 310]
+ },
+ {
+ name: '视频广告',
+ type: 'bar',
+ stack: '总量',
+ label: {
+ normal: {
+ show: true,
+ position: 'insideRight'
+ }
+ },
+ data: [150, 212, 201, 154, 190, 330, 410]
+ },
+ {
+ name: '搜索引擎',
+ type: 'bar',
+ stack: '总量',
+ label: {
+ normal: {
+ show: true,
+ position: 'insideRight'
+ }
+ },
+ data: [820, 832, 901, 934, 1290, 1330, 1320]
+ }
+ ]
+ };
+
+ var chart = testHelper.create(echarts, 'bar-clip', {
+ title: 'Clip bar chart',
+ option: option,
+ height: 400,
+ buttons: makeToggleChartButtons(function (clip) {
+ chart.setOption({
+ series: [{
+ clip: clip
+ }]
+ })
+ }).concat([{
+ text: 'Inverse X',
+ onclick: function () {
+ xInversed = !xInversed;
+ chart.setOption({
+ xAxis: {
+ inverse: xInversed
+ }
+ });
+ }
+ }])
+ });
+ });
+ </script>
</body>
</html>
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org