This repository has been archived by the owner on Jul 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(number of libraries): add pie char for number of libraries used
- Loading branch information
Raphaël Benitte
committed
Dec 3, 2017
1 parent
c19a10f
commit c0fa423
Showing
32 changed files
with
561 additions
and
132 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
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
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,65 @@ | ||
import React, { Component } from 'react' | ||
import PropTypes from 'prop-types' | ||
import { ResponsivePie } from 'nivo' | ||
import { scaleLinear } from 'd3-scale' | ||
|
||
const margin = { | ||
top: 40, | ||
right: 100, | ||
bottom: 40, | ||
left: 100, | ||
} | ||
|
||
const getSliceLabel = d => { | ||
if (d.id === '0') return 'none' | ||
if (d.id === '1') return 'one lib' | ||
return `${d.id} libs` | ||
} | ||
|
||
const getRadialLabel = d => { | ||
if (d.id === '0') return 'Satisfied with none of them' | ||
if (d.id === '1') return 'Only using one library' | ||
return `Using ${d.id} libraries` | ||
} | ||
|
||
export default class NumbersOfLibrariesPie extends Component { | ||
static propTypes = { | ||
keys: PropTypes.arrayOf(PropTypes.string.isRequired).isRequired, | ||
data: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
key: PropTypes.number.isRequired, | ||
doc_count: PropTypes.number.isRequired, | ||
}) | ||
).isRequired, | ||
} | ||
|
||
render() { | ||
const { keys, data } = this.props | ||
|
||
const colorScale = scaleLinear() | ||
.domain([0, 1, keys.length]) | ||
.range(['#dadada', '#9688e4', '#ea2149']) | ||
|
||
const getColor = ({ id }) => colorScale(Number(id)) | ||
|
||
return ( | ||
<ResponsivePie | ||
data={data.map(({ key, doc_count }) => ({ | ||
id: `${key}`, | ||
label: `${key}`, | ||
value: doc_count, | ||
}))} | ||
colorBy={getColor} | ||
margin={margin} | ||
innerRadius={0.6} | ||
padAngle={0.6} | ||
cornerRadius={3} | ||
radialLabelsSkipAngle={10} | ||
radialLabel={getRadialLabel} | ||
radialLabelsLinkColor="inherit" | ||
slicesLabelsSkipAngle={10} | ||
sliceLabel={getSliceLabel} | ||
/> | ||
) | ||
} | ||
} |
Oops, something went wrong.