2021-03-04 05:24:47 +00:00
|
|
|
import React, { lazy, Suspense } from "react";
|
|
|
|
|
import BaseWidget, { WidgetProps, WidgetState } from "widgets/BaseWidget";
|
|
|
|
|
import { WidgetType } from "constants/WidgetConstants";
|
|
|
|
|
import Skeleton from "components/utils/Skeleton";
|
|
|
|
|
import * as Sentry from "@sentry/react";
|
|
|
|
|
import { retryPromise } from "utils/AppsmithUtils";
|
2021-03-30 05:29:03 +00:00
|
|
|
import { EventType } from "constants/AppsmithActionConstants/ActionConstants";
|
2021-03-04 05:24:47 +00:00
|
|
|
import withMeta, { WithMeta } from "widgets/MetaHOC";
|
|
|
|
|
import propertyConfig from "widgets/ChartWidget/propertyConfig";
|
2021-03-24 22:05:04 +00:00
|
|
|
import { CustomFusionChartConfig } from "components/designSystems/appsmith/ChartComponent";
|
2021-03-04 05:24:47 +00:00
|
|
|
|
|
|
|
|
const ChartComponent = lazy(() =>
|
|
|
|
|
retryPromise(() =>
|
|
|
|
|
import(
|
|
|
|
|
/* webpackPrefetch: true, webpackChunkName: "charts" */ "components/designSystems/appsmith/ChartComponent"
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
class ChartWidget extends BaseWidget<ChartWidgetProps, WidgetState> {
|
2021-06-18 07:42:57 +00:00
|
|
|
static getMetaPropertiesMap(): Record<string, any> {
|
2021-03-04 05:24:47 +00:00
|
|
|
return {
|
|
|
|
|
selectedDataPoint: undefined,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static getPropertyPaneConfig() {
|
|
|
|
|
return propertyConfig;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onDataPointClick = (selectedDataPoint: { x: any; y: any }) => {
|
|
|
|
|
this.props.updateWidgetMetaProperty(
|
|
|
|
|
"selectedDataPoint",
|
|
|
|
|
selectedDataPoint,
|
|
|
|
|
{
|
2021-04-23 13:50:55 +00:00
|
|
|
triggerPropertyName: "onDataPointClick",
|
2021-03-04 05:24:47 +00:00
|
|
|
dynamicString: this.props.onDataPointClick,
|
|
|
|
|
event: {
|
|
|
|
|
type: EventType.ON_DATA_POINT_CLICK,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
getPageView() {
|
|
|
|
|
return (
|
|
|
|
|
<Suspense fallback={<Skeleton />}>
|
|
|
|
|
<ChartComponent
|
2021-04-28 10:28:39 +00:00
|
|
|
allowHorizontalScroll={this.props.allowHorizontalScroll}
|
2021-03-04 05:24:47 +00:00
|
|
|
chartData={this.props.chartData}
|
2021-04-28 10:28:39 +00:00
|
|
|
chartName={this.props.chartName}
|
|
|
|
|
chartType={this.props.chartType}
|
2021-03-24 22:05:04 +00:00
|
|
|
customFusionChartConfig={this.props.customFusionChartConfig}
|
2021-04-28 10:28:39 +00:00
|
|
|
isVisible={this.props.isVisible}
|
|
|
|
|
key={this.props.widgetId}
|
2021-03-04 05:24:47 +00:00
|
|
|
onDataPointClick={this.onDataPointClick}
|
2021-04-28 10:28:39 +00:00
|
|
|
widgetId={this.props.widgetId}
|
|
|
|
|
xAxisName={this.props.xAxisName}
|
|
|
|
|
yAxisName={this.props.yAxisName}
|
2021-03-04 05:24:47 +00:00
|
|
|
/>
|
|
|
|
|
</Suspense>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getWidgetType(): WidgetType {
|
|
|
|
|
return "CHART_WIDGET";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export type ChartType =
|
|
|
|
|
| "LINE_CHART"
|
|
|
|
|
| "BAR_CHART"
|
|
|
|
|
| "PIE_CHART"
|
|
|
|
|
| "COLUMN_CHART"
|
|
|
|
|
| "AREA_CHART"
|
2021-03-24 22:05:04 +00:00
|
|
|
| "SCATTER_CHART"
|
|
|
|
|
| "CUSTOM_FUSION_CHART";
|
2021-03-04 05:24:47 +00:00
|
|
|
|
|
|
|
|
export interface ChartDataPoint {
|
|
|
|
|
x: any;
|
|
|
|
|
y: any;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-26 10:35:59 +00:00
|
|
|
export interface AllChartData {
|
|
|
|
|
[key: string]: ChartData;
|
|
|
|
|
}
|
2021-03-04 05:24:47 +00:00
|
|
|
export interface ChartData {
|
|
|
|
|
seriesName?: string;
|
|
|
|
|
data: ChartDataPoint[];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface ChartWidgetProps extends WidgetProps, WithMeta {
|
|
|
|
|
chartType: ChartType;
|
2021-04-26 10:35:59 +00:00
|
|
|
chartData: AllChartData;
|
2021-05-28 09:19:36 +00:00
|
|
|
customFusionChartConfig: CustomFusionChartConfig;
|
2021-03-04 05:24:47 +00:00
|
|
|
xAxisName: string;
|
|
|
|
|
yAxisName: string;
|
|
|
|
|
chartName: string;
|
|
|
|
|
isVisible?: boolean;
|
|
|
|
|
allowHorizontalScroll: boolean;
|
|
|
|
|
onDataPointClick?: string;
|
|
|
|
|
selectedDataPoint?: ChartDataPoint;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default ChartWidget;
|
|
|
|
|
export const ProfiledChartWidget = Sentry.withProfiler(withMeta(ChartWidget));
|