From a40d34307d92789c4620cbc8e573523f08770617 Mon Sep 17 00:00:00 2001 From: pahans Date: Fri, 20 Mar 2020 20:10:46 +0530 Subject: [PATCH 1/3] Summarize pie charts when slices count is high --- .../src/ApiAvailability.jsx | 2 +- .../APIMAppApiUsage/src/APIMAppApiUsage.jsx | 59 ++++++------------- .../src/APIMRegisteredAppUsers.jsx | 34 +++++------ .../src/APIMTopApiCreators.jsx | 32 +++++----- .../src/APIMTopAppCreators.jsx | 33 +++++------ .../APIMTopAppUsers/src/APIMTopAppUsers.jsx | 33 ++++++----- .../src/APIMTopFaultyApis.jsx | 37 ++++++------ .../APIMTopPlatforms/src/APIMTopPlatforms.jsx | 33 ++++++----- .../src/APIMTopSubscribers.jsx | 32 +++++----- .../src/APIMTopThrottledApis.jsx | 33 ++++++----- .../APIMTopUserAgents/src/APIMTopAgents.jsx | 31 +++++----- .../CommonLib/src/Utils.js | 46 +++++++++++++++ .../CommonLib/src/index.js | 4 +- 13 files changed, 219 insertions(+), 190 deletions(-) create mode 100644 components/org.wso2.analytics.apim.widgets/CommonLib/src/Utils.js diff --git a/components/org.wso2.analytics.apim.widgets/APIMApiAvailability/src/ApiAvailability.jsx b/components/org.wso2.analytics.apim.widgets/APIMApiAvailability/src/ApiAvailability.jsx index 591b2ffba..a863e01a6 100644 --- a/components/org.wso2.analytics.apim.widgets/APIMApiAvailability/src/ApiAvailability.jsx +++ b/components/org.wso2.analytics.apim.widgets/APIMApiAvailability/src/ApiAvailability.jsx @@ -22,7 +22,7 @@ import PropTypes from 'prop-types'; import { VictoryPie, VictoryLegend, VictoryTooltip, VictoryTheme, VictoryContainer, } from 'victory'; -import { colorScale } from '@analytics-apim/common-lib'; +import { colorScale, Utils } from '@analytics-apim/common-lib'; import sumBy from 'lodash/sumBy'; /** diff --git a/components/org.wso2.analytics.apim.widgets/APIMAppApiUsage/src/APIMAppApiUsage.jsx b/components/org.wso2.analytics.apim.widgets/APIMAppApiUsage/src/APIMAppApiUsage.jsx index 6b8bda780..79dab8846 100644 --- a/components/org.wso2.analytics.apim.widgets/APIMAppApiUsage/src/APIMAppApiUsage.jsx +++ b/components/org.wso2.analytics.apim.widgets/APIMAppApiUsage/src/APIMAppApiUsage.jsx @@ -34,6 +34,7 @@ import sumBy from 'lodash/sumBy'; import { VictoryPie, VictoryLegend, VictoryTooltip, VictoryTheme, } from 'victory'; +import { colorScale, Utils } from '@analytics-apim/common-lib'; import CustomTable from './CustomTable'; /** @@ -43,7 +44,7 @@ import CustomTable from './CustomTable'; */ export default function APIMAppApiUsage(props) { const { - themeName, height, width, limit, applicationSelected, usageData, legendData, applicationList, + themeName, height, width, limit, applicationSelected, usageData, applicationList, applicationSelectedHandleChange, handleLimitChange, inProgress, } = props; const fontSize = width < 1000 ? 25 : 18; @@ -140,6 +141,7 @@ export default function APIMAppApiUsage(props) { }, }; + const { pieChartData, legendData } = Utils.summarizePieData(usageData, 'apiName', 'hits'); return (
+ d.apiName} y={d => d.hits} labels={d => `${d.apiName} : ${((d.hits - / (sumBy(usageData, o => o.hits))) * 100).toFixed(2)}%`} - /> - o.hits))) * 100).toFixed(2)}%`} />
@@ -342,7 +318,6 @@ APIMAppApiUsage.propTypes = { applicationSelected: PropTypes.number.isRequired, applicationList: PropTypes.instanceOf(Object).isRequired, usageData: PropTypes.instanceOf(Object).isRequired, - legendData: PropTypes.instanceOf(Object).isRequired, applicationSelectedHandleChange: PropTypes.func.isRequired, handleLimitChange: PropTypes.func.isRequired, inProgress: PropTypes.bool.isRequired, diff --git a/components/org.wso2.analytics.apim.widgets/APIMRegisteredAppUsers/src/APIMRegisteredAppUsers.jsx b/components/org.wso2.analytics.apim.widgets/APIMRegisteredAppUsers/src/APIMRegisteredAppUsers.jsx index d3f386cb7..4d11b234d 100644 --- a/components/org.wso2.analytics.apim.widgets/APIMRegisteredAppUsers/src/APIMRegisteredAppUsers.jsx +++ b/components/org.wso2.analytics.apim.widgets/APIMRegisteredAppUsers/src/APIMRegisteredAppUsers.jsx @@ -28,7 +28,7 @@ import sumBy from 'lodash/sumBy'; import { VictoryPie, VictoryLegend, VictoryTooltip, VictoryTheme, } from 'victory'; -import { colorScale } from '@analytics-apim/common-lib'; +import { colorScale, Utils } from '@analytics-apim/common-lib'; import CustomTable from './CustomTable'; /** @@ -38,7 +38,7 @@ import CustomTable from './CustomTable'; */ export default function APIMRegisteredAppUsers(props) { const { - themeName, height, width, usageData, legendData, inProgress, + themeName, height, width, usageData = [], inProgress, } = props; const fontSize = width < 1000 ? 25 : 18; const styles = { @@ -110,6 +110,7 @@ export default function APIMRegisteredAppUsers(props) { strokeWidth: 1, }, }; + const { pieChartData, legendData } = Utils.summarizePieData(usageData, 'applicationName', 'users'); return ( ) : (
- {usageData.length > 0 ? ( + {pieChartData.length > 0 ? (
+ d.applicationName} y={d => d.users} labels={d => `${d.applicationName} : ${((d.users - / (sumBy(usageData, o => o.users))) * 100).toFixed(2)}%`} - /> - o.users))) * 100).toFixed(2)}%`} />
@@ -210,6 +211,5 @@ APIMRegisteredAppUsers.propTypes = { height: PropTypes.number.isRequired, width: PropTypes.number.isRequired, usageData: PropTypes.instanceOf(Object).isRequired, - legendData: PropTypes.instanceOf(Object).isRequired, inProgress: PropTypes.bool.isRequired, }; diff --git a/components/org.wso2.analytics.apim.widgets/APIMTopApiCreators/src/APIMTopApiCreators.jsx b/components/org.wso2.analytics.apim.widgets/APIMTopApiCreators/src/APIMTopApiCreators.jsx index fd426c545..894c23602 100644 --- a/components/org.wso2.analytics.apim.widgets/APIMTopApiCreators/src/APIMTopApiCreators.jsx +++ b/components/org.wso2.analytics.apim.widgets/APIMTopApiCreators/src/APIMTopApiCreators.jsx @@ -32,7 +32,7 @@ import Typography from '@material-ui/core/Typography'; import { VictoryPie, VictoryLegend, VictoryTooltip, VictoryTheme, } from 'victory'; -import { colorScale } from '@analytics-apim/common-lib'; +import { colorScale, Utils } from '@analytics-apim/common-lib'; import sumBy from 'lodash/sumBy'; import CustomTable from './CustomTable'; @@ -61,7 +61,7 @@ const lightTheme = createMuiTheme({ */ export default function APIMTopApiCreators(props) { const { - themeName, height, limit, creatorData, legendData, handleChange, inProgress, width, + themeName, height, limit, creatorData, handleChange, inProgress, width, } = props; const fontSize = width < 1000 ? 25 : 18; const styles = { @@ -133,6 +133,7 @@ export default function APIMTopApiCreators(props) { strokeWidth: 1, }, }; + const { pieChartData, legendData } = Utils.summarizePieData(creatorData, 'creator', 'apicount'); return (
+ d.creator} y={d => d.apicount} labels={d => `${d.creator} : ${((d.apicount - / (sumBy(creatorData, o => o.apicount))) * 100).toFixed(2)}%`} - /> - o.apicount))) * 100).toFixed(2)}%`} />
@@ -276,7 +277,6 @@ APIMTopApiCreators.propTypes = { width: PropTypes.string.isRequired, limit: PropTypes.string.isRequired, creatorData: PropTypes.instanceOf(Object).isRequired, - legendData: PropTypes.instanceOf(Object).isRequired, handleChange: PropTypes.func.isRequired, inProgress: PropTypes.bool.isRequired, }; diff --git a/components/org.wso2.analytics.apim.widgets/APIMTopAppCreators/src/APIMTopAppCreators.jsx b/components/org.wso2.analytics.apim.widgets/APIMTopAppCreators/src/APIMTopAppCreators.jsx index fa31814ce..b5f784da9 100644 --- a/components/org.wso2.analytics.apim.widgets/APIMTopAppCreators/src/APIMTopAppCreators.jsx +++ b/components/org.wso2.analytics.apim.widgets/APIMTopAppCreators/src/APIMTopAppCreators.jsx @@ -32,7 +32,7 @@ import Typography from '@material-ui/core/Typography'; import { VictoryPie, VictoryLegend, VictoryTooltip, VictoryTheme, } from 'victory'; -import { colorScale } from '@analytics-apim/common-lib'; +import { colorScale, Utils } from '@analytics-apim/common-lib'; import sumBy from 'lodash/sumBy'; import CustomTable from './CustomTable'; @@ -61,7 +61,7 @@ const lightTheme = createMuiTheme({ */ export default function APIMTopAppCreators(props) { const { - themeName, height, width, creatorData, legendData, handleChange, limit, inProgress, + themeName, height, width, creatorData, handleChange, limit, inProgress, } = props; const fontSize = width < 1000 ? 25 : 18; const styles = { @@ -132,7 +132,7 @@ export default function APIMTopAppCreators(props) { strokeWidth: 1, }, }; - + const { pieChartData, legendData } = Utils.summarizePieData(creatorData, 'creator', 'appcount'); return (
+ d.creator} y={d => d.appcount} labels={d => `${d.creator} : ${((d.appcount - / (sumBy(creatorData, o => o.appcount))) * 100).toFixed(2)}%`} - /> - o.appcount))) * 100).toFixed(2)}%`} />
@@ -275,5 +275,4 @@ APIMTopAppCreators.propTypes = { handleChange: PropTypes.func.isRequired, inProgress: PropTypes.bool.isRequired, creatorData: PropTypes.instanceOf(Object).isRequired, - legendData: PropTypes.instanceOf(Object).isRequired, }; diff --git a/components/org.wso2.analytics.apim.widgets/APIMTopAppUsers/src/APIMTopAppUsers.jsx b/components/org.wso2.analytics.apim.widgets/APIMTopAppUsers/src/APIMTopAppUsers.jsx index bf3e55daf..024a1907d 100644 --- a/components/org.wso2.analytics.apim.widgets/APIMTopAppUsers/src/APIMTopAppUsers.jsx +++ b/components/org.wso2.analytics.apim.widgets/APIMTopAppUsers/src/APIMTopAppUsers.jsx @@ -34,7 +34,7 @@ import sumBy from 'lodash/sumBy'; import { VictoryPie, VictoryLegend, VictoryTooltip, VictoryTheme, } from 'victory'; -import { colorScale } from '@analytics-apim/common-lib'; +import { colorScale, Utils } from '@analytics-apim/common-lib'; import CustomTable from './CustomTable'; /** @@ -44,7 +44,7 @@ import CustomTable from './CustomTable'; */ export default function APIMTopAppUsers(props) { const { - themeName, height, width, limit, applicationSelected, usageData, legendData, applicationList, + themeName, height, width, limit, applicationSelected, usageData, applicationList, applicationSelectedHandleChange, handleLimitChange, inProgress, } = props; const fontSize = width < 1000 ? 25 : 18; @@ -135,6 +135,8 @@ export default function APIMTopAppUsers(props) { }, }; + const { pieChartData, legendData } = Utils.summarizePieData(usageData, 'username', 'hits'); + return (
+ d.username} y={d => d.hits} labels={d => `${d.username} : ${((d.hits - / (sumBy(usageData, o => o.hits))) * 100).toFixed(2)}%`} - /> - o.hits))) * 100).toFixed(2)}%`} />
@@ -316,7 +318,6 @@ APIMTopAppUsers.propTypes = { applicationSelected: PropTypes.number.isRequired, applicationList: PropTypes.instanceOf(Object).isRequired, usageData: PropTypes.instanceOf(Object).isRequired, - legendData: PropTypes.instanceOf(Object).isRequired, applicationSelectedHandleChange: PropTypes.func.isRequired, handleLimitChange: PropTypes.func.isRequired, inProgress: PropTypes.bool.isRequired, diff --git a/components/org.wso2.analytics.apim.widgets/APIMTopFaultyApis/src/APIMTopFaultyApis.jsx b/components/org.wso2.analytics.apim.widgets/APIMTopFaultyApis/src/APIMTopFaultyApis.jsx index 84b60d6b5..77774446b 100644 --- a/components/org.wso2.analytics.apim.widgets/APIMTopFaultyApis/src/APIMTopFaultyApis.jsx +++ b/components/org.wso2.analytics.apim.widgets/APIMTopFaultyApis/src/APIMTopFaultyApis.jsx @@ -29,7 +29,7 @@ import Typography from '@material-ui/core/Typography'; import { VictoryPie, VictoryLegend, VictoryTooltip, VictoryTheme, } from 'victory'; -import { colorScale } from '@analytics-apim/common-lib'; +import { colorScale, Utils } from '@analytics-apim/common-lib'; import sumBy from 'lodash/sumBy'; import CustomTable from './CustomTable'; @@ -58,7 +58,7 @@ const lightTheme = createMuiTheme({ */ export default function APIMTopFaultyApis(props) { const { - themeName, height, limit, faultData, legendData, handleChange, inProgress, width, + themeName, height, limit, faultData, handleChange, inProgress, width, } = props; const fontSize = width < 1000 ? 16 : 18; const styles = { @@ -124,6 +124,8 @@ export default function APIMTopFaultyApis(props) { }, }; + const { pieChartData, legendData } = Utils.summarizePieData(faultData, 'apiname', 'faultcount'); + return (
+ d.apiname} y={d => d.faultcount} - labels={d => `${d.apiname} : ${((d.faultcount - / (sumBy(faultData, o => o.faultcount))) * 100).toFixed(2)}%`} - /> - `${d.apiname} : ${((d.faultcount + / (sumBy(pieChartData, o => o.faultcount))) * 100).toFixed(2)}%` + } />
@@ -258,7 +262,6 @@ APIMTopFaultyApis.propTypes = { width: PropTypes.string.isRequired, limit: PropTypes.string.isRequired, faultData: PropTypes.instanceOf(Object).isRequired, - legendData: PropTypes.instanceOf(Object).isRequired, handleChange: PropTypes.func.isRequired, inProgress: PropTypes.bool.isRequired, }; diff --git a/components/org.wso2.analytics.apim.widgets/APIMTopPlatforms/src/APIMTopPlatforms.jsx b/components/org.wso2.analytics.apim.widgets/APIMTopPlatforms/src/APIMTopPlatforms.jsx index 7ca60cb08..1cfb78197 100644 --- a/components/org.wso2.analytics.apim.widgets/APIMTopPlatforms/src/APIMTopPlatforms.jsx +++ b/components/org.wso2.analytics.apim.widgets/APIMTopPlatforms/src/APIMTopPlatforms.jsx @@ -35,7 +35,7 @@ import Typography from '@material-ui/core/Typography'; import { VictoryPie, VictoryLegend, VictoryTooltip, VictoryTheme, } from 'victory'; -import { colorScale } from '@analytics-apim/common-lib'; +import { colorScale, Utils } from '@analytics-apim/common-lib'; /** @@ -45,7 +45,7 @@ import { colorScale } from '@analytics-apim/common-lib'; */ export default function APIMTopPlatforms(props) { const { - themeName, height, limit, apiCreatedBy, apiSelected, apiVersion, legendData, platformData, apilist, versionlist, + themeName, height, limit, apiCreatedBy, apiSelected, apiVersion, platformData, apilist, versionlist, apiCreatedHandleChange, apiSelectedHandleChange, apiVersionHandleChange, handleLimitChange, inProgress, } = props; const fontSize = 16; @@ -101,6 +101,8 @@ export default function APIMTopPlatforms(props) { }, }; + const { pieChartData, legendData } = Utils.summarizePieData(platformData, 'platform', 'reqCount'); + return ( + d.platform} y={d => d.reqCount} labels={d => `${d.platform} : ${((d.reqCount - / (sumBy(platformData, o => o.reqCount))) * 100).toFixed(2)}%`} - /> - o.reqCount))) * 100).toFixed(2)}%`} />
@@ -312,7 +314,6 @@ APIMTopPlatforms.propTypes = { apiVersion: PropTypes.string.isRequired, apilist: PropTypes.instanceOf(Object).isRequired, versionlist: PropTypes.instanceOf(Object).isRequired, - legendData: PropTypes.instanceOf(Object).isRequired, platformData: PropTypes.instanceOf(Object).isRequired, apiCreatedHandleChange: PropTypes.func.isRequired, apiSelectedHandleChange: PropTypes.func.isRequired, diff --git a/components/org.wso2.analytics.apim.widgets/APIMTopSubscribers/src/APIMTopSubscribers.jsx b/components/org.wso2.analytics.apim.widgets/APIMTopSubscribers/src/APIMTopSubscribers.jsx index 113c2fc50..b58707226 100644 --- a/components/org.wso2.analytics.apim.widgets/APIMTopSubscribers/src/APIMTopSubscribers.jsx +++ b/components/org.wso2.analytics.apim.widgets/APIMTopSubscribers/src/APIMTopSubscribers.jsx @@ -32,7 +32,7 @@ import Typography from '@material-ui/core/Typography'; import { VictoryPie, VictoryLegend, VictoryTooltip, VictoryTheme, } from 'victory'; -import { colorScale } from '@analytics-apim/common-lib'; +import { colorScale, Utils } from '@analytics-apim/common-lib'; import sumBy from 'lodash/sumBy'; import CustomTable from './CustomTable'; @@ -61,7 +61,7 @@ const lightTheme = createMuiTheme({ */ export default function APIMTopSubscribers(props) { const { - themeName, height, limit, creatorData, legendData, handleChange, inProgress, width, + themeName, height, limit, creatorData, handleChange, inProgress, width, } = props; const fontSize = width < 1000 ? 25 : 18; const styles = { @@ -133,6 +133,7 @@ export default function APIMTopSubscribers(props) { }, }; + const { pieChartData, legendData } = Utils.summarizePieData(creatorData, 'creator', 'subcount'); return (
+ d.creator} y={d => d.subcount} labels={d => `${d.creator} : ${((d.subcount - / (sumBy(creatorData, o => o.subcount))) * 100).toFixed(2)}%`} - /> - o.subcount))) * 100).toFixed(2)}%`} />
@@ -275,7 +276,6 @@ APIMTopSubscribers.propTypes = { height: PropTypes.string.isRequired, limit: PropTypes.string.isRequired, creatorData: PropTypes.instanceOf(Object).isRequired, - legendData: PropTypes.instanceOf(Object).isRequired, handleChange: PropTypes.func.isRequired, inProgress: PropTypes.bool.isRequired, }; diff --git a/components/org.wso2.analytics.apim.widgets/APIMTopThrottledOutApis/src/APIMTopThrottledApis.jsx b/components/org.wso2.analytics.apim.widgets/APIMTopThrottledOutApis/src/APIMTopThrottledApis.jsx index 1975571e1..d45917019 100644 --- a/components/org.wso2.analytics.apim.widgets/APIMTopThrottledOutApis/src/APIMTopThrottledApis.jsx +++ b/components/org.wso2.analytics.apim.widgets/APIMTopThrottledOutApis/src/APIMTopThrottledApis.jsx @@ -29,7 +29,7 @@ import Typography from '@material-ui/core/Typography'; import { VictoryPie, VictoryLegend, VictoryTooltip, VictoryTheme, } from 'victory'; -import { colorScale } from '@analytics-apim/common-lib'; +import { colorScale, Utils } from '@analytics-apim/common-lib'; import sumBy from 'lodash/sumBy'; import CustomTable from './CustomTable'; @@ -58,7 +58,7 @@ const lightTheme = createMuiTheme({ */ export default function APIMTopThrottledApis(props) { const { - themeName, height, limit, throttledData, legendData, handleChange, inProgress, width, + themeName, height, limit, throttledData, handleChange, inProgress, width, } = props; const fontSize = width < 1000 ? 16 : 18; const styles = { @@ -124,6 +124,8 @@ export default function APIMTopThrottledApis(props) { }, }; + const { pieChartData, legendData } = Utils.summarizePieData(throttledData, 'apiname', 'throttledcount'); + return (
+ d.apiname} y={d => d.throttledcount} labels={d => `${d.apiname} : ${((d.throttledcount - / (sumBy(throttledData, o => o.throttledcount))) * 100) + / (sumBy(pieChartData, o => o.throttledcount))) * 100) .toFixed(2)}%`} /> -
@@ -257,7 +259,6 @@ APIMTopThrottledApis.propTypes = { width: PropTypes.string.isRequired, limit: PropTypes.string.isRequired, throttledData: PropTypes.instanceOf(Object).isRequired, - legendData: PropTypes.instanceOf(Object).isRequired, handleChange: PropTypes.func.isRequired, inProgress: PropTypes.bool.isRequired, }; diff --git a/components/org.wso2.analytics.apim.widgets/APIMTopUserAgents/src/APIMTopAgents.jsx b/components/org.wso2.analytics.apim.widgets/APIMTopUserAgents/src/APIMTopAgents.jsx index 845f693bb..21cd0d780 100644 --- a/components/org.wso2.analytics.apim.widgets/APIMTopUserAgents/src/APIMTopAgents.jsx +++ b/components/org.wso2.analytics.apim.widgets/APIMTopUserAgents/src/APIMTopAgents.jsx @@ -35,7 +35,7 @@ import Tooltip from '@material-ui/core/Tooltip'; import { VictoryPie, VictoryLegend, VictoryTooltip, VictoryTheme, } from 'victory'; -import { colorScale } from '@analytics-apim/common-lib'; +import { colorScale, Utils } from '@analytics-apim/common-lib'; /** * React Component for Top User Agents widget body @@ -44,7 +44,7 @@ import { colorScale } from '@analytics-apim/common-lib'; */ export default function APIMTopAgents(props) { const { - themeName, height, limit, apiCreatedBy, apiSelected, apiVersion, legendData, agentData, apilist, versionlist, + themeName, height, limit, apiCreatedBy, apiSelected, apiVersion, agentData, apilist, versionlist, apiCreatedHandleChange, apiSelectedHandleChange, apiVersionHandleChange, handleLimitChange, inProgress, } = props; const fontSize = 16; @@ -104,6 +104,7 @@ export default function APIMTopAgents(props) { }, }; + const { pieChartData, legendData } = Utils.summarizePieData(agentData, 'agent', 'reqCount'); return ( + d.agent} y={d => d.reqCount} labels={d => `${d.agent} : ${((d.reqCount - / (sumBy(agentData, o => o.reqCount))) * 100).toFixed(2)}%`} - /> - o.reqCount))) * 100).toFixed(2)}%`} />
diff --git a/components/org.wso2.analytics.apim.widgets/CommonLib/src/Utils.js b/components/org.wso2.analytics.apim.widgets/CommonLib/src/Utils.js new file mode 100644 index 000000000..b02f5ad27 --- /dev/null +++ b/components/org.wso2.analytics.apim.widgets/CommonLib/src/Utils.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. 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. + * + */ + +function summarizePieData(data=[], nameField, countField) { + const PIE_CHART_LIMIT = 8; + const pieChartData = data.sort((a, b) => { + return b[countField] - a[countField]; + }); + + if (data.length > PIE_CHART_LIMIT) { + const otherPieChartData = pieChartData.slice(PIE_CHART_LIMIT, pieChartData.length) + .reduce((accumulator, currentValue) => { + return { [nameField]: ['Other'],[countField]: accumulator[countField] + currentValue[countField] }; + }, { [nameField]: ['Other'],[countField]: 0 }); + + pieChartData.splice(PIE_CHART_LIMIT, pieChartData.length, otherPieChartData); + } + console.log(pieChartData); + const legendData = pieChartData.map((item) => { + return { name: item[nameField] }; + }); + return { + pieChartData, + legendData + }; +} + +export default { + summarizePieData +} \ No newline at end of file diff --git a/components/org.wso2.analytics.apim.widgets/CommonLib/src/index.js b/components/org.wso2.analytics.apim.widgets/CommonLib/src/index.js index f864bc31c..f07dca9a9 100644 --- a/components/org.wso2.analytics.apim.widgets/CommonLib/src/index.js +++ b/components/org.wso2.analytics.apim.widgets/CommonLib/src/index.js @@ -19,6 +19,8 @@ import CustomTableToolbar from './CustomTableToolbar'; import SummaryWidget from './SummaryWidget'; +import Utils from './Utils'; + const colorScale = [ '#45b29d', '#ff9800', @@ -31,4 +33,4 @@ const colorScale = [ '#607d8b', '#e91e63', ]; -export {CustomTableToolbar, SummaryWidget, colorScale}; +export {CustomTableToolbar, SummaryWidget, colorScale, Utils}; From 9cf3f6e50aa4d30dbbbc3339081fd963648de9f8 Mon Sep 17 00:00:00 2001 From: pahans Date: Fri, 20 Mar 2020 20:30:24 +0530 Subject: [PATCH 2/3] Add new line --- .../org.wso2.analytics.apim.widgets/CommonLib/src/Utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/org.wso2.analytics.apim.widgets/CommonLib/src/Utils.js b/components/org.wso2.analytics.apim.widgets/CommonLib/src/Utils.js index b02f5ad27..dd5e218b1 100644 --- a/components/org.wso2.analytics.apim.widgets/CommonLib/src/Utils.js +++ b/components/org.wso2.analytics.apim.widgets/CommonLib/src/Utils.js @@ -43,4 +43,4 @@ function summarizePieData(data=[], nameField, countField) { export default { summarizePieData -} \ No newline at end of file +} From 84d3f970892e23d35b81c58600b8cee3c395f01c Mon Sep 17 00:00:00 2001 From: pahans Date: Fri, 20 Mar 2020 20:38:30 +0530 Subject: [PATCH 3/3] Remove unused import --- .../APIMApiAvailability/src/ApiAvailability.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/org.wso2.analytics.apim.widgets/APIMApiAvailability/src/ApiAvailability.jsx b/components/org.wso2.analytics.apim.widgets/APIMApiAvailability/src/ApiAvailability.jsx index a863e01a6..591b2ffba 100644 --- a/components/org.wso2.analytics.apim.widgets/APIMApiAvailability/src/ApiAvailability.jsx +++ b/components/org.wso2.analytics.apim.widgets/APIMApiAvailability/src/ApiAvailability.jsx @@ -22,7 +22,7 @@ import PropTypes from 'prop-types'; import { VictoryPie, VictoryLegend, VictoryTooltip, VictoryTheme, VictoryContainer, } from 'victory'; -import { colorScale, Utils } from '@analytics-apim/common-lib'; +import { colorScale } from '@analytics-apim/common-lib'; import sumBy from 'lodash/sumBy'; /**