Skip to content

Commit

Permalink
Merge pull request #19197 from apache/feat-pictorialBar-clip
Browse files Browse the repository at this point in the history
feat(pictorialBar): support clip for pictorialBar series
  • Loading branch information
linghaoSu committed Nov 30, 2023
2 parents 80525ed + 71799e9 commit 7731729
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/chart/bar/PictorialBarSeries.ts
Expand Up @@ -119,6 +119,8 @@ export interface PictorialBarSeriesOption
coordinateSystem?: 'cartesian2d'

data?: (PictorialBarDataItemOption | OptionDataValue | OptionDataValue[])[]

clip?: boolean
}

class PictorialBarSeriesModel extends BaseBarSeriesModel<PictorialBarSeriesOption> {
Expand Down Expand Up @@ -150,6 +152,10 @@ class PictorialBarSeriesModel extends BaseBarSeriesModel<PictorialBarSeriesOptio

barGap: '-100%', // In most case, overlap is needed.

// Pictorial bar do not clip by default because in many cases
// xAxis and yAxis are not displayed and it's expected not to clip
clip: false,

// z can be set in data item, which is z2 actually.

// Disable progressive
Expand Down
13 changes: 13 additions & 0 deletions src/chart/bar/PictorialBarView.ts
Expand Up @@ -38,6 +38,7 @@ import { PathProps, PathStyleProps } from 'zrender/src/graphic/Path';
import { setLabelStyle, getLabelStatesModels } from '../../label/labelStyle';
import ZRImage from 'zrender/src/graphic/Image';
import { getECData } from '../../util/innerStore';
import { createClipPath } from '../helper/createClipPathFromCoordSys';

const BAR_BORDER_WIDTH_QUERY = ['itemStyle', 'borderWidth'] as const;

Expand Down Expand Up @@ -214,6 +215,17 @@ class PictorialBarView extends ChartView {
})
.execute();

// Do clipping
const clipPath = seriesModel.get('clip', true)
? createClipPath(seriesModel.coordinateSystem, false, seriesModel)
: null;
if (clipPath) {
group.setClipPath(clipPath);
}
else {
group.removeClipPath();
}

this._data = data;

return this.group;
Expand Down Expand Up @@ -915,6 +927,7 @@ function updateCommon(

const barPositionOutside = opt.valueDim.posDesc[+(symbolMeta.boundingLength > 0)];
const barRect = bar.__pictorialBarRect;
barRect.ignoreClip = true;

setLabelStyle(
barRect, getLabelStatesModels(itemModel),
Expand Down
101 changes: 101 additions & 0 deletions test/pictorial-single.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7731729

Please sign in to comment.