diff --git a/examples/simple/src/components/Line.tsx b/examples/simple/src/components/Line.tsx index 14716236..16393515 100644 --- a/examples/simple/src/components/Line.tsx +++ b/examples/simple/src/components/Line.tsx @@ -24,6 +24,7 @@ export default function Line() { () => [ { getValue: (datum) => datum.secondary, + alternatingBackgroundColor: "#f5f5f5", }, ], [] diff --git a/src/components/AxisLinear.tsx b/src/components/AxisLinear.tsx index b434cbb0..b2d8b23a 100644 --- a/src/components/AxisLinear.tsx +++ b/src/components/AxisLinear.tsx @@ -107,6 +107,15 @@ export default function AxisLinearComp(axis: Axis) { } }) + // For vertical axis find height, for horizontal width + // if not enough ticks, default to 0 + const bandDim = + ticks.length > 1 + ? axis.isVertical + ? ticks[0].from.y - ticks[1].from.y + : ticks[1].from.x - ticks[0].from.x + : 0 + return ( (axis: Axis) { ) })} + {axis.alternatingBackgroundColor ? ( + + {ticks.map((tick, i) => { + return !isOuter && i % 2 ? ( + + ) : null + })} + + ) : null} {ticks.map((tick, i) => { return ( @@ -209,7 +235,7 @@ export default function AxisLinearComp(axis: Axis) { x2={tick.gridTo.x} y2={tick.gridTo.y} stroke={ - dark ? 'rgba(255,255,255, .05)' : 'rgba(0,0,0, .05)' + dark ? 'rgba(255,255,255, .05)' : 'rgba(0,0,0, .05' } /> ) : null} diff --git a/src/types.ts b/src/types.ts index b58b678f..1778bb1f 100644 --- a/src/types.ts +++ b/src/types.ts @@ -250,6 +250,7 @@ export type AxisOptionsBase = { maxBandSize?: number minDomainLength?: number showGrid?: boolean + alternatingBackgroundColor?: string show?: boolean stacked?: boolean stackOffset?: typeof stackOffsetNone diff --git a/src/utils/buildAxis.linear.ts b/src/utils/buildAxis.linear.ts index 294014d4..0d9776ac 100644 --- a/src/utils/buildAxis.linear.ts +++ b/src/utils/buildAxis.linear.ts @@ -122,12 +122,12 @@ function buildTimeAxis( // see https://stackoverflow.com/a/2831422 if (Object.prototype.toString.call(options.min) === '[object Date]') { - minValue = min([options.min, minValue as Date]) + minValue = min([options.min, minValue] as Date[]) shouldNice = false } if (Object.prototype.toString.call(options.max) === '[object Date]') { - maxValue = max([options.max, maxValue as Date]) + maxValue = max([options.max, maxValue] as Date[]) shouldNice = false }