-
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.
RELATED: ONE-3355 Pass provided colorPalette to the charts
- Loading branch information
1 parent
6205f6d
commit 8e968fd
Showing
8 changed files
with
175 additions
and
25 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,101 @@ | ||
// (C) 2007-2018 GoodData Corporation | ||
import React, { Component } from 'react'; | ||
import { BarChart } from '@gooddata/react-components'; | ||
|
||
import '@gooddata/react-components/styles/css/main.css'; | ||
|
||
import { | ||
totalSalesIdentifier, | ||
locationResortIdentifier, | ||
menuCategoryAttributeDFIdentifier, | ||
projectId | ||
} from '../utils/fixtures'; | ||
import { CUSTOM_COLOR_PALETTE } from '../utils/colors'; | ||
|
||
const defaultProperties = {}; | ||
|
||
export class BarChartDynamicExample extends Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
config: defaultProperties, | ||
customPaletteUsed: false | ||
}; | ||
this.onPaletteChange = this.onPaletteChange.bind(this); | ||
} | ||
|
||
onPaletteChange() { | ||
const { | ||
config: currentConfig, | ||
customPaletteUsed | ||
} = this.state; | ||
const colorPaletteProp = { | ||
colorPalette: customPaletteUsed ? undefined : CUSTOM_COLOR_PALETTE | ||
}; | ||
this.setState({ | ||
config: { | ||
...currentConfig, | ||
...colorPaletteProp | ||
}, | ||
customPaletteUsed: !customPaletteUsed | ||
}); | ||
} | ||
|
||
render() { | ||
const { | ||
config | ||
} = this.state; | ||
|
||
const amount = { | ||
measure: { | ||
localIdentifier: 'amount', | ||
definition: { | ||
measureDefinition: { | ||
item: { | ||
identifier: totalSalesIdentifier | ||
} | ||
} | ||
}, | ||
alias: '$ Total Sales', | ||
format: '#,##0' | ||
} | ||
}; | ||
|
||
const locationResort = { | ||
visualizationAttribute: { | ||
displayForm: { | ||
identifier: locationResortIdentifier | ||
}, | ||
localIdentifier: 'location_resort' | ||
} | ||
}; | ||
|
||
const menuCategory = { | ||
visualizationAttribute: { | ||
displayForm: { | ||
identifier: menuCategoryAttributeDFIdentifier | ||
}, | ||
localIdentifier: 'label.menuitem.menucategory' | ||
} | ||
}; | ||
return ( | ||
<div> | ||
<button onClick={this.onPaletteChange}> | ||
Change palette | ||
</button> | ||
<div style={{ height: 300 }} className="s-bar-chart"> | ||
<BarChart | ||
projectId={projectId} | ||
measures={[amount]} | ||
viewBy={locationResort} | ||
stackBy={menuCategory} | ||
config={config} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default BarChartDynamicExample; |
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
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,19 @@ | ||
// (C) 2007-2018 GoodData Corporation | ||
import React from 'react'; | ||
import ExampleWithSource from '../components/utils/ExampleWithSource'; | ||
|
||
import BarChartDynamicExample from '../components/BarChartDynamicExample'; | ||
import BarChartDynamicExampleSRC from '!raw-loader!../components/BarChartDynamicExample'; // eslint-disable-line | ||
|
||
|
||
export const BarChartDynamic = () => ( | ||
<div> | ||
<h1>Bar Chart with dynamic colors example</h1> | ||
|
||
<hr className="separator" /> | ||
|
||
<ExampleWithSource for={BarChartDynamicExample} source={BarChartDynamicExampleSRC} /> | ||
</div> | ||
); | ||
|
||
export default BarChartDynamic; |
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