diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fbef2889c..41d63f4fd 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,6 +4,8 @@ - [development](#development) - [formatting](#formatting) - [linting](#linting) + - [screenshots](#screenshots) +- [website](#website) - [deploy](#deploy) ## Setup @@ -61,6 +63,31 @@ make package-lint-bar where `bar` is the name of the targeted nivo package. +### Screenshots + +Each package comes with its own README, we use screenshots from the website +in order to illustrate available package components. + +The script takes screenshots from the website using config defined in +`conf/base.yaml`, if you added a new package, please update this config accordingly. + +To refresh the screenshots, please make sure the website is running on port `3000`, +otherwise run: + +``` +make website +``` + +Then run the corresponding script: + +``` +make packages-screenshots +``` + +## Website + +The website is a CRA based application. + ## Deploy The website is hosted on GitHub pages. diff --git a/conf/base.yaml b/conf/base.yaml index ab87680fe..cfe680b3e 100644 --- a/conf/base.yaml +++ b/conf/base.yaml @@ -1,90 +1,102 @@ capture: baseUrl: http://localhost:3000 pages: - - path: /#/bar + - path: /bar selector: .chart-tabs--chart output: ./packages/nivo-bar/doc/bar.png - - path: /#/bar/canvas + - path: /bar/canvas selector: .chart-tabs--chart output: ./packages/nivo-bar/doc/bar-canvas.png - - path: /#/calendar + - path: /calendar selector: .chart-tabs--chart output: ./packages/nivo-calendar/doc/calendar.png - - path: /#/chord + - path: /chord selector: .chart-tabs--chart output: ./packages/nivo-chord/doc/chord.png - - path: /#/chord/canvas + - path: /chord/canvas selector: .chart-tabs--chart output: ./packages/nivo-chord/doc/chord-canvas.png - - path: /#/bubble + - path: /bubble selector: .chart-tabs--chart output: ./packages/nivo-circle-packing/doc/bubble.png - - path: /#/bubble/html + - path: /bubble/html selector: .chart-tabs--chart output: ./packages/nivo-circle-packing/doc/bubble-html.png - - path: /#/bubble/canvas + - path: /bubble/canvas selector: .chart-tabs--chart output: ./packages/nivo-circle-packing/doc/bubble-canvas.png - - path: /#/heatmap + - path: /heatmap selector: .chart-tabs--chart output: ./packages/nivo-heatmap/doc/heatmap.png - - path: /#/heatmap/canvas + - path: /heatmap/canvas selector: .chart-tabs--chart output: ./packages/nivo-heatmap/doc/heatmap-canvas.png - - path: /#/line + - path: /line selector: .chart-tabs--chart output: ./packages/nivo-line/doc/line.png - - path: /#/pie + - path: /pie selector: .chart-tabs--chart output: ./packages/nivo-pie/doc/pie.png - - path: /#/radar + - path: /radar selector: .chart-tabs--chart output: ./packages/nivo-radar/doc/radar.png - - path: /#/sankey + - path: /sankey selector: .chart-tabs--chart output: ./packages/nivo-sankey/doc/sankey.png - - path: /#/scatterplot + - path: /scatterplot selector: .chart-tabs--chart output: ./packages/nivo-scatterplot/doc/scatterplot.png - - path: /#/scatterplot/canvas + - path: /scatterplot/canvas selector: .chart-tabs--chart output: ./packages/nivo-scatterplot/doc/scatterplot-canvas.png - - path: /#/stream + - path: /stream selector: .chart-tabs--chart output: ./packages/nivo-stream/doc/stream.png - - path: /#/sunburst + - path: /sunburst selector: .chart-tabs--chart output: ./packages/nivo-sunburst/doc/sunburst.png - - path: /#/treemap + - path: /treemap selector: .chart-tabs--chart output: ./packages/nivo-treemap/doc/treemap.png - - path: /#/treemap/html + - path: /treemap/html selector: .chart-tabs--chart output: ./packages/nivo-treemap/doc/treemap-html.png - - path: /#/treemap/canvas + - path: /treemap/canvas selector: .chart-tabs--chart output: ./packages/nivo-treemap/doc/treemap-canvas.png - - path: /#/voronoi + - path: /voronoi selector: .chart-tabs--chart output: ./packages/nivo-voronoi/doc/voronoi.png + + - path: /waffle + selector: .chart-tabs--chart + output: ./packages/nivo-waffle/doc/waffle.png + + - path: /waffle/html + selector: .chart-tabs--chart + output: ./packages/nivo-waffle/doc/waffle-html.png + + - path: /waffle/canvas + selector: .chart-tabs--chart + output: ./packages/nivo-waffle/doc/waffle-canvas.png diff --git a/packages/nivo-waffle/doc/waffle-canvas.png b/packages/nivo-waffle/doc/waffle-canvas.png new file mode 100644 index 000000000..1790bf28c Binary files /dev/null and b/packages/nivo-waffle/doc/waffle-canvas.png differ diff --git a/packages/nivo-waffle/doc/waffle-html.png b/packages/nivo-waffle/doc/waffle-html.png new file mode 100644 index 000000000..1516f03f1 Binary files /dev/null and b/packages/nivo-waffle/doc/waffle-html.png differ diff --git a/packages/nivo-waffle/doc/waffle.png b/packages/nivo-waffle/doc/waffle.png new file mode 100644 index 000000000..bd0251a45 Binary files /dev/null and b/packages/nivo-waffle/doc/waffle.png differ diff --git a/packages/nivo-waffle/package.json b/packages/nivo-waffle/package.json index a1078bec6..dc8d1d768 100644 --- a/packages/nivo-waffle/package.json +++ b/packages/nivo-waffle/package.json @@ -6,6 +6,7 @@ "files": [ "README.md", "index.js", + "index.d.ts", "cjs/" ], "dependencies": { diff --git a/packages/nivo-waffle/src/Waffle.js b/packages/nivo-waffle/src/Waffle.js index 846fedb53..2579859cd 100644 --- a/packages/nivo-waffle/src/Waffle.js +++ b/packages/nivo-waffle/src/Waffle.js @@ -9,11 +9,12 @@ import React, { Component, Fragment } from 'react' import partial from 'lodash/partial' import { TransitionMotion, spring } from 'react-motion' -import { Container, SvgWrapper, BasicTooltip } from '@nivo/core' +import { Container, SvgWrapper } from '@nivo/core' import { WafflePropTypes } from './props' import enhance from './enhance' -import WaffleNode from './WaffleNode' import { applyDataToGrid } from './compute' +import WaffleNode from './WaffleNode' +import WaffleCellTooltip from './WaffleCellTooltip' export class Waffle extends Component { static propTypes = WafflePropTypes @@ -26,18 +27,15 @@ export class Waffle extends Component { if (!cell.data) return showTooltip( - , event ) @@ -127,6 +125,7 @@ export class Waffle extends Component { x={cell.x} y={cell.y} color={cell.color} + fill={cell.data && cell.data.fill} opacity={cell.data ? 1 : emptyOpacity} borderWidth={borderWidth} borderColor={getBorderColor(cell)} @@ -154,6 +153,7 @@ export class Waffle extends Component { x={cell.x} y={cell.y} color={cell.color} + fill={cell.data && cell.data.fill} opacity={cell.data ? 1 : emptyOpacity} borderWidth={borderWidth} borderColor={getBorderColor(cell)} diff --git a/packages/nivo-waffle/src/WaffleCanvas.js b/packages/nivo-waffle/src/WaffleCanvas.js index 220aa14fb..85df660be 100644 --- a/packages/nivo-waffle/src/WaffleCanvas.js +++ b/packages/nivo-waffle/src/WaffleCanvas.js @@ -11,8 +11,8 @@ import range from 'lodash/range' import { Container } from '@nivo/core' import enhance from './enhance' import { WafflePropTypes } from './props' -import { computeGrid } from './compute' import { isCursorInRect, getRelativeCursor } from '@nivo/core' +import WaffleCellTooltip from './WaffleCellTooltip' const findCellUnderCursor = (cells, cellSize, origin, margin, x, y) => cells.find(cell => @@ -43,8 +43,6 @@ class WaffleCanvas extends Component { // dimensions margin, - width, - height, outerWidth, outerHeight, @@ -97,9 +95,41 @@ class WaffleCanvas extends Component { } handleMouseHover = (showTooltip, hideTooltip) => event => { - const { isInteractive, margin, theme } = this.props + const { + isInteractive, + margin, + theme, + cells, + cellSize, + origin, + tooltipFormat, + tooltip, + } = this.props + + if (!isInteractive || !cells) return + + const [x, y] = getRelativeCursor(this.surface, event) + const cell = findCellUnderCursor(cells, cellSize, origin, margin, x, y) - if (!isInteractive) return + if (cell !== undefined) { + if (!cell.data) { + hideTooltip() + } else { + showTooltip( + , + event + ) + } + } } handleMouseLeave = hideTooltip => () => { @@ -112,7 +142,6 @@ class WaffleCanvas extends Component { if (!isInteractive || !cells) return const [x, y] = getRelativeCursor(this.surface, event) - const cell = findCellUnderCursor(cells, cellSize, origin, margin, x, y) if (cell !== undefined) onClick(cell, event) } diff --git a/packages/nivo-waffle/src/WaffleCellTooltip.js b/packages/nivo-waffle/src/WaffleCellTooltip.js new file mode 100644 index 000000000..9fc2cb556 --- /dev/null +++ b/packages/nivo-waffle/src/WaffleCellTooltip.js @@ -0,0 +1,56 @@ +/* + * 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 { BasicTooltip } from '@nivo/core' + +const WaffleCellTooltip = ({ + position, + row, + column, + color, + data, + theme, + tooltipFormat, + tooltip, +}) => ( + +) + +WaffleCellTooltip.displayName = 'WaffleCellTooltip' +WaffleCellTooltip.propTypes = { + position: PropTypes.number.isRequired, + row: PropTypes.number.isRequired, + column: PropTypes.number.isRequired, + color: PropTypes.string.isRequired, + data: PropTypes.object.isRequired, + theme: PropTypes.object.isRequired, + tooltipFormat: PropTypes.oneOfType([PropTypes.func, PropTypes.string]), + tooltip: PropTypes.func, +} + +export default WaffleCellTooltip diff --git a/packages/nivo-waffle/src/WaffleHtml.js b/packages/nivo-waffle/src/WaffleHtml.js index 478585621..9e36ca3df 100644 --- a/packages/nivo-waffle/src/WaffleHtml.js +++ b/packages/nivo-waffle/src/WaffleHtml.js @@ -9,10 +9,12 @@ import React, { Component, Fragment } from 'react' import partial from 'lodash/partial' import { TransitionMotion, spring } from 'react-motion' -import { Container, BasicTooltip } from '@nivo/core' +import { Container } from '@nivo/core' import enhance from './enhance' import { WafflePropTypes } from './props' import { applyDataToGrid } from './compute' +import WaffleHtmlNode from './WaffleHtmlNode' +import WaffleCellTooltip from './WaffleCellTooltip' class WaffleHtml extends Component { static propTypes = WafflePropTypes @@ -25,18 +27,15 @@ class WaffleHtml extends Component { if (!cell.data) return showTooltip( - , event ) @@ -118,25 +117,20 @@ class WaffleHtml extends Component { return ( {computedCells.map(cell => ( -
{ - onClick(cell, e) - }} + position={cell.position} + size={cellSize} + x={cell.x} + y={cell.y} + color={cell.color} + opacity={cell.data ? 1 : emptyOpacity} + borderWidth={borderWidth} + borderColor={getBorderColor(cell)} + data={cell.data} + onHover={partial(onHover, cell)} + onLeave={onLeave} + onClick={onClick} /> ))} @@ -150,25 +144,20 @@ class WaffleHtml extends Component { cellsRender = ( {computedCells.map(cell => ( -
{ - onClick(cell, e) - }} + position={cell.position} + size={cellSize} + x={cell.x} + y={cell.y} + color={cell.color} + opacity={cell.data ? 1 : emptyOpacity} + borderWidth={borderWidth} + borderColor={getBorderColor(cell)} + data={cell.data} + onHover={partial(onHover, cell)} + onLeave={onLeave} + onClick={onClick} /> ))} diff --git a/packages/nivo-waffle/src/WaffleHtmlNode.js b/packages/nivo-waffle/src/WaffleHtmlNode.js new file mode 100644 index 000000000..cce3d7726 --- /dev/null +++ b/packages/nivo-waffle/src/WaffleHtmlNode.js @@ -0,0 +1,71 @@ +/* + * 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 pure from 'recompose/pure' + +const WaffleHtmlNode = ({ + position, + size, + x, + y, + color, + opacity, + borderWidth, + borderColor, + data, + onHover, + onLeave, + onClick, +}) => { + return ( +
{ + onClick({ position, color, x, y, data }, event) + }} + /> + ) +} + +WaffleHtmlNode.propTypes = { + position: PropTypes.number.isRequired, + size: PropTypes.number.isRequired, + x: PropTypes.number.isRequired, + y: PropTypes.number.isRequired, + color: PropTypes.string.isRequired, + opacity: PropTypes.number.isRequired, + borderWidth: PropTypes.number.isRequired, + borderColor: PropTypes.string.isRequired, + data: PropTypes.object.isRequired, + onHover: PropTypes.func.isRequired, + onLeave: PropTypes.func.isRequired, + onClick: PropTypes.func.isRequired, +} +WaffleHtmlNode.defaultProps = { + data: {}, +} +WaffleHtmlNode.displayName = 'WaffleHtmlNode' + +export default pure(WaffleHtmlNode) diff --git a/packages/nivo-waffle/src/WaffleNode.js b/packages/nivo-waffle/src/WaffleNode.js index eef4382bf..3bd726892 100644 --- a/packages/nivo-waffle/src/WaffleNode.js +++ b/packages/nivo-waffle/src/WaffleNode.js @@ -16,6 +16,7 @@ const WaffleNode = ({ x, y, color, + fill, opacity, borderWidth, borderColor, @@ -23,26 +24,24 @@ const WaffleNode = ({ onHover, onLeave, onClick, -}) => { - return ( - { - onClick({ position, color, x, y, data }, event) - }} - /> - ) -} +}) => ( + { + onClick({ position, color, x, y, data }, event) + }} + /> +) WaffleNode.propTypes = { position: PropTypes.number.isRequired, @@ -50,6 +49,7 @@ WaffleNode.propTypes = { x: PropTypes.number.isRequired, y: PropTypes.number.isRequired, color: PropTypes.string.isRequired, + fill: PropTypes.string, opacity: PropTypes.number.isRequired, borderWidth: PropTypes.number.isRequired, borderColor: PropTypes.string.isRequired, diff --git a/packages/nivo-waffle/src/enhance.js b/packages/nivo-waffle/src/enhance.js index 6738f125f..ae5eb3987 100644 --- a/packages/nivo-waffle/src/enhance.js +++ b/packages/nivo-waffle/src/enhance.js @@ -62,7 +62,18 @@ export default Component => { switch (Component.displayName) { case 'Waffle': return compose( - ...[defaultProps(implDefaultProps), ...commonEnhancers, withMotion(), pure] + ...[ + defaultProps(implDefaultProps), + ...commonEnhancers, + withMotion(), + pure, + withPropsOnChange( + ['computedData', 'defs', 'fill'], + ({ computedData, defs, fill }) => ({ + defs: bindDefs(defs, computedData, fill, { targetKey: 'fill' }), + }) + ), + ] )(Component) case 'WaffleHtml': diff --git a/packages/nivo-waffle/src/props.js b/packages/nivo-waffle/src/props.js index f60544b9b..2984509ae 100644 --- a/packages/nivo-waffle/src/props.js +++ b/packages/nivo-waffle/src/props.js @@ -46,6 +46,8 @@ export const WafflePropTypes = { // interactivity isInteractive: PropTypes.bool, + tooltipFormat: PropTypes.oneOfType([PropTypes.func, PropTypes.string]), + tooltip: PropTypes.func, // computed cellSize: PropTypes.number.isRequired, diff --git a/website/src/assets/icons/waffle-grey.png b/website/src/assets/icons/waffle-grey.png new file mode 100644 index 000000000..7135ac531 Binary files /dev/null and b/website/src/assets/icons/waffle-grey.png differ diff --git a/website/src/assets/icons/waffle-red.png b/website/src/assets/icons/waffle-red.png new file mode 100644 index 000000000..4a5d64d46 Binary files /dev/null and b/website/src/assets/icons/waffle-red.png differ diff --git a/website/src/components/charts/calendar/props.js b/website/src/components/charts/calendar/props.js index 770b37fe3..ec3848618 100644 --- a/website/src/components/charts/calendar/props.js +++ b/website/src/components/charts/calendar/props.js @@ -20,7 +20,7 @@ export default [ Chart data, which must conform to this structure:
                     {dedent`
-                        Array.<{
+                        Array<{
                             day:   {string} // format must be YYYY-MM-DD,
                             value: {number}
                         }>
@@ -28,7 +28,7 @@ export default [
                 
), - type: '{Object}', + type: '{Array}', required: true, }, { diff --git a/website/src/components/charts/waffle/CustomTooltip.js b/website/src/components/charts/waffle/CustomTooltip.js new file mode 100644 index 000000000..4e140d569 --- /dev/null +++ b/website/src/components/charts/waffle/CustomTooltip.js @@ -0,0 +1,43 @@ +/* + * 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 styled from 'styled-components' + +const TooltipWrapper = styled.div` + display: grid; + grid-template-columns: 1fr 1fr; + grid-column-gap: 12px; +` +const TooltipKey = styled.span` + font-weight: 600; +` +const TooltipValue = styled.span`` + +const CustomTooltip = node => ( + + label + {node.label} + id + {node.id} + value + {node.value} + position + {node.position} + groupIndex + {node.groupIndex} + row + {node.row} + column + {node.column} + color + {node.color} + +) + +export default CustomTooltip diff --git a/website/src/components/charts/waffle/Waffle.js b/website/src/components/charts/waffle/Waffle.js index 8d267c480..233ae5330 100644 --- a/website/src/components/charts/waffle/Waffle.js +++ b/website/src/components/charts/waffle/Waffle.js @@ -24,16 +24,19 @@ const generateData = () => [ id: 'men', label: 'men', value: Math.random() * 33, + color: '#468df3', }, { id: 'women', label: 'women', value: Math.random() * 33, + color: '#ba72ff', }, { id: 'children', label: 'children', value: Math.random() * 33, + color: '#a1cfff', }, ] @@ -48,7 +51,7 @@ export default class Waffle extends Component { rows: 18, columns: 14, fillDirection: 'bottom', - padding: 2, + padding: 1, margin: { top: 10, @@ -58,6 +61,7 @@ export default class Waffle extends Component { }, // styling + theme: nivoTheme, emptyColor: '#cccccc', emptyOpacity: 1, colors: 'nivo', @@ -73,7 +77,10 @@ export default class Waffle extends Component { motionStiffness: 90, motionDamping: 11, + // interactivity isInteractive: true, + 'custom tooltip example': false, + tooltip: null, }, } @@ -104,10 +111,17 @@ export default class Waffle extends Component { const mappedSettings = propsMapper(settings) - const code = generateCode('ResponsiveWaffle', mappedSettings, { - pkg: '@nivo/waffle', - defaults: WaffleDefaultProps, - }) + const code = generateCode( + 'ResponsiveWaffle', + { + ...mappedSettings, + tooltip: mappedSettings.tooltip ? function CustomTooltip() {} : undefined, + }, + { + pkg: '@nivo/waffle', + defaults: WaffleDefaultProps, + } + ) const header = @@ -143,7 +157,7 @@ export default class Waffle extends Component { {description} diff --git a/website/src/components/charts/waffle/WaffleCanvas.js b/website/src/components/charts/waffle/WaffleCanvas.js index 6b8314741..7bbda13dd 100644 --- a/website/src/components/charts/waffle/WaffleCanvas.js +++ b/website/src/components/charts/waffle/WaffleCanvas.js @@ -21,19 +21,46 @@ import propsMapper from './propsMapper' const generateData = () => [ { - id: 'men', - label: 'men', - value: Math.random() * 33, + id: 'car', + label: 'car', + value: Math.random() * 20, + color: '#eaafaf', }, { - id: 'women', - label: 'women', - value: Math.random() * 33, + id: 'walk', + label: 'walk', + value: Math.random() * 20, + color: '#a2738c', }, { - id: 'children', - label: 'children', - value: Math.random() * 33, + id: 'scooter', + label: 'scooter', + value: Math.random() * 20, + color: '#645c84', + }, + { + id: 'bicycle', + label: 'bicycle', + value: Math.random() * 20, + color: '#427996', + }, + { + id: 'e-bicycle', + label: 'e-bicycle', + value: Math.random() * 20, + color: '#42291c', + }, + { + id: 'moto', + label: 'moto', + value: Math.random() * 20, + color: '#3f5468', + }, + { + id: 'other', + label: 'other', + value: Math.random() * 20, + color: '#b8e4c9', }, ] @@ -44,12 +71,13 @@ export default class WaffleCanvas extends Component { pixelRatio: window && window.devicePixelRatio ? window.devicePixelRatio : 1, // data - total: 100, + total: 140, // layout - rows: 84, - columns: 68, - padding: 1, + rows: 36, + columns: 40, + fillDirection: 'bottom', + padding: 0.5, margin: { top: 10, @@ -59,9 +87,10 @@ export default class WaffleCanvas extends Component { }, // styling + theme: nivoTheme, emptyColor: '#cccccc', emptyOpacity: 1, - colors: 'nivo', + colors: 'd320b', colorBy: 'id', borderWidth: 0, borderColor: { @@ -70,6 +99,8 @@ export default class WaffleCanvas extends Component { }, isInteractive: true, + 'custom tooltip example': true, + tooltip: null, }, } @@ -100,10 +131,17 @@ export default class WaffleCanvas extends Component { const mappedSettings = propsMapper(settings) - const code = generateCode('ResponsiveWaffleCanvas', mappedSettings, { - pkg: '@nivo/waffle', - defaults: WaffleDefaultProps, - }) + const code = generateCode( + 'ResponsiveWaffleCanvas', + { + ...mappedSettings, + tooltip: mappedSettings.tooltip ? function CustomTooltip() {} : undefined, + }, + { + pkg: '@nivo/waffle', + defaults: WaffleDefaultProps, + } + ) const header = @@ -140,12 +178,11 @@ export default class WaffleCanvas extends Component { diff --git a/website/src/components/charts/waffle/WaffleHtml.js b/website/src/components/charts/waffle/WaffleHtml.js index 9f1246b46..a0345e0a2 100644 --- a/website/src/components/charts/waffle/WaffleHtml.js +++ b/website/src/components/charts/waffle/WaffleHtml.js @@ -24,16 +24,19 @@ const generateData = () => [ id: 'men', label: 'men', value: Math.random() * 33, + color: '#468df3', }, { id: 'women', label: 'women', value: Math.random() * 33, + color: '#ba72ff', }, { id: 'children', label: 'children', value: Math.random() * 33, + color: '#a1cfff', }, ] @@ -48,7 +51,7 @@ export default class WaffleHtml extends Component { rows: 18, columns: 14, fillDirection: 'bottom', - padding: 2, + padding: 1, margin: { top: 10, @@ -58,6 +61,7 @@ export default class WaffleHtml extends Component { }, // styling + theme: nivoTheme, emptyColor: '#cccccc', emptyOpacity: 1, colors: 'set2', @@ -74,6 +78,8 @@ export default class WaffleHtml extends Component { motionDamping: 11, isInteractive: true, + 'custom tooltip example': false, + tooltip: null, }, } @@ -104,10 +110,17 @@ export default class WaffleHtml extends Component { const mappedSettings = propsMapper(settings) - const code = generateCode('ResponsiveWaffleHtml', mappedSettings, { - pkg: '@nivo/waffle', - defaults: WaffleDefaultProps, - }) + const code = generateCode( + 'ResponsiveWaffleHtml', + { + ...mappedSettings, + tooltip: mappedSettings.tooltip ? function CustomTooltip() {} : undefined, + }, + { + pkg: '@nivo/waffle', + defaults: WaffleDefaultProps, + } + ) const header = @@ -155,7 +168,6 @@ export default class WaffleHtml extends Component { diff --git a/website/src/components/charts/waffle/props.js b/website/src/components/charts/waffle/props.js index 98acfd498..15b157c9d 100644 --- a/website/src/components/charts/waffle/props.js +++ b/website/src/components/charts/waffle/props.js @@ -13,6 +13,7 @@ import { defsProperties, } from '../../../lib/componentProperties' import { WaffleDefaultProps } from '@nivo/waffle' +import dedent from 'dedent-js' const defaults = WaffleDefaultProps @@ -25,10 +26,23 @@ export default [ required: true, }, { - key: 'root', + key: 'data', scopes: '*', - description: 'The hierarchical data object.', - type: '{Object}', + description: ( +
+ Chart data, which must conform to this structure: +
+                    {dedent`
+                        Array<{
+                            id:    {string|number},
+                            value: {number},
+                            label: {string|number},
+                        }>
+                    `}
+                
+
+ ), + type: '{Array}', required: true, }, { @@ -151,18 +165,14 @@ export default [ 'Property to use to determine node color. If a function is provided, it will receive current node data and must return a color.', type: '{string|Function}', required: false, - default: 'depth', + default: 'id', controlType: 'choices', controlGroup: 'Style', controlOptions: { choices: [ { - label: 'depth', - value: 'depth', - }, - { - label: 'name', - value: 'name', + label: 'id', + value: 'id', }, { label: 'd => d.color', @@ -243,5 +253,47 @@ export default [ type: '{Function}', required: false, }, + { + key: 'custom tooltip example', + scopes: ['Waffle', 'WaffleHtml', 'WaffleCanvas'], + excludeFromDoc: true, + description: ( + + You can customize the tooltip using the tooltip property and{' '} + theme.tooltip object. + + ), + type: '{boolean}', + controlType: 'switch', + controlGroup: 'Interactivity', + }, + { + key: 'tooltip', + scopes: ['Waffle', 'WaffleHtml', 'WaffleCanvas'], + type: '{Function}', + required: false, + description: ( +
+ A function allowing complete tooltip customisation, it must return a valid HTML + element and will receive the following data: +
+                    {dedent`
+                        {
+                            id:         {string|number},
+                            value:      {number},
+                            label:      {string|number},
+                            color:      {string},
+                            position:   {number},
+                            row:        {number},
+                            column:     {number},
+                            groupIndex: {number},
+                            startAt:    {number},
+                            endAt:      {number},
+                        }
+                    `}
+                
+
+ ), + }, ...motionProperties(['Waffle', 'WaffleHtml'], defaults), ] diff --git a/website/src/components/charts/waffle/propsMapper.js b/website/src/components/charts/waffle/propsMapper.js index 7780b8e06..9ab02f3f7 100644 --- a/website/src/components/charts/waffle/propsMapper.js +++ b/website/src/components/charts/waffle/propsMapper.js @@ -7,7 +7,35 @@ * file that was distributed with this source code. */ import { settingsMapper, mapInheritedColor } from '../../../lib/settings' +import CustomTooltip from './CustomTooltip' -export default settingsMapper({ - borderColor: mapInheritedColor, -}) +export default settingsMapper( + { + colorBy: value => { + if (value === 'd => d.color') return d => d.color + return value + }, + borderColor: mapInheritedColor, + theme: (value, values) => { + if (!values['custom tooltip example']) return value + + return { + ...values.theme, + tooltip: { + container: { + ...values.theme.tooltip.container, + background: '#333', + }, + }, + } + }, + tooltip: (value, values) => { + if (!values['custom tooltip example']) return null + + return CustomTooltip + }, + }, + { + exclude: ['custom tooltip example'], + } +)