PromucFlow_constructor/app/client/src/widgets/ChartWidget.tsx

78 lines
2.1 KiB
TypeScript
Raw Normal View History

import React, { lazy, Suspense } from "react";
2020-03-13 12:06:41 +00:00
import BaseWidget, { WidgetProps, WidgetState } from "./BaseWidget";
import { WidgetType } from "constants/WidgetConstants";
// import ChartComponent from "components/designSystems/appsmith/ChartComponent";
2020-03-13 12:06:41 +00:00
import { WidgetPropertyValidationType } from "utils/ValidationFactory";
import { VALIDATION_TYPES } from "constants/WidgetValidation";
2020-04-16 08:32:58 +00:00
import Skeleton from "components/utils/Skeleton";
2020-03-13 12:06:41 +00:00
const ChartComponent = lazy(() =>
import(
2020-04-17 04:59:43 +00:00
/* webpackPrefetch: true, webpackChunkName: "charts" */ "components/designSystems/appsmith/ChartComponent"
),
);
2020-03-13 12:06:41 +00:00
class ChartWidget extends BaseWidget<ChartWidgetProps, WidgetState> {
static getPropertyValidationMap(): WidgetPropertyValidationType {
return {
xAxisName: VALIDATION_TYPES.TEXT,
yAxisName: VALIDATION_TYPES.TEXT,
chartName: VALIDATION_TYPES.TEXT,
isVisible: VALIDATION_TYPES.BOOLEAN,
2020-05-07 10:51:37 +00:00
chartData: VALIDATION_TYPES.CHART_DATA,
2020-03-13 12:06:41 +00:00
};
}
getPageView() {
return (
2020-04-16 08:32:58 +00:00
<Suspense fallback={<Skeleton />}>
<ChartComponent
key={this.props.widgetId}
isVisible={this.props.isVisible}
chartType={this.props.chartType}
xAxisName={this.props.xAxisName}
yAxisName={this.props.yAxisName}
chartName={this.props.chartName}
chartData={this.props.chartData}
widgetId={this.props.widgetId}
allowHorizontalScroll={this.props.allowHorizontalScroll}
/>
</Suspense>
2020-03-13 12:06:41 +00:00
);
}
getWidgetType(): WidgetType {
return "CHART_WIDGET";
}
}
export type ChartType =
| "LINE_CHART"
| "BAR_CHART"
| "PIE_CHART"
| "COLUMN_CHART"
| "AREA_CHART"
| "SCATTER_CHART";
2020-04-15 11:42:11 +00:00
export interface ChartDataPoint {
2020-03-13 12:06:41 +00:00
x: any;
y: any;
}
2020-04-15 11:42:11 +00:00
export interface ChartData {
seriesName?: string;
data: ChartDataPoint[];
}
2020-03-13 12:06:41 +00:00
export interface ChartWidgetProps extends WidgetProps {
chartType: ChartType;
chartData: ChartData[];
xAxisName: string;
yAxisName: string;
chartName: string;
isVisible?: boolean;
2020-04-15 11:42:11 +00:00
allowHorizontalScroll: boolean;
2020-03-13 12:06:41 +00:00
}
export default ChartWidget;