You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by "Pashted (via GitHub)" <gi...@apache.org> on 2023/12/23 23:58:08 UTC
[PR] feat(pie): 'itemRadiusScale' function added for pie series [echarts]
Pashted opened a new pull request, #19435:
URL: https://github.com/apache/echarts/pull/19435
<!-- Please fill in the following information to help us review your PR more efficiently. -->
## Brief Information
This pull request is in the type of:
- [ ] bug fixing
- [x] new feature
- [ ] others
### What does this PR do?
<!-- USE ONE SENTENCE TO DESCRIBE WHAT THIS PR DOES. -->
`itemRadiusScale` function added for pie series to control the radius of each item
### Fixed issues
<!--
- #xxxx: ...
-->
#19020
#15674
## Details
### Before: What was the problem?
<!-- DESCRIBE THE BUG OR REQUIREMENT HERE. -->
There was no easy option for pie charts to control the radius of items. In current version I can control either the whole pie radius or use some autocalculations with `roseType` option. But this is not suitable for our tasks. Earlier we used dashbords in PowerBI and the same feature in PBI looked like:
<!-- ADD SCREENSHOT HERE IF APPLICABLE. -->


### After: How does it behave after the fixing?
<!-- THE RESULT AFTER FIXING AND A SIMPLE EXPLANATION ABOUT HOW IT IS FIXED. -->
The solution is very similar with [scatter charts](https://echarts.apache.org/examples/en/editor.html?c=bubble-gradient) and its `symbolSize` option. Now (with this PR) i can pass custom function `itemRadiusScale`, which returns value from 0 to 1. That value is used within pie component to calculate outer radius for each item. In simple words, we now have a third dimension for each item, which means the size from center to the outer circle, almost like in scatter.
Also, few calculated values (sum, maxValue) passed into `getDataParams` callback to make tooltip calculations easier.
<!-- ADD SCREENSHOT HERE IF APPLICABLE. -->

## Document Info
One of the following should be checked.
- [ ] This PR doesn't relate to document changes
- [x] The document should be updated later
- [ ] The document changes have been made in apache/echarts-doc#xxx
## Misc
### ZRender Changes
- [ ] This PR depends on ZRender changes (ecomfe/zrender#xxx).
### Related test cases or examples to use the new APIs
`test/pie-itemRadiusScale.html`
here some content from the test file
https://github.com/apache/echarts/assets/16826622/2464bf2c-48d4-4f20-b84b-c3a7c18e73d9
## Others
### Merging options
- [x] Please squash the commits into a single one when merging.
### Other information
This is my first PR here. Sorry, if i violated the rules (=
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
Re: [PR] feat(pie): 'itemRadiusScale' function added for pie series [echarts]
Posted by "Pashted (via GitHub)" <gi...@apache.org>.
Pashted commented on PR #19435:
URL: https://github.com/apache/echarts/pull/19435#issuecomment-1881869962
@Ovilia, I added my solution for background option. It's based on `src/chart/bar/BarView.ts` component. Please, leave a feedback.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
Re: [PR] feat(pie): 'itemRadiusScale' function added for pie series [echarts]
Posted by "Ovilia (via GitHub)" <gi...@apache.org>.
Ovilia commented on PR #19435:
URL: https://github.com/apache/echarts/pull/19435#issuecomment-1869916297
> > This is a really fascinating feature and this PR is well-written! Thanks for your contribution. I like this feature but just want to make sure, can you give me a real world usage for this feature. #19020 is a good case but it only uses this feature when one bar is highlighted so it may not be convincing.
>
> Thanks for your time and so high evaluation of my work.
>
> This feature is called "cross selection" or "cross filtering" in Power BI. Using one vertical bar in some chart for cross selection is just a special case. There is almost no limitation about source of the filter. There may be an item from another pie chart (with different grouping settings), or rows/columns/cells from a table or any other custom component, or even selected cities/regions on the map. The targets of cross filtering are also may be different. In addition to pies, it can be columns (vertical or horizontal) or “stacked” areas on XY charts.
>
> There is some short [youtube tutorial](https://www.youtube.com/watch?app=desktop&v=nRTOHmqyhoo) about cross filtering in powerbi with demo.
>
> Also, employees in my company are often used such feature in PBI. On the next screenshot you can see a fragment from the real dashboard in PBI, where i selected few rows within the table 
Thanks for you explanation! This sounds reasonable and I'm looking forward to it!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
Re: [PR] feat(pie): 'itemRadiusScale' function added for pie series [echarts]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #19435:
URL: https://github.com/apache/echarts/pull/19435#issuecomment-4232757176
This PR has been automatically closed because it has not had recent activity. Sorry for that and we are looking forward to your next contribution.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
Re: [PR] feat(pie): 'itemRadiusScale' function added for pie series [echarts]
Posted by "Pashted (via GitHub)" <gi...@apache.org>.
Pashted commented on code in PR #19435:
URL: https://github.com/apache/echarts/pull/19435#discussion_r1436419534
##########
src/chart/pie/PieSeries.ts:
##########
@@ -107,6 +109,7 @@ export interface PieSeriesOption extends
type?: 'pie'
roseType?: 'radius' | 'area'
+ itemRadiusScale?: (dataParams: PieCallbackDataParams) => number
Review Comment:
`scalePercent`
`itemStyle.radius`
`itemStyle.scalePercent` (preferred)
also it would be an `itemStyle.scaleSize`. but I think (not 100% sure yet =), i will lose the ability to use nonlinear functions. becase percentages are calculated on the lib side in this case
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
Re: [PR] feat(pie): 'itemRadiusScale' function added for pie series [echarts]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #19435: feat(pie): 'itemRadiusScale' function added for pie series
URL: https://github.com/apache/echarts/pull/19435
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
Re: [PR] feat(pie): 'itemRadiusScale' function added for pie series [echarts]
Posted by "Pashted (via GitHub)" <gi...@apache.org>.
Pashted commented on code in PR #19435:
URL: https://github.com/apache/echarts/pull/19435#discussion_r1436419534
##########
src/chart/pie/PieSeries.ts:
##########
@@ -107,6 +109,7 @@ export interface PieSeriesOption extends
type?: 'pie'
roseType?: 'radius' | 'area'
+ itemRadiusScale?: (dataParams: PieCallbackDataParams) => number
Review Comment:
`scalePercent`
`itemStyle.radius`
`itemStyle.scalePercent`
also it would be an `itemStyle.scaleSize`. but I think (not 100% sure yet =), i will lose the ability to use nonlinear functions. becase percentages are calculated on lib side in this case
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
Re: [PR] feat(pie): 'itemRadiusScale' function added for pie series [echarts]
Posted by "Pashted (via GitHub)" <gi...@apache.org>.
Pashted commented on code in PR #19435:
URL: https://github.com/apache/echarts/pull/19435#discussion_r1436419534
##########
src/chart/pie/PieSeries.ts:
##########
@@ -107,6 +109,7 @@ export interface PieSeriesOption extends
type?: 'pie'
roseType?: 'radius' | 'area'
+ itemRadiusScale?: (dataParams: PieCallbackDataParams) => number
Review Comment:
`scalePercent`
`itemStyle.radius`
`itemStyle.scalePercent`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
Re: [PR] feat(pie): 'itemRadiusScale' function added for pie series [echarts]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #19435:
URL: https://github.com/apache/echarts/pull/19435#issuecomment-1868494640
<!-- ECHARTS_PR_PREVIEW -->
The changes brought by this PR can be previewed at: https://echarts.apache.org/examples/editor?version=PR-19435@0e29090
<!-- ECHARTS_PR_PREVIEW -->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
Re: [PR] feat(pie): 'itemRadiusScale' function added for pie series [echarts]
Posted by "Ovilia (via GitHub)" <gi...@apache.org>.
Ovilia commented on code in PR #19435:
URL: https://github.com/apache/echarts/pull/19435#discussion_r1436718492
##########
src/chart/pie/PieSeries.ts:
##########
@@ -107,6 +109,7 @@ export interface PieSeriesOption extends
type?: 'pie'
roseType?: 'radius' | 'area'
+ itemRadiusScale?: (dataParams: PieCallbackDataParams) => number
Review Comment:
I would personnally perfer `itemStyle.radiusPercent` to avoid using `scaleXXX`, but not with very strong preference. If only `itemStyle.xxx` is used but no `series.xxx`, I think we should skip the callback function.
In ECharts, for options support both value and percentage form (like [radius](https://echarts.apache.org/zh/option.html#series-pie.radius), we usually use strings like `'30%'` to represent percentage. But since we don't support number type in our case, I think a 0-1 number type is acceptable.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
Re: [PR] feat(pie): 'itemRadiusScale' function added for pie series [echarts]
Posted by "Pashted (via GitHub)" <gi...@apache.org>.
Pashted commented on PR #19435:
URL: https://github.com/apache/echarts/pull/19435#issuecomment-1868426952
about tests... i selected 5.4.4-dev.20231116 as expected version while running them, because i found something similar in package.json. other versions have more errors in result.
some tests not working, cause of baidu connectivity issues with my network.

some just not working. i dont know why - they are not related with this PR.

testing from the console was completley failed - all tests run in parallel and i stuck in out of memory isssues
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
Re: [PR] feat(pie): 'itemRadiusScale' function added for pie series [echarts]
Posted by "Ovilia (via GitHub)" <gi...@apache.org>.
Ovilia commented on code in PR #19435:
URL: https://github.com/apache/echarts/pull/19435#discussion_r1452067343
##########
src/chart/pie/PieSeries.ts:
##########
@@ -299,6 +318,11 @@ class PieSeriesModel extends SeriesModel<PieSeriesOption> {
opacity: 1
},
+ showBackground: false,
+ backgroundStyle: {
+ opacity: 1
Review Comment:
Setting `opacity: 1` by default is confusing and unconvenient. How about make it 0.25 by default?
##########
src/chart/pie/PieView.ts:
##########
@@ -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();
Review Comment:
If `data.backgroundStyle` is not supported, how should developers set each pie piece to be a different color other than the default colors? I would suggest supporting `data.backgroundStyle` but not `data.showBackground` (only `series.showBackground` is supported).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
Re: [PR] feat(pie): 'itemRadiusScale' function added for pie series [echarts]
Posted by "Ovilia (via GitHub)" <gi...@apache.org>.
Ovilia commented on code in PR #19435:
URL: https://github.com/apache/echarts/pull/19435#discussion_r1436720039
##########
test/pie-itemRadiusScale.html:
##########
@@ -0,0 +1,291 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<html>
+<head>
+ <meta charset="utf-8">
+ <script src="lib/simpleRequire.js"></script>
+ <script src="lib/config.js"></script>
+ <style>
+ body {
+ margin: 0;
+ }
+
+ #main {
+ width: 100%;
+ height: 92%;
+ }
+
+ p {
+ text-align: center;
+ }
+
+ button {
+ padding: 5px 15px;
+ background: lightgray;
+ cursor: pointer;
+ }
+
+ button:hover {
+ background: transparent;
+ }
+ </style>
+</head>
+<body>
+<p>
+ <button type="button"
+ onclick="selectRandomValues()">
+ Random selection
+ </button>
+</p>
+<div id="main"></div>
+<script>
+ let dataset = {
+ dimensions: ['key', 'value', 'selected'],
+ source: [
+ ['A', 1092, 112],
+ ['B', 768, 499],
+ ['C', 604, 257],
+ ['D', 238, 180]
+ ],
+ };
+
+ function selectRandomValues() {
+ dataset.source.forEach(row => {
+ row[2] = row[1] * Math.random();
+ });
+ chart.setOption({dataset});
+ }
+
+
+ function itemScale(params) {
+ const {data = []} = params;
+ return data[2] / data[1];
+ }
+
+ function itemScaleQuadratic(params) {
+ const {value, encode} = params;
+ const val = value[encode.value?.[0]];
+ const selected = value[encode.value?.[1]];
+ const scale = selected / val;
+ return Math.pow(scale, 1 / 2);
+ }
+
+ function itemScaleCubic(params) {
+ const {value, encode} = params;
+ const val = value[encode.value?.[0]];
+ const selected = value[encode.value?.[1]];
+ const scale = selected / val;
+ return Math.pow(scale, 1 / 3);
+ }
+
+ let chart;
+
+ require([
+ 'echarts'
+ ], function (echarts) {
+ chart = echarts.init(document.getElementById('main'), null, {});
+
+ chart.setOption({
+ legend: {
+ itemStyle: {
+ opacity: 1
+ }
+ },
+ tooltip: {trigger: 'item'},
+ dataset: dataset,
+ title: [
+ createTitle([1, 1], 'default'),
+ createTitle([1, 2], 'extra pie as background'),
+ createTitle([1, 3], 'donut style'),
+ createTitle([2, 1], 'cubic scale'),
+ createTitle([2, 2], 'quadratic scale'),
+ createTitle([2, 3], 'quadratic scale + donut style'),
+ ],
+ series: [
+ /** example #1: scaling based on a simple function */
+ createScaledSeries(
+ [1, 1],
+ {},
+ itemScale
+ ),
+
+ /** example #2: add pie with the same angles,
+ * but full radius and semitransparent background */
+ createBackgroundSeries([1, 2]),
Review Comment:
Yes, I would slighter prefer to callback than under `itemStyle` because users don't have to write multiple times. Another option could be, `series-pie.backgroundStyle.color` has a default value `'auto'` meaning use color of each piece. [series-pie.colorBy](https://echarts.apache.org/en/option.html#series-pie.colorBy) is `'series'` by default, so it's intuitively OK for the background to use the color of each piece.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
Re: [PR] feat(pie): 'itemRadiusScale' function added for pie series [echarts]
Posted by "Pashted (via GitHub)" <gi...@apache.org>.
Pashted commented on code in PR #19435:
URL: https://github.com/apache/echarts/pull/19435#discussion_r1436419534
##########
src/chart/pie/PieSeries.ts:
##########
@@ -107,6 +109,7 @@ export interface PieSeriesOption extends
type?: 'pie'
roseType?: 'radius' | 'area'
+ itemRadiusScale?: (dataParams: PieCallbackDataParams) => number
Review Comment:
`scalePercent`
`itemStyle.radius`
`itemStyle.scalePercent` (preferred)
also it would be an `itemStyle.scaleSize`. but I think (not 100% sure yet =), i will lose the ability to use nonlinear functions. because percentages are calculated on the lib side in this case
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
Re: [PR] feat(pie): 'itemRadiusScale' function added for pie series [echarts]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #19435:
URL: https://github.com/apache/echarts/pull/19435#issuecomment-4189535485
This PR has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. If you wish not to mark it as stale, please leave a comment in this PR. We are sorry for this but 2 years is a long time and the code base has been changed a lot. Thanks for your contribution anyway.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
Re: [PR] feat(pie): 'itemRadiusScale' function added for pie series [echarts]
Posted by "Pashted (via GitHub)" <gi...@apache.org>.
Pashted commented on code in PR #19435:
URL: https://github.com/apache/echarts/pull/19435#discussion_r1436419534
##########
src/chart/pie/PieSeries.ts:
##########
@@ -107,6 +109,7 @@ export interface PieSeriesOption extends
type?: 'pie'
roseType?: 'radius' | 'area'
+ itemRadiusScale?: (dataParams: PieCallbackDataParams) => number
Review Comment:
`scalePercent`
`itemStyle.radius`
`itemStyle.scalePercent` (preferred)
also it would be an `itemStyle.scaleSize`. but I think (not 100% sure yet =), i will lose the ability to use nonlinear functions. becase percentages are calculated on lib side in this case
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
Re: [PR] feat(pie): 'itemRadiusScale' function added for pie series [echarts]
Posted by "Pashted (via GitHub)" <gi...@apache.org>.
Pashted commented on code in PR #19435:
URL: https://github.com/apache/echarts/pull/19435#discussion_r1436419534
##########
src/chart/pie/PieSeries.ts:
##########
@@ -107,6 +109,7 @@ export interface PieSeriesOption extends
type?: 'pie'
roseType?: 'radius' | 'area'
+ itemRadiusScale?: (dataParams: PieCallbackDataParams) => number
Review Comment:
`scalePercent`
`itemStyle.radius`
`itemStyle.scalePercent`
also it would be an `itemStyle.scaleSize`. but I lose the ability to use nonlinear functions. becase percentages are calculated on lib side in this case
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
Re: [PR] feat(pie): 'itemRadiusScale' function added for pie series [echarts]
Posted by "Pashted (via GitHub)" <gi...@apache.org>.
Pashted commented on PR #19435:
URL: https://github.com/apache/echarts/pull/19435#issuecomment-1869460122
> This is a really fascinating feature and this PR is well-written! Thanks for your contribution. I like this feature but just want to make sure, can you give me a real world usage for this feature. #19020 is a good case but it only uses this feature when one bar is highlighted so it may not be convincing.
Thanks for your time and so high evaluation of my work.
This feature is called "cross selection" or "cross filtering" in Power BI. Using one vertical bar in some chart for cross selection is just a special case. There is almost no limitation about source of the filter. There may be an item from another pie chart (with different grouping settings), or rows/columns/cells from a table or any other custom component, or even selected cities/regions on the map. The targets of cross filtering are also may be defferent. In addition to pies, it can be columns (vertical or horizontal) or “stacked” areas on XY charts.
There is some short [youtube tutorial](https://www.youtube.com/watch?app=desktop&v=nRTOHmqyhoo) about cross filtering in powerbi with demo.
Also, employees in my company are often used such feature in PBI. On the next screenshot you can see a fragment from the real dashboard in PBI, where i selected few rows within the table

--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
Re: [PR] feat(pie): 'itemRadiusScale' function added for pie series [echarts]
Posted by "Ovilia (via GitHub)" <gi...@apache.org>.
Ovilia commented on PR #19435:
URL: https://github.com/apache/echarts/pull/19435#issuecomment-1891600914
Please merge from the latest `master` branck to solve the lint problem.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
Re: [PR] feat(pie): 'itemRadiusScale' function added for pie series [echarts]
Posted by "echarts-bot[bot] (via GitHub)" <gi...@apache.org>.
echarts-bot[bot] commented on PR #19435:
URL: https://github.com/apache/echarts/pull/19435#issuecomment-1868392187
Thanks for your contribution!
The community will review it ASAP. In the meanwhile, please checkout [the coding standard](https://echarts.apache.org/en/coding-standard.html) and Wiki about [How to make a pull request](https://github.com/apache/echarts/wiki/How-to-make-a-pull-request).
Document changes are required in this PR. Please also make a PR to [apache/echarts-doc](https://github.com/apache/echarts-doc) for document changes and update the issue id in the PR description. When the doc PR is merged, the maintainers will remove the `PR: awaiting doc` label.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
Re: [PR] feat(pie): 'itemRadiusScale' function added for pie series [echarts]
Posted by "Ovilia (via GitHub)" <gi...@apache.org>.
Ovilia commented on code in PR #19435:
URL: https://github.com/apache/echarts/pull/19435#discussion_r1436346552
##########
src/chart/pie/PieSeries.ts:
##########
@@ -54,6 +54,8 @@ interface PieItemStyleOption<TCbParams = never> extends ItemStyleOption<TCbParam
export interface PieCallbackDataParams extends CallbackDataParams {
percent: number
+ maxValue?: number
Review Comment:
How about `max` for simplicity?
##########
src/chart/pie/PieSeries.ts:
##########
@@ -107,6 +109,7 @@ export interface PieSeriesOption extends
type?: 'pie'
roseType?: 'radius' | 'area'
+ itemRadiusScale?: (dataParams: PieCallbackDataParams) => number
Review Comment:
I would suggest considering another name than `radius` because it may cause confusion with [emphasis.scaleSize](https://echarts.apache.org/en/option.html#series-pie.emphasis.scaleSize), which is the enlarging animation when emphasizing. You are welcomed to suggest a new name.
##########
test/pie-itemRadiusScale.html:
##########
@@ -0,0 +1,291 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<html>
+<head>
+ <meta charset="utf-8">
+ <script src="lib/simpleRequire.js"></script>
+ <script src="lib/config.js"></script>
+ <style>
+ body {
+ margin: 0;
+ }
+
+ #main {
+ width: 100%;
+ height: 92%;
+ }
+
+ p {
+ text-align: center;
+ }
+
+ button {
+ padding: 5px 15px;
+ background: lightgray;
+ cursor: pointer;
+ }
+
+ button:hover {
+ background: transparent;
+ }
+ </style>
+</head>
+<body>
+<p>
+ <button type="button"
+ onclick="selectRandomValues()">
+ Random selection
+ </button>
+</p>
+<div id="main"></div>
+<script>
+ let dataset = {
+ dimensions: ['key', 'value', 'selected'],
+ source: [
+ ['A', 1092, 112],
+ ['B', 768, 499],
+ ['C', 604, 257],
+ ['D', 238, 180]
+ ],
+ };
+
+ function selectRandomValues() {
+ dataset.source.forEach(row => {
+ row[2] = row[1] * Math.random();
+ });
+ chart.setOption({dataset});
+ }
+
+
+ function itemScale(params) {
+ const {data = []} = params;
+ return data[2] / data[1];
+ }
+
+ function itemScaleQuadratic(params) {
+ const {value, encode} = params;
+ const val = value[encode.value?.[0]];
+ const selected = value[encode.value?.[1]];
+ const scale = selected / val;
+ return Math.pow(scale, 1 / 2);
+ }
+
+ function itemScaleCubic(params) {
+ const {value, encode} = params;
+ const val = value[encode.value?.[0]];
+ const selected = value[encode.value?.[1]];
+ const scale = selected / val;
+ return Math.pow(scale, 1 / 3);
+ }
+
+ let chart;
+
+ require([
+ 'echarts'
+ ], function (echarts) {
+ chart = echarts.init(document.getElementById('main'), null, {});
+
+ chart.setOption({
+ legend: {
+ itemStyle: {
+ opacity: 1
+ }
+ },
+ tooltip: {trigger: 'item'},
+ dataset: dataset,
+ title: [
+ createTitle([1, 1], 'default'),
+ createTitle([1, 2], 'extra pie as background'),
+ createTitle([1, 3], 'donut style'),
+ createTitle([2, 1], 'cubic scale'),
+ createTitle([2, 2], 'quadratic scale'),
+ createTitle([2, 3], 'quadratic scale + donut style'),
+ ],
+ series: [
+ /** example #1: scaling based on a simple function */
+ createScaledSeries(
+ [1, 1],
+ {},
+ itemScale
+ ),
+
+ /** example #2: add pie with the same angles,
+ * but full radius and semitransparent background */
+ createBackgroundSeries([1, 2]),
Review Comment:
I would suggest providing two new options `series-pie.backgroundStyle` and `series-pie.backgroundStyle` like [series-bar.showBackground](https://echarts.apache.org/en/option.html#series-bar.showBackground) and [series-bar.backgroundStyle](https://echarts.apache.org/en/option.html#series-bar.backgroundStyle), where `series-pie.backgroundStyle.color` can be a callback function so that developers can set the background according to the piece color.
##########
test/pie-itemRadiusScale.html:
##########
@@ -0,0 +1,291 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<html>
+<head>
+ <meta charset="utf-8">
+ <script src="lib/simpleRequire.js"></script>
+ <script src="lib/config.js"></script>
+ <style>
+ body {
+ margin: 0;
+ }
+
+ #main {
+ width: 100%;
+ height: 92%;
+ }
+
+ p {
+ text-align: center;
+ }
+
+ button {
+ padding: 5px 15px;
+ background: lightgray;
+ cursor: pointer;
+ }
+
+ button:hover {
+ background: transparent;
+ }
+ </style>
+</head>
+<body>
+<p>
+ <button type="button"
+ onclick="selectRandomValues()">
+ Random selection
+ </button>
+</p>
+<div id="main"></div>
+<script>
+ let dataset = {
+ dimensions: ['key', 'value', 'selected'],
+ source: [
+ ['A', 1092, 112],
+ ['B', 768, 499],
+ ['C', 604, 257],
+ ['D', 238, 180]
+ ],
+ };
+
+ function selectRandomValues() {
+ dataset.source.forEach(row => {
+ row[2] = row[1] * Math.random();
+ });
+ chart.setOption({dataset});
+ }
+
+
+ function itemScale(params) {
+ const {data = []} = params;
+ return data[2] / data[1];
+ }
+
+ function itemScaleQuadratic(params) {
+ const {value, encode} = params;
+ const val = value[encode.value?.[0]];
+ const selected = value[encode.value?.[1]];
+ const scale = selected / val;
+ return Math.pow(scale, 1 / 2);
+ }
+
+ function itemScaleCubic(params) {
+ const {value, encode} = params;
+ const val = value[encode.value?.[0]];
+ const selected = value[encode.value?.[1]];
+ const scale = selected / val;
+ return Math.pow(scale, 1 / 3);
+ }
+
+ let chart;
+
+ require([
+ 'echarts'
+ ], function (echarts) {
+ chart = echarts.init(document.getElementById('main'), null, {});
+
+ chart.setOption({
+ legend: {
+ itemStyle: {
+ opacity: 1
+ }
+ },
+ tooltip: {trigger: 'item'},
+ dataset: dataset,
+ title: [
+ createTitle([1, 1], 'default'),
+ createTitle([1, 2], 'extra pie as background'),
+ createTitle([1, 3], 'donut style'),
+ createTitle([2, 1], 'cubic scale'),
+ createTitle([2, 2], 'quadratic scale'),
+ createTitle([2, 3], 'quadratic scale + donut style'),
+ ],
+ series: [
+ /** example #1: scaling based on a simple function */
+ createScaledSeries(
+ [1, 1],
+ {},
+ itemScale
+ ),
+
+ /** example #2: add pie with the same angles,
+ * but full radius and semitransparent background */
+ createBackgroundSeries([1, 2]),
+ createScaledSeries(
+ [1, 2],
+ {},
+ itemScale
+ ),
+
+ /** example #3: add donut with the same angles,
+ * but full outer radius and semitransparent background */
+ createBackgroundSeries(
+ [1, 3],
+ {radius: ['13%', '22%']}
+ ),
+ createScaledSeries(
+ [1, 3],
+ {radius: ['13%', '22%']},
+ itemScale
+ ),
+
+ /** example #4: almost the same as examples #2,
+ * but non-linear function used */
+ createBackgroundSeries([2, 1]),
+ createScaledSeries(
+ [2, 1],
+ {encode: ['value', 'selected']},
+ itemScaleCubic
+ ),
+
+ /** example #5: almost the same as examples #2,
+ * but non-linear function used */
+ createBackgroundSeries([2, 2]),
+ createScaledSeries(
+ [2, 2],
+ {encode: ['value', 'selected']},
+ itemScaleQuadratic
+ ),
+
+ /** example #6: almost the same as examples #3,
+ * but non-linear function used */
+ createBackgroundSeries(
+ [2, 3],
+ {radius: ['13%', '22%']}
+ ),
+ createScaledSeries(
+ [2, 3],
+ {
+ radius: ['13%', '22%'],
+ encode: ['value', 'selected']
+ },
+ itemScaleQuadratic
+ ),
+ ]
+ });
+
+ function createTitle(pos, text) {
+ return {
+ subtext: text,
+ textAlign: 'center',
+ left: `${(pos[1] / 3 - 1 / 6) * 100}%`,
+ top: `${(pos[0] - 1) * 50 + 6}%`
+ };
+ }
+
+ /**
+ * @param pos {number[]}
+ * @param [radius] {string[]|number[]}
+ * @param [encode] {string|string[]}
+ * @param itemRadiusScale {function}
+ * @return {*}
+ */
+ function createScaledSeries(pos, {radius, encode = 'value'} = {}, itemRadiusScale) {
+ return {
+ name: `Selected ${encode instanceof Array ? encode[0] : encode}`,
+ type: 'pie',
+ center: [
+ `${(pos[1] / 3 - 1 / 6) * 100}%`,
+ `${(pos[0] - 1) * 50 + 25}%`,
+ ],
+ radius: radius || '22%',
+ z: 10,
+ emphasis: {disabled: true},
Review Comment:
If `backgroundStyle` is provided, then there should be no need to disable emphasis.
##########
test/pie-itemRadiusScale.html:
##########
@@ -0,0 +1,291 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<html>
+<head>
+ <meta charset="utf-8">
+ <script src="lib/simpleRequire.js"></script>
+ <script src="lib/config.js"></script>
+ <style>
+ body {
+ margin: 0;
+ }
+
+ #main {
+ width: 100%;
+ height: 92%;
+ }
+
+ p {
+ text-align: center;
+ }
+
+ button {
+ padding: 5px 15px;
+ background: lightgray;
+ cursor: pointer;
+ }
+
+ button:hover {
+ background: transparent;
+ }
+ </style>
+</head>
+<body>
+<p>
+ <button type="button"
+ onclick="selectRandomValues()">
+ Random selection
+ </button>
+</p>
+<div id="main"></div>
+<script>
+ let dataset = {
+ dimensions: ['key', 'value', 'selected'],
+ source: [
+ ['A', 1092, 112],
+ ['B', 768, 499],
+ ['C', 604, 257],
+ ['D', 238, 180]
+ ],
+ };
+
+ function selectRandomValues() {
+ dataset.source.forEach(row => {
+ row[2] = row[1] * Math.random();
+ });
+ chart.setOption({dataset});
+ }
+
+
+ function itemScale(params) {
+ const {data = []} = params;
+ return data[2] / data[1];
+ }
+
+ function itemScaleQuadratic(params) {
+ const {value, encode} = params;
+ const val = value[encode.value?.[0]];
+ const selected = value[encode.value?.[1]];
+ const scale = selected / val;
+ return Math.pow(scale, 1 / 2);
+ }
+
+ function itemScaleCubic(params) {
+ const {value, encode} = params;
+ const val = value[encode.value?.[0]];
+ const selected = value[encode.value?.[1]];
+ const scale = selected / val;
+ return Math.pow(scale, 1 / 3);
+ }
+
+ let chart;
+
+ require([
+ 'echarts'
+ ], function (echarts) {
+ chart = echarts.init(document.getElementById('main'), null, {});
+
+ chart.setOption({
+ legend: {
+ itemStyle: {
+ opacity: 1
+ }
+ },
+ tooltip: {trigger: 'item'},
+ dataset: dataset,
+ title: [
+ createTitle([1, 1], 'default'),
+ createTitle([1, 2], 'extra pie as background'),
+ createTitle([1, 3], 'donut style'),
+ createTitle([2, 1], 'cubic scale'),
+ createTitle([2, 2], 'quadratic scale'),
+ createTitle([2, 3], 'quadratic scale + donut style'),
+ ],
+ series: [
+ /** example #1: scaling based on a simple function */
+ createScaledSeries(
+ [1, 1],
+ {},
+ itemScale
+ ),
+
+ /** example #2: add pie with the same angles,
+ * but full radius and semitransparent background */
+ createBackgroundSeries([1, 2]),
Review Comment:
You make make a seperate PR (or just in this if you like) for the background related feature because it also benifits the roseType pies.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
Re: [PR] feat(pie): 'itemRadiusScale' function added for pie series [echarts]
Posted by "Pashted (via GitHub)" <gi...@apache.org>.
Pashted commented on code in PR #19435:
URL: https://github.com/apache/echarts/pull/19435#discussion_r1436429361
##########
test/pie-itemRadiusScale.html:
##########
@@ -0,0 +1,291 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<html>
+<head>
+ <meta charset="utf-8">
+ <script src="lib/simpleRequire.js"></script>
+ <script src="lib/config.js"></script>
+ <style>
+ body {
+ margin: 0;
+ }
+
+ #main {
+ width: 100%;
+ height: 92%;
+ }
+
+ p {
+ text-align: center;
+ }
+
+ button {
+ padding: 5px 15px;
+ background: lightgray;
+ cursor: pointer;
+ }
+
+ button:hover {
+ background: transparent;
+ }
+ </style>
+</head>
+<body>
+<p>
+ <button type="button"
+ onclick="selectRandomValues()">
+ Random selection
+ </button>
+</p>
+<div id="main"></div>
+<script>
+ let dataset = {
+ dimensions: ['key', 'value', 'selected'],
+ source: [
+ ['A', 1092, 112],
+ ['B', 768, 499],
+ ['C', 604, 257],
+ ['D', 238, 180]
+ ],
+ };
+
+ function selectRandomValues() {
+ dataset.source.forEach(row => {
+ row[2] = row[1] * Math.random();
+ });
+ chart.setOption({dataset});
+ }
+
+
+ function itemScale(params) {
+ const {data = []} = params;
+ return data[2] / data[1];
+ }
+
+ function itemScaleQuadratic(params) {
+ const {value, encode} = params;
+ const val = value[encode.value?.[0]];
+ const selected = value[encode.value?.[1]];
+ const scale = selected / val;
+ return Math.pow(scale, 1 / 2);
+ }
+
+ function itemScaleCubic(params) {
+ const {value, encode} = params;
+ const val = value[encode.value?.[0]];
+ const selected = value[encode.value?.[1]];
+ const scale = selected / val;
+ return Math.pow(scale, 1 / 3);
+ }
+
+ let chart;
+
+ require([
+ 'echarts'
+ ], function (echarts) {
+ chart = echarts.init(document.getElementById('main'), null, {});
+
+ chart.setOption({
+ legend: {
+ itemStyle: {
+ opacity: 1
+ }
+ },
+ tooltip: {trigger: 'item'},
+ dataset: dataset,
+ title: [
+ createTitle([1, 1], 'default'),
+ createTitle([1, 2], 'extra pie as background'),
+ createTitle([1, 3], 'donut style'),
+ createTitle([2, 1], 'cubic scale'),
+ createTitle([2, 2], 'quadratic scale'),
+ createTitle([2, 3], 'quadratic scale + donut style'),
+ ],
+ series: [
+ /** example #1: scaling based on a simple function */
+ createScaledSeries(
+ [1, 1],
+ {},
+ itemScale
+ ),
+
+ /** example #2: add pie with the same angles,
+ * but full radius and semitransparent background */
+ createBackgroundSeries([1, 2]),
Review Comment:
Intuitively, it seems that the background style in the series root will be applied to the entire pie. it's not obvious that the function is called on every element. If I'm trying to intuitively understand property names, then it seems more logical for me to put the style of the elements into itemStyle. Like `series-pie.itemStyle.backgroundStyle.color`.
But this entry `series-pie.backgroundStyle.opacity` with a numeric type rather than a function seems clear to me. This tells me that transparency will work the same on all elements
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org