-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
son do
committed
Apr 3, 2018
1 parent
6e6c15e
commit fb3cbdd
Showing
21 changed files
with
640 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import React, { Component } from 'react'; | ||
import { AreaChart } from '@gooddata/react-components'; | ||
|
||
import '@gooddata/react-components/styles/css/main.css'; | ||
import CustomLoading from './utils/CustomLoading'; | ||
import CustomError from './utils/CustomError'; | ||
|
||
import { | ||
projectId, | ||
monthDateIdentifier, | ||
franchiseFeesIdentifier, | ||
franchiseFeesAdRoyaltyIdentifier, | ||
franchiseFeesInitialFranchiseFeeIdentifier, | ||
franchiseFeesIdentifierOngoingRoyalty | ||
} from '../utils/fixtures'; | ||
|
||
export class AreaChartExample extends Component { | ||
onLoadingChanged(...params) { | ||
// eslint-disable-next-line no-console | ||
return console.log('AreaChartExample onLoadingChanged', ...params); | ||
} | ||
|
||
onError(...params) { | ||
// eslint-disable-next-line no-console | ||
return console.log('AreaChartExample onError', ...params); | ||
} | ||
|
||
render() { | ||
const measures = [ | ||
{ | ||
measure: { | ||
localIdentifier: 'franchiseFeesIdentifier', | ||
definition: { | ||
measureDefinition: { | ||
item: { | ||
identifier: franchiseFeesIdentifier | ||
} | ||
} | ||
}, | ||
format: '#,##0' | ||
} | ||
}, | ||
{ | ||
measure: { | ||
localIdentifier: 'franchiseFeesAdRoyaltyIdentifier', | ||
definition: { | ||
measureDefinition: { | ||
item: { | ||
identifier: franchiseFeesAdRoyaltyIdentifier | ||
} | ||
} | ||
}, | ||
format: '#,##0' | ||
} | ||
}, | ||
{ | ||
measure: { | ||
localIdentifier: 'franchiseFeesInitialFranchiseFeeIdentifier', | ||
definition: { | ||
measureDefinition: { | ||
item: { | ||
identifier: franchiseFeesInitialFranchiseFeeIdentifier | ||
} | ||
} | ||
}, | ||
format: '#,##0' | ||
} | ||
}, | ||
{ | ||
measure: { | ||
localIdentifier: 'franchiseFeesIdentifierOngoingRoyalty', | ||
definition: { | ||
measureDefinition: { | ||
item: { | ||
identifier: franchiseFeesIdentifierOngoingRoyalty | ||
} | ||
} | ||
}, | ||
format: '#,##0' | ||
} | ||
} | ||
]; | ||
|
||
const attributes = [ | ||
{ | ||
visualizationAttribute: { | ||
displayForm: { | ||
identifier: monthDateIdentifier | ||
}, | ||
localIdentifier: 'month' | ||
} | ||
} | ||
]; | ||
|
||
return ( | ||
<div style={{ height: 300 }} className="s-area-chart"> | ||
<AreaChart | ||
projectId={projectId} | ||
measures={measures} | ||
viewBy={attributes} | ||
onLoadingChanged={this.onLoadingChanged} | ||
onError={this.onError} | ||
LoadingComponent={CustomLoading} | ||
ErrorComponent={CustomError} | ||
config={{ | ||
stacking: false | ||
}} | ||
/> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default AreaChartExample; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import React, { Component } from 'react'; | ||
import { AreaChart } from '@gooddata/react-components'; | ||
|
||
import '@gooddata/react-components/styles/css/main.css'; | ||
import CustomLoading from './utils/CustomLoading'; | ||
import CustomError from './utils/CustomError'; | ||
|
||
import { | ||
projectId, | ||
monthDateIdentifier, | ||
franchiseFeesIdentifier, | ||
franchiseFeesAdRoyaltyIdentifier, | ||
franchiseFeesInitialFranchiseFeeIdentifier, | ||
franchiseFeesIdentifierOngoingRoyalty | ||
} from '../utils/fixtures'; | ||
|
||
export class StackedAreaChartExample extends Component { | ||
onLoadingChanged(...params) { | ||
// eslint-disable-next-line no-console | ||
return console.log('StackedAreaChartExample onLoadingChanged', ...params); | ||
} | ||
|
||
onError(...params) { | ||
// eslint-disable-next-line no-console | ||
return console.log('StackedAreaChartExample onError', ...params); | ||
} | ||
|
||
render() { | ||
const measures = [ | ||
{ | ||
measure: { | ||
localIdentifier: 'franchiseFeesIdentifier', | ||
definition: { | ||
measureDefinition: { | ||
item: { | ||
identifier: franchiseFeesIdentifier | ||
} | ||
} | ||
}, | ||
format: '#,##0' | ||
} | ||
}, | ||
{ | ||
measure: { | ||
localIdentifier: 'franchiseFeesAdRoyaltyIdentifier', | ||
definition: { | ||
measureDefinition: { | ||
item: { | ||
identifier: franchiseFeesAdRoyaltyIdentifier | ||
} | ||
} | ||
}, | ||
format: '#,##0' | ||
} | ||
}, | ||
{ | ||
measure: { | ||
localIdentifier: 'franchiseFeesInitialFranchiseFeeIdentifier', | ||
definition: { | ||
measureDefinition: { | ||
item: { | ||
identifier: franchiseFeesInitialFranchiseFeeIdentifier | ||
} | ||
} | ||
}, | ||
format: '#,##0' | ||
} | ||
}, | ||
{ | ||
measure: { | ||
localIdentifier: 'franchiseFeesIdentifierOngoingRoyalty', | ||
definition: { | ||
measureDefinition: { | ||
item: { | ||
identifier: franchiseFeesIdentifierOngoingRoyalty | ||
} | ||
} | ||
}, | ||
format: '#,##0' | ||
} | ||
} | ||
]; | ||
|
||
const attributes = [ | ||
{ | ||
visualizationAttribute: { | ||
displayForm: { | ||
identifier: monthDateIdentifier | ||
}, | ||
localIdentifier: 'month' | ||
} | ||
} | ||
]; | ||
|
||
return ( | ||
<div style={{ height: 300 }} className="s-area-chart"> | ||
<AreaChart | ||
projectId={projectId} | ||
measures={measures} | ||
viewBy={attributes} | ||
onLoadingChanged={this.onLoadingChanged} | ||
onError={this.onError} | ||
LoadingComponent={CustomLoading} | ||
ErrorComponent={CustomError} | ||
config={{ | ||
stacking: true | ||
}} | ||
/> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default StackedAreaChartExample; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import * as React from 'react'; | ||
import { omit, get } from 'lodash'; | ||
import { Subtract } from 'utility-types'; | ||
import { VisualizationObject, AFM } from '@gooddata/typings'; | ||
|
||
import { AreaChart as AfmAreaChart } from './afm/AreaChart'; | ||
|
||
import { ICommonChartProps } from './core/base/BaseChart'; | ||
import { convertBucketsToAFM } from '../helpers/conversion'; | ||
import { generateStackedDimensions } from '../helpers/dimensions'; | ||
import { isStackedChart } from '../helpers/stacks'; | ||
|
||
export interface IAreaChartBucketProps extends ICommonChartProps { | ||
measures: VisualizationObject.BucketItem[]; | ||
viewBy?: VisualizationObject.IVisualizationAttribute[]; | ||
stackBy?: VisualizationObject.IVisualizationAttribute[]; | ||
filters?: VisualizationObject.VisualizationObjectFilter[]; | ||
} | ||
|
||
export interface IAreaChartProps extends ICommonChartProps, IAreaChartBucketProps { | ||
projectId: string; | ||
} | ||
|
||
type IAreaChartNonBucketProps = Subtract<IAreaChartProps, IAreaChartBucketProps>; | ||
|
||
export interface IAreaChartProps extends ICommonChartProps { | ||
projectId: string; | ||
} | ||
|
||
function generateDefaultDimensions(afm: AFM.IAfm): AFM.IDimension[] { | ||
return [ | ||
{ | ||
itemIdentifiers: ['measureGroup'] | ||
}, | ||
{ | ||
itemIdentifiers: get(afm, 'attributes', []).map(a => a.localIdentifier) | ||
} | ||
]; | ||
} | ||
|
||
function getStackingResultSpec(buckets: VisualizationObject.IBucket[]): AFM.IResultSpec { | ||
if (isStackedChart(buckets)) { | ||
return { | ||
dimensions: generateStackedDimensions(buckets) | ||
}; | ||
} | ||
|
||
return { | ||
dimensions: generateDefaultDimensions(convertBucketsToAFM(buckets)) | ||
}; | ||
} | ||
|
||
export function AreaChart(props: IAreaChartProps): JSX.Element { | ||
const buckets: VisualizationObject.IBucket[] = [ | ||
{ | ||
localIdentifier: 'measures', | ||
items: get(props, 'measures', []) | ||
}, | ||
{ | ||
localIdentifier: 'attributes', | ||
items: get(props, 'viewBy', []) | ||
}, | ||
{ | ||
localIdentifier: 'stacks', | ||
items: get(props, 'stackBy', []) | ||
} | ||
]; | ||
|
||
const newProps | ||
= omit<IAreaChartProps, IAreaChartNonBucketProps>(props, ['measures', 'viewBy', 'stackBy', 'filters']); | ||
|
||
return ( | ||
<AfmAreaChart | ||
{...newProps} | ||
projectId={props.projectId} | ||
afm={convertBucketsToAFM(buckets, props.filters)} | ||
resultSpec={getStackingResultSpec(buckets)} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// (C) 2007-2018 GoodData Corporation | ||
import { | ||
dataSourceProvider, | ||
IDataSourceProviderProps | ||
} from './DataSourceProvider'; | ||
|
||
export { | ||
IDataSourceProviderProps | ||
}; | ||
|
||
import { ICommonChartProps } from '../core/base/BaseChart'; | ||
import { AreaChart as CoreAreaChart } from '../core/AreaChart'; | ||
import { generateDefaultDimensions } from './afmHelper'; | ||
|
||
export const AreaChart = dataSourceProvider<ICommonChartProps>(CoreAreaChart, generateDefaultDimensions, 'AreaChart'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.