-
Notifications
You must be signed in to change notification settings - Fork 19.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(pie): 'itemRadiusScale' function added for pie series #19435
Open
Pashted
wants to merge
6
commits into
apache:master
Choose a base branch
from
Pashted:fix-19020
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c711f3a
feat(pie): 'itemRadiusScale' function added for pie series to control…
Pashted 0e29090
following the apache coding standard
Pashted a9eed59
maxValue, itemRadiusScale, pie-itemRadiusScale.html renamed.
Pashted 1f544cc
backgroundStyle option added.
Pashted 921cb9a
createBackgroundSeries function removed from the test file.
Pashted a0db5b4
use zrUtil for radiusPercent type recognition
Pashted File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,13 +19,14 @@ | |
*/ | ||
|
||
|
||
import { extend, retrieve3 } from 'zrender/src/core/util'; | ||
import { extend, defaults, retrieve3 } from 'zrender/src/core/util'; | ||
import * as graphic from '../../util/graphic'; | ||
import { setStatesStylesFromModel, toggleHoverEmphasis } from '../../util/states'; | ||
import ChartView from '../../view/Chart'; | ||
import GlobalModel from '../../model/Global'; | ||
import ExtensionAPI from '../../core/ExtensionAPI'; | ||
import { Payload, ColorString } from '../../util/types'; | ||
import {SectorProps} from 'zrender/src/graphic/shape/Sector'; | ||
import SeriesData from '../../data/SeriesData'; | ||
import PieSeriesModel, {PieDataItemOption} from './PieSeries'; | ||
import labelLayout from './labelLayout'; | ||
|
@@ -236,6 +237,9 @@ class PieView extends ChartView { | |
private _data: SeriesData; | ||
private _emptyCircleSector: graphic.Sector; | ||
|
||
private _backgroundGroup: graphic.Group; | ||
private _backgroundEls: graphic.Sector[] = []; | ||
|
||
render(seriesModel: PieSeriesModel, ecModel: GlobalModel, api: ExtensionAPI, payload: Payload): void { | ||
const data = seriesModel.getData(); | ||
|
||
|
@@ -268,12 +272,43 @@ class PieView extends ChartView { | |
group.add(sector); | ||
} | ||
|
||
|
||
const animationModel = seriesModel.isAnimationEnabled() ? seriesModel : null; | ||
const drawBackground = seriesModel.get('showBackground', true); | ||
const basicOuterRadius = getBasicPieLayout(seriesModel, api).r; | ||
const bgStyle = seriesModel.getModel('backgroundStyle').getItemStyle(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If |
||
|
||
const bgEls: PieView['_backgroundEls'] = []; | ||
const existBgEls = this._backgroundEls; | ||
|
||
function createBackground(idx: number) { | ||
const bgEl = new graphic.Sector({ | ||
shape: data.getItemLayout(idx), | ||
silent: true, | ||
z2: 0 | ||
}); | ||
bgEl.setShape('r', basicOuterRadius); | ||
|
||
const style = data.getItemVisual(idx, 'style'); | ||
const visualColor = style && style.fill as ColorString; | ||
bgEl.useStyle(extend( | ||
// inherit item color if no background color specified | ||
{fill: visualColor}, | ||
bgStyle | ||
)); | ||
return bgEl; | ||
} | ||
|
||
data.diff(oldData) | ||
.add(function (idx) { | ||
const piePiece = new PiePiece(data, idx, startAngle); | ||
|
||
data.setItemGraphicEl(idx, piePiece); | ||
|
||
if (drawBackground) { | ||
bgEls[idx] = createBackground(idx); | ||
} | ||
|
||
group.add(piePiece); | ||
}) | ||
.update(function (newIdx, oldIdx) { | ||
|
@@ -283,6 +318,15 @@ class PieView extends ChartView { | |
|
||
piePiece.off('click'); | ||
|
||
if (drawBackground) { | ||
bgEls[newIdx] = existBgEls[oldIdx] || createBackground(newIdx); | ||
const shape = defaults( | ||
{r: basicOuterRadius}, | ||
data.getItemLayout(newIdx) | ||
); | ||
graphic.updateProps<SectorProps>(bgEls[newIdx], {shape}, animationModel, newIdx); | ||
} | ||
|
||
group.add(piePiece); | ||
data.setItemGraphicEl(newIdx, piePiece); | ||
}) | ||
|
@@ -292,6 +336,15 @@ class PieView extends ChartView { | |
}) | ||
.execute(); | ||
|
||
this._backgroundGroup ||= new graphic.Group(); | ||
this._backgroundGroup.removeAll(); | ||
|
||
for (const bgEl of bgEls) { | ||
this._backgroundGroup.add(bgEl); | ||
} | ||
group.add(this._backgroundGroup); | ||
this._backgroundEls = bgEls; | ||
|
||
labelLayout(seriesModel); | ||
|
||
// Always use initial animation. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting
opacity: 1
by default is confusing and unconvenient. How about make it 0.25 by default?