Skip to content

Commit

Permalink
feat: pie chart expose selection
Browse files Browse the repository at this point in the history
  • Loading branch information
gjulivan committed Nov 6, 2024
1 parent cd8e8df commit 5e2f196
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/pluggableWidgets/charts-web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mendix/charts-web",
"version": "5.1.0",
"version": "5.1.1",
"description": "Chart widgets collection for data visualization",
"license": "Apache-2.0",
"private": false,
Expand Down
2 changes: 1 addition & 1 deletion packages/pluggableWidgets/charts-web/src/package.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<package xmlns="http://www.mendix.com/package/1.0/">
<clientModule name="Charts" version="5.1.0" xmlns="http://www.mendix.com/clientModule/1.0/">
<clientModule name="Charts" version="5.1.1" xmlns="http://www.mendix.com/clientModule/1.0/">
<widgetFiles>
<widgetFile path="AreaChart/AreaChart.xml" />
<widgetFile path="BarChart/BarChart.xml" />
Expand Down
4 changes: 4 additions & 0 deletions packages/pluggableWidgets/pie-doughnut-chart-web/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

### Added

- We allow pie chart to exposed the selection.

## [5.1.0] - 2024-10-28

### Changed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@mendix/pie-doughnut-chart-web",
"widgetName": "PieChart",
"version": "5.1.0",
"version": "5.1.1",
"description": "Shows data in a pie format graph.",
"copyright": "© Mendix Technology BV 2023. All rights reserved.",
"license": "Apache-2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export function PieChart(props: PieChartContainerProps): ReactElement | null {
seriesSortOrder: props.seriesSortOrder,
seriesValueAttribute: props.seriesValueAttribute,
onClickAction: props.onClickAction,
tooltipHoverText: props.tooltipHoverText
tooltipHoverText: props.tooltipHoverText,
optionsSourceDatabaseItemSelection: props.optionsSourceDatabaseItemSelection
});

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@
<description />
<returnType type="String" />
</property>
<property key="optionsSourceDatabaseItemSelection" type="selection" dataSource="seriesDataSource">
<caption>Selection type</caption>
<description />
<selectionTypes>
<selectionType name="None" />
<selectionType name="Single" />
</selectionTypes>
</property>
</propertyGroup>
<propertyGroup caption="General">
<property key="enableAdvancedOptions" type="boolean" defaultValue="false">
Expand Down
18 changes: 14 additions & 4 deletions packages/pluggableWidgets/pie-doughnut-chart-web/src/hooks/data.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ValueStatus } from "mendix";
import { useEffect, useMemo, useState } from "react";
import { ObjectItem, SelectionSingleValue, ValueStatus } from "mendix";
import { useCallback, useEffect, useMemo, useState } from "react";
import { ensure } from "@mendix/pluggable-widgets-tools";
import Big from "big.js";
import { PieChartContainerProps } from "../../typings/PieChartProps";
Expand All @@ -18,6 +18,7 @@ type PieChartDataSeriesHooks = Pick<
| "seriesSortOrder"
| "seriesValueAttribute"
| "tooltipHoverText"
| "optionsSourceDatabaseItemSelection"
>;

type LocalPieChartData = {
Expand All @@ -38,7 +39,8 @@ export const usePieChartDataSeries = ({
seriesSortOrder,
seriesValueAttribute,
onClickAction,
tooltipHoverText
tooltipHoverText,
optionsSourceDatabaseItemSelection
}: PieChartDataSeriesHooks): ChartWidgetProps["data"] => {
const [pieChartData, setPieChartData] = useState<LocalPieChartData[]>([]);

Expand Down Expand Up @@ -71,7 +73,15 @@ export const usePieChartDataSeries = ({
tooltipHoverText
]);

const onClick = useMemo(() => (onClickAction ? () => executeAction(onClickAction) : undefined), [onClickAction]);
const onClick: (obj: ObjectItem) => void = useCallback(
(item: ObjectItem) => {
executeAction(onClickAction);
if (optionsSourceDatabaseItemSelection && optionsSourceDatabaseItemSelection.type === "Single") {
(optionsSourceDatabaseItemSelection as SelectionSingleValue).setSelection(item);
}
},
[onClickAction]
);

return useMemo<ChartWidgetProps["data"]>(
() => [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<package xmlns="http://www.mendix.com/package/1.0/">
<clientModule name="PieChart" version="5.1.0" xmlns="http://www.mendix.com/clientModule/1.0/">
<clientModule name="PieChart" version="5.1.1" xmlns="http://www.mendix.com/clientModule/1.0/">
<widgetFiles>
<widgetFile path="PieChart.xml" />
</widgetFiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @author Mendix Widgets Framework Team
*/
import { ComponentType, CSSProperties, ReactNode } from "react";
import { ActionValue, ListValue, ListAttributeValue, ListExpressionValue } from "mendix";
import { ActionValue, ListValue, ListAttributeValue, ListExpressionValue, SelectionSingleValue } from "mendix";
import { Big } from "big.js";

export type SeriesSortOrderEnum = "asc" | "desc";
Expand All @@ -24,6 +24,7 @@ export interface PieChartContainerProps {
seriesSortAttribute?: ListAttributeValue<string | boolean | Date | Big>;
seriesSortOrder: SeriesSortOrderEnum;
seriesColorAttribute?: ListExpressionValue<string>;
optionsSourceDatabaseItemSelection?: SelectionSingleValue;
enableAdvancedOptions: boolean;
showPlaygroundSlot: boolean;
playground?: ReactNode;
Expand Down Expand Up @@ -57,6 +58,7 @@ export interface PieChartPreviewProps {
seriesSortAttribute: string;
seriesSortOrder: SeriesSortOrderEnum;
seriesColorAttribute: string;
optionsSourceDatabaseItemSelection: "None" | "Single";
enableAdvancedOptions: boolean;
showPlaygroundSlot: boolean;
playground: { widgetCount: number; renderer: ComponentType<{ children: ReactNode; caption?: string }> };
Expand Down

0 comments on commit 5e2f196

Please sign in to comment.