2021-03-04 05:24:47 +00:00
|
|
|
import React, { lazy, Suspense } from "react";
|
2021-08-26 09:58:43 +00:00
|
|
|
|
2021-03-04 05:24:47 +00:00
|
|
|
import BaseWidget, { WidgetProps, WidgetState } from "widgets/BaseWidget";
|
|
|
|
|
import Skeleton from "components/utils/Skeleton";
|
2021-09-09 15:10:22 +00:00
|
|
|
import { retryPromise } from "utils/AppsmithUtils";
|
|
|
|
|
import { EventType } from "constants/AppsmithActionConstants/ActionConstants";
|
|
|
|
|
import propertyConfig from "./propertyConfig";
|
2021-08-18 07:11:07 +00:00
|
|
|
import {
|
2021-09-09 15:10:22 +00:00
|
|
|
ChartType,
|
|
|
|
|
CustomFusionChartConfig,
|
|
|
|
|
AllChartData,
|
2021-08-18 07:11:07 +00:00
|
|
|
ChartSelectedDataPoint,
|
2021-09-09 15:10:22 +00:00
|
|
|
} from "../constants";
|
|
|
|
|
|
2021-08-26 09:58:43 +00:00
|
|
|
import { WidgetType } from "constants/WidgetConstants";
|
2021-09-09 15:10:22 +00:00
|
|
|
import { ChartComponentProps } from "../component";
|
2021-03-04 05:24:47 +00:00
|
|
|
|
|
|
|
|
const ChartComponent = lazy(() =>
|
|
|
|
|
retryPromise(() =>
|
|
|
|
|
import(
|
2021-09-09 15:10:22 +00:00
|
|
|
/* webpackPrefetch: true, webpackChunkName: "charts" */ "../component"
|
2021-03-04 05:24:47 +00:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-18 07:11:07 +00:00
|
|
|
onDataPointClick = (selectedDataPoint: ChartSelectedDataPoint) => {
|
2021-03-04 05:24:47 +00:00
|
|
|
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-08-26 09:58:43 +00:00
|
|
|
labelOrientation={this.props.labelOrientation}
|
2021-03-04 05:24:47 +00:00
|
|
|
onDataPointClick={this.onDataPointClick}
|
2021-09-06 12:15:58 +00:00
|
|
|
setAdaptiveYMin={this.props.setAdaptiveYMin}
|
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>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-09 15:10:22 +00:00
|
|
|
static getWidgetType(): WidgetType {
|
2021-03-04 05:24:47 +00:00
|
|
|
return "CHART_WIDGET";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-09 15:10:22 +00:00
|
|
|
export interface ChartWidgetProps extends WidgetProps {
|
|
|
|
|
chartType: ChartType;
|
|
|
|
|
chartData: AllChartData;
|
|
|
|
|
customFusionChartConfig: CustomFusionChartConfig;
|
|
|
|
|
xAxisName: string;
|
|
|
|
|
yAxisName: string;
|
|
|
|
|
chartName: string;
|
|
|
|
|
isVisible?: boolean;
|
|
|
|
|
allowHorizontalScroll: boolean;
|
2021-03-04 05:24:47 +00:00
|
|
|
}
|
|
|
|
|
|
2021-08-26 09:58:43 +00:00
|
|
|
type ChartComponentPartialProps = Omit<ChartComponentProps, "onDataPointClick">;
|
|
|
|
|
export interface ChartWidgetProps
|
|
|
|
|
extends WidgetProps,
|
|
|
|
|
ChartComponentPartialProps {
|
2021-03-04 05:24:47 +00:00
|
|
|
onDataPointClick?: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default ChartWidget;
|