diff --git a/packages/vx-demo/components/tiles/barstack.js b/packages/vx-demo/components/tiles/barstack.js index 7845e5730..f8a438de1 100644 --- a/packages/vx-demo/components/tiles/barstack.js +++ b/packages/vx-demo/components/tiles/barstack.js @@ -1,6 +1,7 @@ import React from 'react'; import { BarStack } from '@vx/shape'; import { Group } from '@vx/group'; +import { Grid } from '@vx/grid'; import { AxisBottom } from '@vx/axis'; import { cityTemperature } from '@vx/mock-data'; import { scaleBand, scaleLinear, scaleOrdinal } from '@vx/scale'; @@ -73,6 +74,17 @@ export default withTooltip(
+ { {`import React from 'react'; import { BarStack } from '@vx/shape'; import { Group } from '@vx/group'; +import { Grid } from '@vx/grid'; import { AxisBottom } from '@vx/axis'; import { cityTemperature } from '@vx/mock-data'; import { scaleBand, scaleLinear, scaleOrdinal } from '@vx/scale'; @@ -79,13 +80,17 @@ export default withTooltip( return (
- + event => { if (tooltipTimeout) clearTimeout(tooltipTimeout); const top = event.clientY - margin.top - data.height; - const left = - xScale(data.x) + data.width + data.paddingInner * data.step / 2; + const left = xScale(data.x) + data.width + data.paddingInner * data.step / 2; showTooltip({ tooltipData: data, tooltipTop: top, @@ -125,7 +129,7 @@ export default withTooltip( tickLabelProps={(value, index) => ({ fill: '#a44afe', fontSize: 11, - textAnchor: 'middle', + textAnchor: 'middle' })} /> @@ -139,13 +143,9 @@ export default withTooltip( fontSize: '14px' }} > - +
- {tooltipOpen && + {tooltipOpen && (
- - {tooltipData.key} - -
-
- {tooltipData.data[tooltipData.key]}℉ + {tooltipData.key}
+
{tooltipData.data[tooltipData.key]}℉
- - {tooltipData.xFormatted} - + {tooltipData.xFormatted}
-
} + + )}
); } -); -`} +);`} ); }; diff --git a/packages/vx-grid/src/grids/Columns.js b/packages/vx-grid/src/grids/Columns.js index 90afdfb15..426536216 100644 --- a/packages/vx-grid/src/grids/Columns.js +++ b/packages/vx-grid/src/grids/Columns.js @@ -15,34 +15,35 @@ export default function Columns({ className, numTicks = 10, lineStyle, + offset, ...restProps }) { + const ticks = scale.ticks ? scale.ticks(numTicks) : scale.domain(); return ( - {scale.ticks && - scale.ticks(numTicks).map((d, i) => { - const x = scale(d); - const fromPoint = new Point({ - x, - y: 0 - }); - const toPoint = new Point({ - x, - y: height - }); - return ( - - ); - })} + {ticks.map((d, i) => { + const x = offset ? scale(d) + offset : scale(d); + const fromPoint = new Point({ + x, + y: 0 + }); + const toPoint = new Point({ + x, + y: height + }); + return ( + + ); + })} ); } diff --git a/packages/vx-grid/src/grids/Grid.js b/packages/vx-grid/src/grids/Grid.js index 49377baae..a351dee4d 100644 --- a/packages/vx-grid/src/grids/Grid.js +++ b/packages/vx-grid/src/grids/Grid.js @@ -18,7 +18,10 @@ export default function Grid({ numTicksRows, numTicksColumns, rowLineStyle, - columnLineStyle + columnLineStyle, + xOffset, + yOffset, + ...restProps }) { return ( @@ -31,6 +34,8 @@ export default function Grid({ strokeDasharray={strokeDasharray} numTicks={numTicksRows} style={rowLineStyle} + offset={yOffset} + {...restProps} /> ); diff --git a/packages/vx-grid/src/grids/Rows.js b/packages/vx-grid/src/grids/Rows.js index 7f2b0742a..8c94e13a5 100644 --- a/packages/vx-grid/src/grids/Rows.js +++ b/packages/vx-grid/src/grids/Rows.js @@ -15,34 +15,35 @@ export default function Rows({ className, numTicks = 10, lineStyle, + offset, ...restProps }) { + const ticks = scale.ticks ? scale.ticks(numTicks) : scale.domain(); return ( - {scale.ticks && - scale.ticks(numTicks).map((d, i) => { - const y = scale(d); - const fromPoint = new Point({ - x: 0, - y - }); - const toPoint = new Point({ - x: width, - y - }); - return ( - - ); - })} + {ticks.map((d, i) => { + const y = offset ? scale(d) + offset : scale(d); + const fromPoint = new Point({ + x: 0, + y + }); + const toPoint = new Point({ + x: width, + y + }); + return ( + + ); + })} ); }