Skip to content

Commit

Permalink
feat(dots): add ability to define custom dot symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphaël Benitte committed Aug 21, 2017
1 parent 2bd2554 commit da49e15
Show file tree
Hide file tree
Showing 13 changed files with 134 additions and 184 deletions.
2 changes: 1 addition & 1 deletion src/Nivo.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const defaultTheme = {
strokeWidth: 1,
strokeDasharray: '',
},
markers: {
dots: {
textColor: '#000',
fontSize: '11px',
},
Expand Down
3 changes: 3 additions & 0 deletions src/components/charts/line/Line.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const Line = ({

// dots
enableDots,
dotSymbol,
dotSize,
dotColor,
dotBorderWidth,
Expand Down Expand Up @@ -121,6 +122,7 @@ const Line = ({
{enableDots &&
<LineDots
lines={lines}
symbol={dotSymbol}
size={dotSize}
color={getInheritedColorGenerator(dotColor)}
borderWidth={dotBorderWidth}
Expand Down Expand Up @@ -175,6 +177,7 @@ Line.propTypes = {

// dots
enableDots: PropTypes.bool.isRequired,
dotSymbol: PropTypes.func,
dotSize: PropTypes.number.isRequired,
dotColor: PropTypes.any.isRequired,
dotBorderWidth: PropTypes.number.isRequired,
Expand Down
8 changes: 7 additions & 1 deletion src/components/charts/line/LineDots.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import DotsItem from '../../dots/DotsItem'

const LineDots = ({
lines,

symbol,
size,
color,
borderWidth,
Expand Down Expand Up @@ -68,6 +70,7 @@ const LineDots = ({
key={point.key}
x={point.x}
y={point.y}
symbol={symbol}
size={size}
color={point.fill}
borderWidth={borderWidth}
Expand Down Expand Up @@ -105,6 +108,7 @@ const LineDots = ({
<DotsItem
key={key}
{...style}
symbol={symbol}
color={point.fill}
borderWidth={borderWidth}
borderColor={point.stroke}
Expand All @@ -124,6 +128,8 @@ LineDots.propTypes = {
id: PropTypes.string.isRequired,
})
),

symbol: PropTypes.func,
size: PropTypes.number.isRequired,
color: PropTypes.func.isRequired,
borderWidth: PropTypes.number.isRequired,
Expand All @@ -137,7 +143,7 @@ LineDots.propTypes = {

// theming
theme: PropTypes.shape({
markers: PropTypes.shape({
dots: PropTypes.shape({
textColor: PropTypes.string.isRequired,
fontSize: PropTypes.string.isRequired,
}).isRequired,
Expand Down
69 changes: 36 additions & 33 deletions src/components/charts/radar/Radar.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import SvgWrapper from '../SvgWrapper'
import RadarShapes from './RadarShapes'
import RadarGrid from './RadarGrid'
import RadarTooltip from './RadarTooltip'
import RadarMarkers from './RadarMarkers'
import RadarDots from './RadarDots'

const Radar = ({
data,
Expand Down Expand Up @@ -52,16 +52,17 @@ const Radar = ({
gridShape,
gridLabelOffset,

// markers
enableMarkers,
markersSize,
markersColor,
markersBorderWidth,
markersBorderColor,
enableMarkersLabel,
markersLabel,
markersLabelFormat,
markersLabelYOffset,
// dots
enableDots,
dotSymbol,
dotSize,
dotColor,
dotBorderWidth,
dotBorderColor,
enableDotLabel,
dotLabel,
dotLabelFormat,
dotLabelYOffset,

// theming
theme,
Expand Down Expand Up @@ -121,22 +122,23 @@ const Radar = ({
showTooltip={showTooltip}
hideTooltip={hideTooltip}
/>}
{enableMarkers &&
<RadarMarkers
{enableDots &&
<RadarDots
data={data}
keys={keys}
getIndex={getIndex}
radiusScale={radiusScale}
angleStep={angleStep}
size={markersSize}
symbol={dotSymbol}
size={dotSize}
colorByKey={colorByKey}
color={markersColor}
borderWidth={markersBorderWidth}
borderColor={markersBorderColor}
enableLabel={enableMarkersLabel}
label={markersLabel}
labelFormat={markersLabelFormat}
labelYOffset={markersLabelYOffset}
color={dotColor}
borderWidth={dotBorderWidth}
borderColor={dotBorderColor}
enableLabel={enableDotLabel}
label={dotLabel}
labelFormat={dotLabelFormat}
labelYOffset={dotLabelYOffset}
theme={theme}
{...motionProps}
/>}
Expand Down Expand Up @@ -167,16 +169,17 @@ Radar.propTypes = {
gridShape: PropTypes.oneOf(['circular', 'linear']),
gridLabelOffset: PropTypes.number,

// markers
enableMarkers: PropTypes.bool.isRequired,
markersSize: PropTypes.number,
markersColor: PropTypes.any,
markersBorderWidth: PropTypes.number,
markersBorderColor: PropTypes.any,
enableMarkersLabel: PropTypes.bool,
markersLabel: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
markersLabelFormat: PropTypes.string,
markersLabelYOffset: PropTypes.number,
// dots
enableDots: PropTypes.bool.isRequired,
dotSymbol: PropTypes.func,
dotSize: PropTypes.number,
dotColor: PropTypes.any,
dotBorderWidth: PropTypes.number,
dotBorderColor: PropTypes.any,
enableDotLabel: PropTypes.bool,
dotLabel: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
dotLabelFormat: PropTypes.string,
dotLabelYOffset: PropTypes.number,

// theming
getColor: PropTypes.func.isRequired, // computed
Expand All @@ -199,8 +202,8 @@ export const RadarDefaultProps = {
gridShape: 'circular',
gridLabelOffset: 16,

// markers
enableMarkers: true,
// dots
enableDots: true,

// theming
fillOpacity: 0.15,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import { motionPropTypes } from '../../../props'
import { getInheritedColorGenerator } from '../../../lib/colorUtils'
import { positionFromAngle } from '../../../lib/arcUtils'
import { getLabelGenerator } from '../../../lib/propertiesConverters'
import MarkersItem from '../../markers/MarkersItem'
import DotsItem from '../../dots/DotsItem'

export default class RadarMarkers extends Component {
export default class RadarDots extends Component {
static propTypes = {
data: PropTypes.arrayOf(PropTypes.object).isRequired,
keys: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number]))
Expand All @@ -26,6 +26,8 @@ export default class RadarMarkers extends Component {

radiusScale: PropTypes.func.isRequired,
angleStep: PropTypes.number.isRequired,

symbol: PropTypes.func,
size: PropTypes.number.isRequired,
color: PropTypes.oneOfType([PropTypes.string, PropTypes.func]).isRequired,
borderWidth: PropTypes.number.isRequired,
Expand All @@ -39,7 +41,7 @@ export default class RadarMarkers extends Component {

// theming
theme: PropTypes.shape({
markers: PropTypes.shape({
dots: PropTypes.shape({
textColor: PropTypes.string.isRequired,
fontSize: PropTypes.string.isRequired,
}).isRequired,
Expand Down Expand Up @@ -69,6 +71,8 @@ export default class RadarMarkers extends Component {

radiusScale,
angleStep,

symbol,
size,
color,
borderWidth,
Expand Down Expand Up @@ -121,10 +125,11 @@ export default class RadarMarkers extends Component {
return (
<g>
{points.map(point =>
<MarkersItem
<DotsItem
key={point.key}
x={point.style.x}
y={point.style.y}
symbol={symbol}
size={size}
color={point.style.fill}
borderWidth={borderWidth}
Expand Down Expand Up @@ -158,9 +163,10 @@ export default class RadarMarkers extends Component {
{interpolatedStyles =>
<g>
{interpolatedStyles.map(({ key, style, data: point }) =>
<MarkersItem
<DotsItem
key={key}
{...style}
symbol={symbol}
color={point.style.fill}
borderWidth={borderWidth}
borderColor={point.style.stroke}
Expand Down
2 changes: 1 addition & 1 deletion src/components/charts/radar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
export { default as Radar } from './Radar'
export * from './Radar'
export { default as ResponsiveRadar } from './ResponsiveRadar'
export { default as RadarMarkers } from './RadarMarkers'
export { default as RadarDots } from './RadarDots'
24 changes: 15 additions & 9 deletions src/components/dots/DotsItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import DotsItemSymbol from './DotsItemSymbol'
const DotsItem = ({
x,
y,
symbol,
size,
color,
borderWidth,
Expand All @@ -24,19 +25,19 @@ const DotsItem = ({
theme,
}) =>
<g transform={`translate(${x}, ${y})`} style={{ pointerEvents: 'none' }}>
<DotsItemSymbol
size={size}
color={color}
borderWidth={borderWidth}
borderColor={borderColor}
/>
{React.createElement(symbol, {
size: size,
color: color,
borderWidth: borderWidth,
borderColor: borderColor,
})}
{label &&
<text
textAnchor={labelTextAnchor}
y={labelYOffset}
style={{
fontSize: theme.markers.fontSize,
fill: theme.markers.textColor,
fontSize: theme.dots.fontSize,
fill: theme.dots.textColor,
}}
>
{label}
Expand All @@ -54,21 +55,26 @@ DotsItem.propTypes = {
borderWidth: PropTypes.number.isRequired,
borderColor: PropTypes.string.isRequired,

symbol: PropTypes.func.isRequired,

// label
label: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
labelTextAnchor: PropTypes.oneOf(['start', 'middle', 'end']),
labelYOffset: PropTypes.number.isRequired,

// theming
theme: PropTypes.shape({
markers: PropTypes.shape({
dots: PropTypes.shape({
textColor: PropTypes.string.isRequired,
fontSize: PropTypes.string.isRequired,
}).isRequired,
}).isRequired,
}

export const DotsItemDefaultProps = {
symbol: DotsItemSymbol,

// label
labelTextAnchor: 'middle',
labelYOffset: -12,
}
Expand Down
75 changes: 0 additions & 75 deletions src/components/markers/MarkersItem.js

This file was deleted.

Loading

0 comments on commit da49e15

Please sign in to comment.