-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bar): adjust legend data according to layout/mode/reverse
- Loading branch information
Raphaël Benitte
authored and
Raphaël Benitte
committed
Mar 21, 2019
1 parent
4568516
commit 0c0a6a1
Showing
4 changed files
with
175 additions
and
30 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
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 |
---|---|---|
|
@@ -8,3 +8,4 @@ | |
*/ | ||
export * from './grouped' | ||
export * from './stacked' | ||
export * from './legends' |
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,50 @@ | ||
/* | ||
* This file is part of the nivo project. | ||
* | ||
* Copyright 2016-present, Raphaël Benitte. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
import { uniqBy } from 'lodash' | ||
|
||
export const getLegendDataForKeys = (bars, layout, groupMode, reverse) => { | ||
const data = uniqBy( | ||
bars.map(bar => ({ | ||
id: bar.data.id, | ||
label: bar.data.id, | ||
color: bar.color, | ||
fill: bar.data.fill, | ||
})), | ||
({ id }) => id | ||
) | ||
|
||
if ( | ||
(layout === 'vertical' && groupMode === 'stacked' && reverse !== true) || | ||
(layout === 'horizontal' && groupMode === 'stacked' && reverse === true) | ||
) { | ||
data.reverse() | ||
} | ||
|
||
return data | ||
} | ||
|
||
export const getLegendDataForIndexes = bars => { | ||
return uniqBy( | ||
bars.map(bar => ({ | ||
id: bar.data.indexValue, | ||
label: bar.data.indexValue, | ||
color: bar.color, | ||
fill: bar.data.fill, | ||
})), | ||
({ id }) => id | ||
) | ||
} | ||
|
||
export const getLegendData = ({ from, bars, layout, groupMode, reverse }) => { | ||
if (from === 'indexes') { | ||
return getLegendDataForIndexes(bars) | ||
} | ||
|
||
return getLegendDataForKeys(bars, layout, groupMode, reverse) | ||
} |
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