-
-
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.
- Loading branch information
Raphaël Benitte
committed
Dec 7, 2017
1 parent
6ed2289
commit 56c5f99
Showing
12 changed files
with
883 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# src (will be transpiled) | ||
/src | ||
|
||
# logs | ||
*.log* | ||
|
||
# OSX | ||
.DS_Store | ||
|
||
# config/build | ||
.babelrc | ||
|
||
# storybook | ||
/.storybook | ||
/stories | ||
/storybook-static | ||
|
||
# test | ||
/coverage | ||
/tests |
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,37 @@ | ||
{ | ||
"name": "@nivo/legends", | ||
"version": "0.32.0", | ||
"license": "MIT", | ||
"main": "./lib/index.js", | ||
"module": "es/index.js", | ||
"jsnext:main": "es/index.js", | ||
"dependencies": { | ||
"recompose": "^0.26.0" | ||
}, | ||
"devDependencies": { | ||
"@nivo/babel-preset": "0.32.0", | ||
"babel-cli": "^6.26.0", | ||
"babel-jest": "^20.0.3", | ||
"cross-env": "^5.0.5", | ||
"jest": "^21.0.1", | ||
"react": "^15.6.1", | ||
"react-dom": "^15.6.1", | ||
"react-test-renderer": "^15.6.1" | ||
}, | ||
"peerDependencies": { | ||
"prop-types": "^15.5.10", | ||
"react": ">= 15.6.1 < 17.0.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"scripts": { | ||
"test": "jest --verbose ./tests", | ||
"test:cover": "jest --verbose --coverage ./tests", | ||
"build:commonjs": "rm -rf lib && cross-env NODE_ENV=commonjs babel src --out-dir lib", | ||
"build:commonjs:watch": "npm run build:commonjs -- --watch", | ||
"build:es": "rm -rf es && cross-env NODE_ENV=es babel src --out-dir es", | ||
"build:es:watch": "npm run build:es -- --watch", | ||
"build": "npm run build:commonjs && npm run build:es" | ||
} | ||
} |
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,24 @@ | ||
/* | ||
* 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. | ||
*/ | ||
export const DIRECTION_ROW = 'row' | ||
export const DIRECTION_COLUMN = 'column' | ||
|
||
export const ANCHOR_TOP = 'top' | ||
export const ANCHOR_TOP_RIGHT = 'top-right' | ||
export const ANCHOR_RIGHT = 'right' | ||
export const ANCHOR_BOTTOM_RIGHT = 'bottom-right' | ||
export const ANCHOR_BOTTOM = 'bottom' | ||
export const ANCHOR_BOTTOM_LEFT = 'bottom-left' | ||
export const ANCHOR_LEFT = 'left' | ||
export const ANCHOR_TOP_LEFT = 'top-left' | ||
|
||
export const DIRECTION_LEFT_TO_RIGHT = 'left-to-right' | ||
export const DIRECTION_RIGHT_TO_LEFT = 'right-to-left' | ||
export const DIRECTION_TOP_TO_BOTTOM = 'top-to-bottom' | ||
export const DIRECTION_BOTTOM_TO_TOP = 'bottom-to-top' |
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,9 @@ | ||
/* | ||
* 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. | ||
*/ | ||
export * from './svg' |
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,141 @@ | ||
/* | ||
* 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 React from 'react' | ||
import PropTypes from 'prop-types' | ||
import LegendSvg from './LegendSvg' | ||
import { | ||
DIRECTION_ROW, | ||
DIRECTION_COLUMN, | ||
DIRECTION_BOTTOM_TO_TOP, | ||
DIRECTION_LEFT_TO_RIGHT, | ||
DIRECTION_RIGHT_TO_LEFT, | ||
DIRECTION_TOP_TO_BOTTOM, | ||
ANCHOR_TOP, | ||
ANCHOR_TOP_RIGHT, | ||
ANCHOR_RIGHT, | ||
ANCHOR_BOTTOM_RIGHT, | ||
ANCHOR_BOTTOM, | ||
ANCHOR_BOTTOM_LEFT, | ||
ANCHOR_LEFT, | ||
ANCHOR_TOP_LEFT, | ||
} from '../constants' | ||
|
||
const BoxLegendSvg = ({ | ||
data, | ||
|
||
containerWidth, | ||
containerHeight, | ||
anchor, | ||
direction, | ||
justify, | ||
|
||
itemWidth, | ||
itemHeight, | ||
itemDirection, | ||
itemsSpacing, | ||
symbolSize, | ||
symbolSpacing, | ||
}) => { | ||
let x = 0 | ||
let y = 0 | ||
|
||
let width = itemWidth | ||
let height = itemHeight | ||
if (direction === DIRECTION_ROW) { | ||
width = itemWidth * data.length | ||
} else if (direction === DIRECTION_COLUMN) { | ||
height = itemHeight * data.length | ||
} | ||
|
||
switch (anchor) { | ||
case ANCHOR_TOP: | ||
x = (containerWidth - width) / 2 | ||
break | ||
|
||
case ANCHOR_TOP_RIGHT: | ||
x = containerWidth - width | ||
break | ||
|
||
case ANCHOR_RIGHT: | ||
x = containerWidth - width | ||
y = (containerHeight - height) / 2 | ||
break | ||
|
||
case ANCHOR_BOTTOM_RIGHT: | ||
x = containerWidth - width | ||
y = containerHeight - height | ||
break | ||
|
||
case ANCHOR_BOTTOM: | ||
x = (containerWidth - width) / 2 | ||
y = containerHeight - height | ||
break | ||
|
||
case ANCHOR_BOTTOM_LEFT: | ||
y = containerHeight - height | ||
break | ||
|
||
case ANCHOR_LEFT: | ||
y = (containerHeight - height) / 2 | ||
break | ||
} | ||
|
||
return ( | ||
<LegendSvg | ||
data={data} | ||
x={x} | ||
y={y} | ||
width={width} | ||
height={height} | ||
direction={direction} | ||
justify={justify} | ||
itemWidth={itemWidth} | ||
itemHeight={itemHeight} | ||
itemDirection={itemDirection} | ||
itemsSpacing={itemsSpacing} | ||
symbolSize={symbolSize} | ||
symbolSpacing={symbolSpacing} | ||
/> | ||
) | ||
} | ||
|
||
BoxLegendSvg.propTypes = { | ||
containerWidth: PropTypes.number.isRequired, | ||
containerHeight: PropTypes.number.isRequired, | ||
anchor: PropTypes.oneOf([ | ||
ANCHOR_TOP, | ||
ANCHOR_TOP_RIGHT, | ||
ANCHOR_RIGHT, | ||
ANCHOR_BOTTOM_RIGHT, | ||
ANCHOR_BOTTOM, | ||
ANCHOR_BOTTOM_LEFT, | ||
ANCHOR_LEFT, | ||
ANCHOR_TOP_LEFT, | ||
]).isRequired, | ||
direction: PropTypes.oneOf([DIRECTION_ROW, DIRECTION_COLUMN]).isRequired, | ||
justify: PropTypes.bool, | ||
|
||
itemWidth: PropTypes.number.isRequired, | ||
itemHeight: PropTypes.number.isRequired, | ||
itemDirection: PropTypes.oneOf([ | ||
DIRECTION_LEFT_TO_RIGHT, | ||
DIRECTION_RIGHT_TO_LEFT, | ||
DIRECTION_TOP_TO_BOTTOM, | ||
DIRECTION_BOTTOM_TO_TOP, | ||
]), | ||
itemsSpacing: PropTypes.number.isRequired, | ||
symbolSize: PropTypes.number, | ||
symbolSpacing: PropTypes.number, | ||
} | ||
|
||
BoxLegendSvg.defaultProps = { | ||
itemsSpacing: 0, | ||
} | ||
|
||
export default BoxLegendSvg |
Oops, something went wrong.