Skip to content

Commit

Permalink
feat(waffle-grid): add support for standard chart axes
Browse files Browse the repository at this point in the history
  • Loading branch information
plouc committed Dec 13, 2021
1 parent 9a92803 commit 0e08f9c
Show file tree
Hide file tree
Showing 9 changed files with 287 additions and 98 deletions.
8 changes: 6 additions & 2 deletions packages/axes/src/components/Axes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export const Axes = memo(
<X extends ScaleValue, Y extends ScaleValue>({
xScale,
yScale,
x = 0,
y = 0,
width,
height,
top,
Expand All @@ -17,6 +19,8 @@ export const Axes = memo(
}: {
xScale: AnyScale
yScale: AnyScale
x?: number
y?: number
width: number
height: number
top?: AxisProps<X> | null
Expand Down Expand Up @@ -44,8 +48,8 @@ export const Axes = memo(
key={position}
{...axis}
axis={isXAxis ? 'x' : 'y'}
x={position === 'right' ? width : 0}
y={position === 'bottom' ? height : 0}
x={position === 'right' ? x + width : x}
y={position === 'bottom' ? y + height : y}
scale={isXAxis ? xScale : yScale}
length={isXAxis ? width : height}
ticksPosition={ticksPosition}
Expand Down
1 change: 1 addition & 0 deletions packages/waffle-grid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@nivo/axes": "0.74.0",
"@nivo/colors": "0.74.0",
"@nivo/legends": "0.74.0",
"@nivo/scales": "0.74.0",
"@nivo/tooltip": "0.74.0",
"@react-spring/web": "9.3.1"
},
Expand Down
23 changes: 21 additions & 2 deletions packages/waffle-grid/src/WaffleGrid.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ReactNode, Fragment, createElement, useMemo } from 'react'
import { Container, useDimensions, SvgWrapper } from '@nivo/core'
import { Axes } from '@nivo/axes'
import { WaffleGridAllCells } from './WaffleGridAllCells'
import { WaffleGridAxes } from './WaffleGridAxes'
import { WaffleGridGrid } from './WaffleGridGrid'
import { WaffleGridSvgProps, WaffleGridLayerId, WaffleGridCustomLayerProps } from './types'
import { svgDefaultProps } from './defaults'
Expand All @@ -28,6 +28,10 @@ export const InnerWaffleGrid = ({
valueCellColor = svgDefaultProps.valueCellColor,
enableGridX = svgDefaultProps.enableGridX,
enableGridY = svgDefaultProps.enableGridY,
axisTop,
axisRight,
axisBottom,
axisLeft,
layers = svgDefaultProps.layers,
blankCellComponent = svgDefaultProps.blankCellComponent,
blankCellsMotion = {},
Expand Down Expand Up @@ -77,7 +81,22 @@ export const InnerWaffleGrid = ({
}

if (layers.includes('axes')) {
layerById.axes = <WaffleGridAxes key="axes" xAxis={xAxis} yAxis={yAxis} />
// layerById.axes = <WaffleGridAxes key="axes" xAxis={xAxis} yAxis={yAxis} />
layerById.axes = (
<Axes
key="axes"
xScale={xAxis.scale}
yScale={yAxis.scale}
x={yAxis.x1}
y={xAxis.y1}
width={yAxis.x2 - yAxis.x1}
height={xAxis.y2 - xAxis.y1}
top={axisTop}
right={axisRight}
bottom={axisBottom}
left={axisLeft}
/>
)
}

if (layers.includes('cells')) {
Expand Down
4 changes: 4 additions & 0 deletions packages/waffle-grid/src/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export const commonDefaultProps = {

enableGridX: true,
enableGridY: true,
axisTop: null,
axisRight: null,
axisBottom: {},
axisLeft: {},

layers: ['grid', 'axes', 'cells'] as WaffleGridLayerId[],

Expand Down
Loading

0 comments on commit 0e08f9c

Please sign in to comment.