2020-03-13 12:06:41 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import BaseWidget, { WidgetProps, WidgetState } from "./BaseWidget";
|
|
|
|
|
import { WidgetType } from "constants/WidgetConstants";
|
|
|
|
|
import ChartComponent from "components/designSystems/appsmith/ChartComponent";
|
|
|
|
|
import { WidgetPropertyValidationType } from "utils/ValidationFactory";
|
|
|
|
|
import { VALIDATION_TYPES } from "constants/WidgetValidation";
|
|
|
|
|
|
|
|
|
|
class ChartWidget extends BaseWidget<ChartWidgetProps, WidgetState> {
|
|
|
|
|
static getPropertyValidationMap(): WidgetPropertyValidationType {
|
|
|
|
|
return {
|
|
|
|
|
xAxisName: VALIDATION_TYPES.TEXT,
|
|
|
|
|
yAxisName: VALIDATION_TYPES.TEXT,
|
|
|
|
|
chartName: VALIDATION_TYPES.TEXT,
|
2020-04-13 08:55:01 +00:00
|
|
|
isVisible: VALIDATION_TYPES.BOOLEAN,
|
2020-03-13 12:06:41 +00:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getPageView() {
|
|
|
|
|
return (
|
|
|
|
|
<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}
|
2020-03-20 12:16:53 +00:00
|
|
|
widgetId={this.props.widgetId}
|
2020-04-15 11:42:11 +00:00
|
|
|
allowHorizontalScroll={this.props.allowHorizontalScroll}
|
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;
|