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";
|
2022-09-29 05:24:49 +00:00
|
|
|
import { contentConfig, styleConfig } 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";
|
2022-08-12 12:10:17 +00:00
|
|
|
import { Colors } from "constants/Colors";
|
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,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-09 13:05:36 +00:00
|
|
|
static getPropertyPaneContentConfig() {
|
|
|
|
|
return contentConfig;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static getPropertyPaneStyleConfig() {
|
|
|
|
|
return styleConfig;
|
|
|
|
|
}
|
|
|
|
|
|
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-10-25 11:39:39 +00:00
|
|
|
allowScroll={this.props.allowScroll}
|
2022-05-04 09:45:57 +00:00
|
|
|
borderRadius={this.props.borderRadius}
|
|
|
|
|
boxShadow={this.props.boxShadow}
|
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}
|
2022-08-12 12:10:17 +00:00
|
|
|
fontFamily={this.props.fontFamily ?? "Nunito Sans"}
|
2022-01-18 07:51:28 +00:00
|
|
|
isLoading={this.props.isLoading}
|
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}
|
2022-08-12 12:10:17 +00:00
|
|
|
primaryColor={this.props.accentColor ?? Colors.ROYAL_BLUE_2}
|
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;
|
2021-10-25 11:39:39 +00:00
|
|
|
allowScroll: boolean;
|
2022-05-04 09:45:57 +00:00
|
|
|
borderRadius: string;
|
|
|
|
|
boxShadow?: string;
|
2022-08-12 12:10:17 +00:00
|
|
|
accentColor?: string;
|
|
|
|
|
fontFamily?: string;
|
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;
|