@nivo/legends
Advanced tools
Comparing version 0.34.0-1 to 0.35.0
@@ -7,16 +7,7 @@ 'use strict'; | ||
var lodash = require('lodash'); | ||
var React = require('react'); | ||
var React__default = _interopDefault(React); | ||
var PropTypes = _interopDefault(require('prop-types')); | ||
var lodash = require('lodash'); | ||
var max = _interopDefault(require('lodash/max')); | ||
/* | ||
* 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. | ||
*/ | ||
var DIRECTION_ROW = 'row'; | ||
@@ -35,16 +26,2 @@ var DIRECTION_COLUMN = 'column'; | ||
var POSITION_TOP = 'top'; | ||
var POSITION_RIGHT = 'right'; | ||
var POSITION_BOTTOM = 'bottom'; | ||
var POSITION_LEFT = 'left'; | ||
var DIRECTION_TOP_LEFT = 'top-left'; | ||
var DIRECTION_TOP_RIGHT = 'top-right'; | ||
var DIRECTION_RIGHT_TOP = 'right-top'; | ||
var DIRECTION_RIGHT_BOTTOM = 'right-bottom'; | ||
var DIRECTION_BOTTOM_LEFT = 'bottom-left'; | ||
var DIRECTION_BOTTOM_RIGHT = 'bottom-right'; | ||
var DIRECTION_LEFT_TOP = 'left-top'; | ||
var DIRECTION_LEFT_BOTTOM = 'left-bottom'; | ||
var DIRECTION_LEFT_TO_RIGHT = 'left-to-right'; | ||
@@ -55,5 +32,2 @@ var DIRECTION_RIGHT_TO_LEFT = 'right-to-left'; | ||
var SHAPE_SQUARE = 'square'; | ||
var SHAPE_CIRCLE = 'circle'; | ||
var classCallCheck = function (instance, Constructor) { | ||
@@ -123,10 +97,2 @@ if (!(instance instanceof Constructor)) { | ||
/* | ||
* 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. | ||
*/ | ||
var zeroPadding = { | ||
@@ -318,10 +284,2 @@ top: 0, | ||
/* | ||
* 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. | ||
*/ | ||
var SymbolCircle = function SymbolCircle(_ref) { | ||
@@ -342,10 +300,2 @@ var x = _ref.x, | ||
/* | ||
* 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. | ||
*/ | ||
var SymbolDiamond = function SymbolDiamond(_ref) { | ||
@@ -374,10 +324,2 @@ var x = _ref.x, | ||
/* | ||
* 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. | ||
*/ | ||
var SymbolSquare = function SymbolSquare(_ref) { | ||
@@ -398,10 +340,2 @@ var x = _ref.x, | ||
/* | ||
* 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. | ||
*/ | ||
var SymbolTriangle = function SymbolTriangle(_ref) { | ||
@@ -429,19 +363,2 @@ var x = _ref.x, | ||
/* | ||
* 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. | ||
*/ | ||
/* | ||
* 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. | ||
*/ | ||
var symbolByShape = { | ||
@@ -473,2 +390,3 @@ circle: SymbolCircle, | ||
fill = _props.fill, | ||
textColor = _props.textColor, | ||
direction = _props.direction, | ||
@@ -502,3 +420,3 @@ justify = _props.justify; | ||
textAnchor: labelAnchor, | ||
style: { fill: 'black', alignmentBaseline: labelAlignment }, | ||
style: { fill: textColor, alignmentBaseline: labelAlignment }, | ||
x: labelX, | ||
@@ -527,2 +445,3 @@ y: labelY | ||
fill: PropTypes.string.isRequired, | ||
textColor: PropTypes.string.isRequired, | ||
@@ -540,10 +459,2 @@ direction: PropTypes.oneOf([DIRECTION_LEFT_TO_RIGHT, DIRECTION_RIGHT_TO_LEFT, DIRECTION_TOP_TO_BOTTOM, DIRECTION_BOTTOM_TO_TOP]).isRequired, | ||
/* | ||
* 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. | ||
*/ | ||
var LegendSvg = function LegendSvg(_ref) { | ||
@@ -562,3 +473,4 @@ var data = _ref.data, | ||
symbolSpacing = _ref.symbolSpacing, | ||
symbolShape = _ref.symbolShape; | ||
symbolShape = _ref.symbolShape, | ||
textColor = _ref.textColor; | ||
@@ -604,3 +516,4 @@ // eslint-disable-next-line no-unused-vars | ||
label: label, | ||
fill: fill | ||
fill: fill, | ||
textColor: textColor | ||
}); | ||
@@ -636,3 +549,4 @@ }) | ||
symbolSpacing: PropTypes.number, | ||
symbolShape: PropTypes.oneOfType([PropTypes.string, PropTypes.func]) | ||
symbolShape: PropTypes.oneOfType([PropTypes.string, PropTypes.func]), | ||
textColor: PropTypes.string.isRequired | ||
}; | ||
@@ -647,13 +561,6 @@ | ||
itemDirection: DIRECTION_LEFT_TO_RIGHT, | ||
itemsSpacing: 0 | ||
itemsSpacing: 0, | ||
textColor: 'black' | ||
}; | ||
/* | ||
* 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. | ||
*/ | ||
var BoxLegendSvg = function BoxLegendSvg(_ref) { | ||
@@ -675,3 +582,4 @@ var data = _ref.data, | ||
symbolSpacing = _ref.symbolSpacing, | ||
symbolShape = _ref.symbolShape; | ||
symbolShape = _ref.symbolShape, | ||
textColor = _ref.textColor; | ||
@@ -714,3 +622,4 @@ var _computeDimensions = computeDimensions({ | ||
symbolSpacing: symbolSpacing, | ||
symbolShape: symbolShape | ||
symbolShape: symbolShape, | ||
textColor: textColor | ||
}); | ||
@@ -744,3 +653,4 @@ }; | ||
symbolSpacing: PropTypes.number, | ||
symbolShape: PropTypes.oneOfType([PropTypes.string, PropTypes.func]) | ||
symbolShape: PropTypes.oneOfType([PropTypes.string, PropTypes.func]), | ||
textColor: PropTypes.string | ||
}; | ||
@@ -755,922 +665,2 @@ | ||
/* | ||
* 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. | ||
*/ | ||
var SizeLegendSvg = function SizeLegendSvg(_ref) { | ||
var x = _ref.x, | ||
y = _ref.y, | ||
anchor = _ref.anchor, | ||
linkLength = _ref.linkLength, | ||
labelPosition = _ref.labelPosition, | ||
labelOffset = _ref.labelOffset, | ||
shape = _ref.shape; | ||
var data = [{ | ||
size: 120 | ||
}, { | ||
size: 90 | ||
}, { | ||
size: 50 | ||
}]; | ||
var maxShape = data[0]; | ||
var maxSize = max(data.map(function (d) { | ||
return d.size; | ||
})); | ||
var shapes = void 0; | ||
var links = []; | ||
var labels = []; | ||
var alignmentBaseline = void 0; | ||
var textAnchor = void 0; | ||
switch (labelPosition) { | ||
case POSITION_TOP: | ||
alignmentBaseline = 'baseline'; | ||
textAnchor = 'middle'; | ||
break; | ||
case POSITION_RIGHT: | ||
alignmentBaseline = 'central'; | ||
textAnchor = 'start'; | ||
break; | ||
case POSITION_LEFT: | ||
alignmentBaseline = 'central'; | ||
textAnchor = 'end'; | ||
break; | ||
case POSITION_BOTTOM: | ||
alignmentBaseline = 'hanging'; | ||
textAnchor = 'middle'; | ||
} | ||
switch (anchor) { | ||
case ANCHOR_TOP_LEFT: | ||
shapes = data.map(function (d) { | ||
return { | ||
x: 0, | ||
y: 0, | ||
size: d.size | ||
}; | ||
}); | ||
switch (labelPosition) { | ||
case POSITION_RIGHT: | ||
links = shapes.map(function (s) { | ||
return { | ||
source: { | ||
x: shape === SHAPE_SQUARE ? s.size : s.size / 2, | ||
y: s.y + s.size | ||
}, | ||
target: { | ||
x: maxSize - s.x + linkLength, | ||
y: s.y + s.size | ||
} | ||
}; | ||
}); | ||
labels = links.map(function (link, i) { | ||
return { | ||
x: link.target.x + labelOffset, | ||
y: link.target.y, | ||
label: i | ||
}; | ||
}); | ||
break; | ||
case POSITION_LEFT: | ||
links = shapes.map(function (s) { | ||
return { | ||
source: { | ||
x: shape === SHAPE_SQUARE ? 0 : s.size / 2, | ||
y: s.y + s.size | ||
}, | ||
target: { | ||
x: -linkLength, | ||
y: s.y + s.size | ||
} | ||
}; | ||
}); | ||
labels = links.map(function (link, i) { | ||
return { | ||
x: link.target.x - labelOffset, | ||
y: link.target.y, | ||
label: i | ||
}; | ||
}); | ||
break; | ||
case POSITION_BOTTOM: | ||
links = shapes.map(function (s) { | ||
return { | ||
source: { | ||
x: s.size, | ||
y: shape === SHAPE_SQUARE ? s.size : s.size / 2 | ||
}, | ||
target: { | ||
x: s.size, | ||
y: maxSize + linkLength | ||
} | ||
}; | ||
}); | ||
labels = links.map(function (link, i) { | ||
return { | ||
x: link.target.x, | ||
y: link.target.y + labelOffset, | ||
label: i | ||
}; | ||
}); | ||
break; | ||
case POSITION_TOP: | ||
links = shapes.map(function (s) { | ||
return { | ||
source: { | ||
x: s.size, | ||
y: shape === SHAPE_SQUARE ? 0 : s.size / 2 | ||
}, | ||
target: { | ||
x: s.size, | ||
y: -linkLength | ||
} | ||
}; | ||
}); | ||
labels = links.map(function (link, i) { | ||
return { | ||
x: link.target.x, | ||
y: link.target.y - labelOffset, | ||
label: i | ||
}; | ||
}); | ||
break; | ||
} | ||
break; | ||
case ANCHOR_TOP: | ||
shapes = data.map(function (d) { | ||
return { | ||
x: (maxShape.size - d.size) / 2, | ||
y: 0, | ||
size: d.size | ||
}; | ||
}); | ||
switch (labelPosition) { | ||
case POSITION_RIGHT: | ||
links = shapes.map(function (s) { | ||
return { | ||
source: { | ||
x: shape === SHAPE_SQUARE ? s.x + s.size : s.x + s.size / 2, | ||
y: s.size | ||
}, | ||
target: { | ||
x: maxSize + linkLength, | ||
y: s.size | ||
} | ||
}; | ||
}); | ||
labels = links.map(function (link, i) { | ||
return { | ||
x: link.target.x + labelOffset, | ||
y: link.target.y, | ||
label: i | ||
}; | ||
}); | ||
break; | ||
case POSITION_LEFT: | ||
links = shapes.map(function (s) { | ||
return { | ||
source: { | ||
x: shape === SHAPE_SQUARE ? s.x : maxSize / 2, | ||
y: s.size | ||
}, | ||
target: { | ||
x: -linkLength, | ||
y: s.size | ||
} | ||
}; | ||
}); | ||
labels = links.map(function (link, i) { | ||
return { | ||
x: link.target.x - labelOffset, | ||
y: link.target.y, | ||
label: i | ||
}; | ||
}); | ||
break; | ||
case POSITION_BOTTOM: | ||
links = shapes.map(function (s) { | ||
return { | ||
source: { | ||
x: s.x + s.size, | ||
y: shape === SHAPE_SQUARE ? s.size : s.size / 2 | ||
}, | ||
target: { | ||
x: s.x + s.size, | ||
y: maxSize + linkLength | ||
} | ||
}; | ||
}); | ||
labels = links.map(function (link, i) { | ||
return { | ||
x: link.target.x, | ||
y: link.target.y + labelOffset, | ||
label: i | ||
}; | ||
}); | ||
break; | ||
case POSITION_TOP: | ||
links = shapes.map(function (s) { | ||
return { | ||
source: { | ||
x: s.x + s.size, | ||
y: shape === SHAPE_SQUARE ? 0 : s.size / 2 | ||
}, | ||
target: { | ||
x: s.x + s.size, | ||
y: -linkLength | ||
} | ||
}; | ||
}); | ||
labels = links.map(function (link, i) { | ||
return { | ||
x: link.target.x, | ||
y: link.target.y - labelOffset, | ||
label: i | ||
}; | ||
}); | ||
break; | ||
} | ||
break; | ||
case ANCHOR_TOP_RIGHT: | ||
shapes = data.map(function (d) { | ||
return { | ||
x: maxShape.size - d.size, | ||
y: 0, | ||
size: d.size | ||
}; | ||
}); | ||
switch (labelPosition) { | ||
case POSITION_RIGHT: | ||
links = shapes.map(function (s) { | ||
return { | ||
source: { | ||
x: shape === SHAPE_SQUARE ? maxSize : s.x + s.size / 2, | ||
y: s.size | ||
}, | ||
target: { | ||
x: s.x + s.size + linkLength, | ||
y: s.size | ||
} | ||
}; | ||
}); | ||
labels = links.map(function (link, i) { | ||
return { | ||
x: link.target.x + labelOffset, | ||
y: link.target.y, | ||
label: i | ||
}; | ||
}); | ||
break; | ||
case POSITION_LEFT: | ||
links = shapes.map(function (s) { | ||
return { | ||
source: { | ||
x: shape === SHAPE_SQUARE ? s.x : s.x + s.size / 2, | ||
y: s.size | ||
}, | ||
target: { | ||
x: -linkLength, | ||
y: s.size | ||
} | ||
}; | ||
}); | ||
labels = links.map(function (link, i) { | ||
return { | ||
x: link.target.x - labelOffset, | ||
y: link.target.y, | ||
label: i | ||
}; | ||
}); | ||
break; | ||
case POSITION_BOTTOM: | ||
links = shapes.map(function (s) { | ||
return { | ||
source: { | ||
x: s.x, | ||
y: shape === SHAPE_SQUARE ? s.size : s.size / 2 | ||
}, | ||
target: { | ||
x: s.x, | ||
y: maxSize + linkLength | ||
} | ||
}; | ||
}); | ||
labels = links.map(function (link, i) { | ||
return { | ||
x: link.target.x, | ||
y: link.target.y + labelOffset, | ||
label: i | ||
}; | ||
}); | ||
break; | ||
case POSITION_TOP: | ||
links = shapes.map(function (s) { | ||
return { | ||
source: { | ||
x: s.x, | ||
y: shape === SHAPE_SQUARE ? 0 : s.size / 2 | ||
}, | ||
target: { | ||
x: s.x, | ||
y: -linkLength | ||
} | ||
}; | ||
}); | ||
labels = links.map(function (link, i) { | ||
return { | ||
x: link.target.x, | ||
y: link.target.y - labelOffset, | ||
label: i | ||
}; | ||
}); | ||
break; | ||
} | ||
break; | ||
case ANCHOR_RIGHT: | ||
shapes = data.map(function (d) { | ||
return { | ||
x: maxShape.size - d.size, | ||
y: (maxShape.size - d.size) / 2, | ||
size: d.size | ||
}; | ||
}); | ||
switch (labelPosition) { | ||
case POSITION_RIGHT: | ||
links = shapes.map(function (s) { | ||
return { | ||
source: { | ||
x: shape === SHAPE_SQUARE ? maxSize : s.x + s.size / 2, | ||
y: s.y | ||
}, | ||
target: { | ||
x: s.x + s.size + linkLength, | ||
y: s.y | ||
} | ||
}; | ||
}); | ||
labels = links.map(function (link, i) { | ||
return { | ||
x: link.target.x + labelOffset, | ||
y: link.target.y, | ||
label: i | ||
}; | ||
}); | ||
break; | ||
case POSITION_LEFT: | ||
links = shapes.map(function (s) { | ||
return { | ||
source: { | ||
x: shape === SHAPE_SQUARE ? s.x : s.x + s.size / 2, | ||
y: s.y | ||
}, | ||
target: { | ||
x: -linkLength, | ||
y: s.y | ||
} | ||
}; | ||
}); | ||
labels = links.map(function (link, i) { | ||
return { | ||
x: link.target.x - labelOffset, | ||
y: link.target.y, | ||
label: i | ||
}; | ||
}); | ||
break; | ||
case POSITION_BOTTOM: | ||
links = shapes.map(function (s) { | ||
return { | ||
source: { | ||
x: s.x, | ||
y: shape === SHAPE_SQUARE ? s.y + s.size : s.y + s.size / 2 | ||
}, | ||
target: { | ||
x: s.x, | ||
y: maxSize + linkLength | ||
} | ||
}; | ||
}); | ||
labels = links.map(function (link, i) { | ||
return { | ||
x: link.target.x, | ||
y: link.target.y + labelOffset, | ||
label: i | ||
}; | ||
}); | ||
break; | ||
case POSITION_TOP: | ||
links = shapes.map(function (s) { | ||
return { | ||
source: { | ||
x: s.x, | ||
y: shape === SHAPE_SQUARE ? s.y : s.y + s.size / 2 | ||
}, | ||
target: { | ||
x: s.x, | ||
y: -linkLength | ||
} | ||
}; | ||
}); | ||
labels = links.map(function (link, i) { | ||
return { | ||
x: link.target.x, | ||
y: link.target.y - labelOffset, | ||
label: i | ||
}; | ||
}); | ||
break; | ||
} | ||
break; | ||
case ANCHOR_BOTTOM_RIGHT: | ||
shapes = data.map(function (d) { | ||
return { | ||
x: maxShape.size - d.size, | ||
y: maxShape.size - d.size, | ||
size: d.size | ||
}; | ||
}); | ||
switch (labelPosition) { | ||
case POSITION_RIGHT: | ||
links = shapes.map(function (s) { | ||
return { | ||
source: { | ||
x: shape === SHAPE_SQUARE ? maxSize : s.x + s.size / 2, | ||
y: s.y | ||
}, | ||
target: { | ||
x: s.x + s.size + linkLength, | ||
y: s.y | ||
} | ||
}; | ||
}); | ||
labels = links.map(function (link, i) { | ||
return { | ||
x: link.target.x + labelOffset, | ||
y: link.target.y, | ||
label: i | ||
}; | ||
}); | ||
break; | ||
case POSITION_LEFT: | ||
links = shapes.map(function (s) { | ||
return { | ||
source: { | ||
x: shape === SHAPE_SQUARE ? s.x : s.x + s.size / 2, | ||
y: s.y | ||
}, | ||
target: { | ||
x: -linkLength, | ||
y: s.y | ||
} | ||
}; | ||
}); | ||
labels = links.map(function (link, i) { | ||
return { | ||
x: link.target.x - labelOffset, | ||
y: link.target.y, | ||
label: i | ||
}; | ||
}); | ||
break; | ||
case POSITION_BOTTOM: | ||
links = shapes.map(function (s) { | ||
return { | ||
source: { | ||
x: s.x, | ||
y: shape === SHAPE_SQUARE ? maxSize : maxSize - s.size / 2 | ||
}, | ||
target: { | ||
x: s.x, | ||
y: maxSize + linkLength | ||
} | ||
}; | ||
}); | ||
labels = links.map(function (link, i) { | ||
return { | ||
x: link.target.x, | ||
y: link.target.y + labelOffset, | ||
label: i | ||
}; | ||
}); | ||
break; | ||
case POSITION_TOP: | ||
links = shapes.map(function (s) { | ||
return { | ||
source: { | ||
x: s.x, | ||
y: shape === SHAPE_SQUARE ? s.y : maxSize - s.size / 2 | ||
}, | ||
target: { | ||
x: s.x, | ||
y: -linkLength | ||
} | ||
}; | ||
}); | ||
labels = links.map(function (link, i) { | ||
return { | ||
x: link.target.x, | ||
y: link.target.y - labelOffset, | ||
label: i | ||
}; | ||
}); | ||
break; | ||
} | ||
break; | ||
case ANCHOR_BOTTOM: | ||
shapes = data.map(function (d) { | ||
return { | ||
x: (maxShape.size - d.size) / 2, | ||
y: maxShape.size - d.size, | ||
size: d.size | ||
}; | ||
}); | ||
switch (labelPosition) { | ||
case POSITION_RIGHT: | ||
links = shapes.map(function (s) { | ||
return { | ||
source: { | ||
x: shape === SHAPE_SQUARE ? s.x + s.size : s.x + s.size / 2, | ||
y: s.y | ||
}, | ||
target: { | ||
x: s.x + s.size / 2 + maxSize / 2 + linkLength, | ||
y: s.y | ||
} | ||
}; | ||
}); | ||
labels = links.map(function (link, i) { | ||
return { | ||
x: link.target.x + labelOffset, | ||
y: link.target.y, | ||
label: i | ||
}; | ||
}); | ||
break; | ||
case POSITION_LEFT: | ||
links = shapes.map(function (s) { | ||
return { | ||
source: { | ||
x: shape === SHAPE_SQUARE ? s.x : maxSize / 2, | ||
y: s.y | ||
}, | ||
target: { | ||
x: -linkLength, | ||
y: s.y | ||
} | ||
}; | ||
}); | ||
labels = links.map(function (link, i) { | ||
return { | ||
x: link.target.x - labelOffset, | ||
y: link.target.y, | ||
label: i | ||
}; | ||
}); | ||
break; | ||
case POSITION_BOTTOM: | ||
links = shapes.map(function (s) { | ||
return { | ||
source: { | ||
x: s.x + s.size, | ||
y: shape === SHAPE_SQUARE ? maxSize : maxSize - s.size / 2 | ||
}, | ||
target: { | ||
x: s.x + s.size, | ||
y: maxSize + linkLength | ||
} | ||
}; | ||
}); | ||
labels = links.map(function (link, i) { | ||
return { | ||
x: link.target.x, | ||
y: link.target.y + labelOffset, | ||
label: i | ||
}; | ||
}); | ||
break; | ||
case POSITION_TOP: | ||
links = shapes.map(function (s) { | ||
return { | ||
source: { | ||
x: s.x + s.size, | ||
y: shape === SHAPE_SQUARE ? s.y : maxSize - s.size / 2 | ||
}, | ||
target: { | ||
x: s.x + s.size, | ||
y: -linkLength | ||
} | ||
}; | ||
}); | ||
labels = links.map(function (link, i) { | ||
return { | ||
x: link.target.x, | ||
y: link.target.y - labelOffset, | ||
label: i | ||
}; | ||
}); | ||
break; | ||
} | ||
break; | ||
case ANCHOR_BOTTOM_LEFT: | ||
shapes = data.map(function (d) { | ||
return { | ||
x: 0, | ||
y: maxShape.size - d.size, | ||
size: d.size | ||
}; | ||
}); | ||
switch (labelPosition) { | ||
case POSITION_RIGHT: | ||
links = shapes.map(function (s) { | ||
return { | ||
source: { | ||
x: shape === SHAPE_SQUARE ? s.size : s.x + s.size / 2, | ||
y: s.y | ||
}, | ||
target: { | ||
x: maxSize - s.x + linkLength, | ||
y: s.y | ||
} | ||
}; | ||
}); | ||
labels = links.map(function (link, i) { | ||
return { | ||
x: link.target.x + labelOffset, | ||
y: link.target.y, | ||
label: i | ||
}; | ||
}); | ||
break; | ||
case POSITION_LEFT: | ||
links = shapes.map(function (s) { | ||
return { | ||
source: { | ||
x: shape === SHAPE_SQUARE ? 0 : s.size / 2, | ||
y: s.y | ||
}, | ||
target: { | ||
x: -linkLength, | ||
y: s.y | ||
} | ||
}; | ||
}); | ||
labels = links.map(function (link, i) { | ||
return { | ||
x: link.target.x - labelOffset, | ||
y: link.target.y, | ||
label: i | ||
}; | ||
}); | ||
break; | ||
case POSITION_BOTTOM: | ||
links = shapes.map(function (s) { | ||
return { | ||
source: { | ||
x: s.size, | ||
y: shape === SHAPE_SQUARE ? maxSize : maxSize - s.size / 2 | ||
}, | ||
target: { | ||
x: s.size, | ||
y: maxSize + linkLength | ||
} | ||
}; | ||
}); | ||
labels = links.map(function (link, i) { | ||
return { | ||
x: link.target.x, | ||
y: link.target.y + labelOffset, | ||
label: i | ||
}; | ||
}); | ||
break; | ||
case POSITION_TOP: | ||
links = shapes.map(function (s) { | ||
return { | ||
source: { | ||
x: s.size, | ||
y: shape === SHAPE_SQUARE ? s.y : maxSize - s.size / 2 | ||
}, | ||
target: { | ||
x: s.size, | ||
y: -linkLength | ||
} | ||
}; | ||
}); | ||
labels = links.map(function (link, i) { | ||
return { | ||
x: link.target.x, | ||
y: link.target.y - labelOffset, | ||
label: i | ||
}; | ||
}); | ||
break; | ||
} | ||
break; | ||
case ANCHOR_LEFT: | ||
shapes = data.map(function (d) { | ||
return { | ||
x: 0, | ||
y: (maxShape.size - d.size) / 2, | ||
size: d.size | ||
}; | ||
}); | ||
switch (labelPosition) { | ||
case POSITION_RIGHT: | ||
links = shapes.map(function (s) { | ||
return { | ||
source: { | ||
x: shape === SHAPE_SQUARE ? s.size : s.size / 2, | ||
y: s.y | ||
}, | ||
target: { | ||
x: maxSize - s.x + linkLength, | ||
y: s.y | ||
} | ||
}; | ||
}); | ||
labels = links.map(function (link, i) { | ||
return { | ||
x: link.target.x + labelOffset, | ||
y: link.target.y, | ||
label: i | ||
}; | ||
}); | ||
break; | ||
case POSITION_LEFT: | ||
links = shapes.map(function (s) { | ||
return { | ||
source: { | ||
x: shape === SHAPE_SQUARE ? 0 : s.size / 2, | ||
y: s.y | ||
}, | ||
target: { | ||
x: -linkLength, | ||
y: s.y | ||
} | ||
}; | ||
}); | ||
labels = links.map(function (link, i) { | ||
return { | ||
x: link.target.x - labelOffset, | ||
y: link.target.y, | ||
label: i | ||
}; | ||
}); | ||
break; | ||
case POSITION_BOTTOM: | ||
links = shapes.map(function (s) { | ||
return { | ||
source: { | ||
x: s.size, | ||
y: shape === SHAPE_SQUARE ? s.y + s.size : s.y + s.size / 2 | ||
}, | ||
target: { | ||
x: s.size, | ||
y: maxSize + linkLength | ||
} | ||
}; | ||
}); | ||
labels = links.map(function (link, i) { | ||
return { | ||
x: link.target.x, | ||
y: link.target.y + labelOffset, | ||
label: i | ||
}; | ||
}); | ||
break; | ||
case POSITION_TOP: | ||
links = shapes.map(function (s) { | ||
return { | ||
source: { | ||
x: s.size, | ||
y: shape === SHAPE_SQUARE ? s.y : s.y + s.size / 2 | ||
}, | ||
target: { | ||
x: s.size, | ||
y: -linkLength | ||
} | ||
}; | ||
}); | ||
labels = links.map(function (link, i) { | ||
return { | ||
x: link.target.x, | ||
y: link.target.y - labelOffset, | ||
label: i | ||
}; | ||
}); | ||
break; | ||
} | ||
break; | ||
} | ||
return React__default.createElement( | ||
'g', | ||
{ transform: 'translate(' + x + ',' + y + ')' }, | ||
shape === 'circle' && shapes.map(function (s, i) { | ||
return React__default.createElement('circle', { | ||
key: i, | ||
r: s.size / 2, | ||
cx: s.x + s.size / 2, | ||
cy: s.y + s.size / 2, | ||
fill: 'none', | ||
strokeDasharray: '3 6', | ||
stroke: 'black' | ||
}); | ||
}), | ||
shape === 'square' && shapes.map(function (s, i) { | ||
return React__default.createElement('rect', { | ||
key: i, | ||
x: s.x, | ||
y: s.y, | ||
width: s.size, | ||
height: s.size, | ||
fill: 'none', | ||
strokeDasharray: '3 6', | ||
stroke: 'black' | ||
}); | ||
}), | ||
links.map(function (link, i) { | ||
return React__default.createElement( | ||
React.Fragment, | ||
{ key: i }, | ||
React__default.createElement('line', { | ||
stroke: 'black', | ||
x1: link.source.x, | ||
y1: link.source.y, | ||
x2: link.target.x, | ||
y2: link.target.y | ||
}), | ||
React__default.createElement('circle', { fill: 'black', r: 2, cx: link.source.x, cy: link.source.y }), | ||
React__default.createElement('circle', { fill: 'black', r: 2, cx: link.target.x, cy: link.target.y }) | ||
); | ||
}), | ||
labels.map(function (label, i) { | ||
return React__default.createElement( | ||
'text', | ||
{ | ||
key: i, | ||
x: label.x, | ||
y: label.y, | ||
textAnchor: textAnchor, | ||
style: { alignmentBaseline: alignmentBaseline, fill: 'black' } | ||
}, | ||
label.label | ||
); | ||
}) | ||
); | ||
}; | ||
SizeLegendSvg.propTypes = { | ||
x: PropTypes.number.isRequired, | ||
y: 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, | ||
labelPosition: PropTypes.oneOf([POSITION_TOP, POSITION_RIGHT, POSITION_BOTTOM, POSITION_LEFT]).isRequired, | ||
linkLength: PropTypes.number.isRequired, | ||
labelOffset: PropTypes.number.isRequired, | ||
shape: PropTypes.oneOf([SHAPE_CIRCLE, SHAPE_SQUARE]).isRequired | ||
}; | ||
SizeLegendSvg.defaultProps = { | ||
x: 0, | ||
y: 0, | ||
anchor: ANCHOR_BOTTOM, | ||
labelPosition: POSITION_RIGHT, | ||
linkLength: 20, | ||
labelOffset: 9, | ||
shape: SHAPE_SQUARE | ||
}; | ||
/* | ||
* 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. | ||
*/ | ||
/* | ||
* 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. | ||
*/ | ||
var textPropsMapping = { | ||
@@ -1712,3 +702,5 @@ align: { | ||
_ref$symbolSpacing = _ref.symbolSpacing, | ||
symbolSpacing = _ref$symbolSpacing === undefined ? LegendSvgItem.defaultProps.symbolSpacing : _ref$symbolSpacing; | ||
symbolSpacing = _ref$symbolSpacing === undefined ? LegendSvgItem.defaultProps.symbolSpacing : _ref$symbolSpacing, | ||
_ref$textColor = _ref.textColor, | ||
textColor = _ref$textColor === undefined ? LegendSvg.defaultProps.textColor : _ref$textColor; | ||
@@ -1774,3 +766,3 @@ var _computeDimensions = computeDimensions({ | ||
ctx.textBaseline = textPropsMapping.baseline[labelAlignment]; | ||
ctx.fillStyle = '#000000'; | ||
ctx.fillStyle = textColor; | ||
ctx.fillText(d.label, itemX + labelX, itemY + labelY); | ||
@@ -1782,10 +774,2 @@ }); | ||
/* | ||
* 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. | ||
*/ | ||
/** | ||
@@ -1824,18 +808,9 @@ * The prop type is exported as a simple object instead of `PropTypes.shape` | ||
symbolSpacing: PropTypes.number, | ||
symbolShape: PropTypes.oneOfType([PropTypes.string, PropTypes.func]) | ||
symbolShape: PropTypes.oneOfType([PropTypes.string, PropTypes.func]), | ||
textColor: PropTypes.string | ||
}; | ||
/* | ||
* 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. | ||
*/ | ||
exports.BoxLegendSvg = BoxLegendSvg; | ||
exports.LegendSvg = LegendSvg; | ||
exports.LegendSvgItem = LegendSvgItem; | ||
exports.SizeLegendSvg = SizeLegendSvg; | ||
exports.renderLegendToCanvas = renderLegendToCanvas; | ||
@@ -1853,14 +828,2 @@ exports.DIRECTION_ROW = DIRECTION_ROW; | ||
exports.ANCHOR_CENTER = ANCHOR_CENTER; | ||
exports.POSITION_TOP = POSITION_TOP; | ||
exports.POSITION_RIGHT = POSITION_RIGHT; | ||
exports.POSITION_BOTTOM = POSITION_BOTTOM; | ||
exports.POSITION_LEFT = POSITION_LEFT; | ||
exports.DIRECTION_TOP_LEFT = DIRECTION_TOP_LEFT; | ||
exports.DIRECTION_TOP_RIGHT = DIRECTION_TOP_RIGHT; | ||
exports.DIRECTION_RIGHT_TOP = DIRECTION_RIGHT_TOP; | ||
exports.DIRECTION_RIGHT_BOTTOM = DIRECTION_RIGHT_BOTTOM; | ||
exports.DIRECTION_BOTTOM_LEFT = DIRECTION_BOTTOM_LEFT; | ||
exports.DIRECTION_BOTTOM_RIGHT = DIRECTION_BOTTOM_RIGHT; | ||
exports.DIRECTION_LEFT_TOP = DIRECTION_LEFT_TOP; | ||
exports.DIRECTION_LEFT_BOTTOM = DIRECTION_LEFT_BOTTOM; | ||
exports.DIRECTION_LEFT_TO_RIGHT = DIRECTION_LEFT_TO_RIGHT; | ||
@@ -1870,4 +833,2 @@ exports.DIRECTION_RIGHT_TO_LEFT = DIRECTION_RIGHT_TO_LEFT; | ||
exports.DIRECTION_BOTTOM_TO_TOP = DIRECTION_BOTTOM_TO_TOP; | ||
exports.SHAPE_SQUARE = SHAPE_SQUARE; | ||
exports.SHAPE_CIRCLE = SHAPE_CIRCLE; | ||
exports.LegendPropShape = LegendPropShape; |
{ | ||
"name": "@nivo/legends", | ||
"description": "legend components for nivo dataviz library", | ||
"version": "0.34.0-1", | ||
"version": "0.35.0", | ||
"license": "MIT", | ||
@@ -15,15 +15,2 @@ "main": "./index.js", | ||
}, | ||
"devDependencies": { | ||
"@nivo/babel-preset": "0.34.0-1", | ||
"babel-cli": "^6.26.0", | ||
"babel-eslint": "^8.0.3", | ||
"babel-jest": "^21.2.0", | ||
"cross-env": "^5.1.1", | ||
"eslint": "^4.12.1", | ||
"eslint-plugin-react": "^7.5.1", | ||
"jest": "^21.2.1", | ||
"react": "^16.2.0", | ||
"react-dom": "^16.2.0", | ||
"react-test-renderer": "^16.2.0" | ||
}, | ||
"peerDependencies": { | ||
@@ -35,8 +22,3 @@ "prop-types": "^15.5.10", | ||
"access": "public" | ||
}, | ||
"scripts": { | ||
"lint": "eslint src stories tests", | ||
"test": "jest --verbose ./tests", | ||
"test:cover": "jest --verbose --coverage ./tests" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
0
26452
692
1