-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathAreaChart.tsx
More file actions
77 lines (67 loc) · 2.58 KB
/
Copy pathAreaChart.tsx
File metadata and controls
77 lines (67 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// (C) 2007-2019 GoodData Corporation
import * as React from "react";
import omit = require("lodash/omit");
import { VisualizationObject, VisualizationInput } from "@gooddata/typings";
import { Subtract } from "../typings/subtract";
import { AreaChart as AfmAreaChart } from "./afm/AreaChart";
import { ICommonChartProps } from "./core/base/BaseChart";
import { convertBucketsToAFM } from "../helpers/conversion";
import { getStackingResultSpec } from "../helpers/resultSpec";
import { MEASURES, ATTRIBUTE, STACK } from "../constants/bucketNames";
import { verifyBuckets, getBucketsProps, getConfigProps } from "../helpers/optionalStacking/areaChart";
import { sanitizeConfig, sanitizeComputeRatioOnMeasures } from "../helpers/optionalStacking/common";
export interface IAreaChartBucketProps {
measures: VisualizationInput.AttributeOrMeasure[];
viewBy?: VisualizationInput.IAttribute | VisualizationInput.IAttribute[];
stackBy?: VisualizationInput.IAttribute;
filters?: VisualizationInput.IFilter[];
sortBy?: VisualizationInput.ISort[];
}
export interface IAreaChartProps extends ICommonChartProps, IAreaChartBucketProps {
projectId: string;
}
type IAreaChartNonBucketProps = Subtract<IAreaChartProps, IAreaChartBucketProps>;
/**
* [AreaChart](http://sdk.gooddata.com/gooddata-ui/docs/area_chart_component.html)
* is a component with bucket props measures, viewBy, stacksBy, filters
*/
export function AreaChart(props: IAreaChartProps): JSX.Element {
verifyBuckets(props);
const { measures, viewBy, stackBy } = getBucketsProps(props);
const sanitizedMeasures = sanitizeComputeRatioOnMeasures(measures);
const configProp = getConfigProps(props);
const buckets: VisualizationObject.IBucket[] = [
{
localIdentifier: MEASURES,
items: sanitizedMeasures,
},
{
localIdentifier: ATTRIBUTE,
items: viewBy,
},
{
localIdentifier: STACK,
items: stackBy,
},
];
const newProps: IAreaChartNonBucketProps = omit<IAreaChartProps, keyof IAreaChartBucketProps>(props, [
"measures",
"viewBy",
"stackBy",
"filters",
"sortBy",
]);
const sanitizedConfig = sanitizeConfig(measures, {
...newProps.config,
...configProp,
});
return (
<AfmAreaChart
{...newProps}
config={sanitizedConfig}
projectId={props.projectId}
afm={convertBucketsToAFM(buckets, props.filters)}
resultSpec={getStackingResultSpec(buckets, props.sortBy)}
/>
);
}