@@ -2,10 +2,10 @@ import { scaleLinear, ScaleContinuousNumeric, ScaleLinear } from "d3-scale";
22import React , { createContext , useContext , useMemo } from "react" ;
33import h from "@macrostrat/hyper" ;
44
5- type HeightRange = [ number , number ] ;
5+ type HeightRange = number ;
66type ColumnScale = ScaleContinuousNumeric < HeightRange , number > | any ;
77
8- type ColumnScaleClamped = ScaleLinear < number , number > ;
8+ type ColumnScaleClamped = ScaleContinuousNumeric < number , number > ;
99
1010export declare interface ColumnDivision {
1111 section_id : string ;
@@ -55,6 +55,7 @@ export interface ColumnProviderProps<T extends ColumnDivision> {
5555 width ?: number ;
5656 axisType ?: ColumnAxisType ;
5757 children ?: any ;
58+ scale ?: ColumnScale ;
5859}
5960
6061function ColumnProvider < T extends ColumnDivision > (
@@ -75,6 +76,7 @@ function ColumnProvider<T extends ColumnDivision>(
7576 divisions = [ ] ,
7677 width = 150 ,
7778 axisType = ColumnAxisType . HEIGHT ,
79+ scale : _scale ,
7880 ...rest
7981 } = props ;
8082
@@ -103,9 +105,17 @@ function ColumnProvider<T extends ColumnDivision>(
103105 }
104106
105107 // same as the old `innerHeight`
106- const pixelHeight = height * pixelsPerMeter * zoom ;
107-
108- const scale = scaleLinear ( ) . domain ( range ) . range ( [ pixelHeight , 0 ] ) ;
108+ let scale = _scale ;
109+ let pixelHeight : number ;
110+ if ( scale == null ) {
111+ pixelHeight = height * pixelsPerMeter * zoom ;
112+ scale = scaleLinear ( ) . domain ( range ) . range ( [ pixelHeight , 0 ] ) ;
113+ } else {
114+ pixelHeight = Math . abs ( scale . range ( ) [ 1 ] - scale . range ( ) [ 0 ] ) ;
115+ // Remove any offset that might exist from paddings, scale breaks, etc.
116+ const r1 = scale . range ( ) . map ( ( d ) => d - scale . range ( ) [ 0 ] ) ;
117+ scale = _scale . copy ( ) . range ( r1 ) ;
118+ }
109119 const scaleClamped = scale . copy ( ) . clamp ( true ) ;
110120
111121 return {
0 commit comments