diff --git a/packages/annotations/src/compute.ts b/packages/annotations/src/compute.ts index 3feaa44ac..c359ac0b5 100644 --- a/packages/annotations/src/compute.ts +++ b/packages/annotations/src/compute.ts @@ -28,8 +28,8 @@ export const bindAnnotations = < getPosition, getDimensions, }: { - data: Datum[] - annotations: AnnotationMatcher[] + data: readonly Datum[] + annotations: readonly AnnotationMatcher[] getPosition: AnnotationPositionGetter getDimensions: AnnotationDimensionsGetter }): BoundAnnotation[] => diff --git a/packages/annotations/src/hooks.ts b/packages/annotations/src/hooks.ts index 7f6e44762..c870de553 100644 --- a/packages/annotations/src/hooks.ts +++ b/packages/annotations/src/hooks.ts @@ -16,8 +16,8 @@ export const useAnnotations = ({ getPosition, getDimensions, }: { - data: Datum[] - annotations: AnnotationMatcher[] + data: readonly Datum[] + annotations: readonly AnnotationMatcher[] getPosition: AnnotationPositionGetter getDimensions: AnnotationDimensionsGetter }) => @@ -35,7 +35,7 @@ export const useAnnotations = ({ export const useComputedAnnotations = ({ annotations, }: { - annotations: BoundAnnotation[] + annotations: readonly BoundAnnotation[] }) => useMemo( () => diff --git a/packages/bar/src/Bar.tsx b/packages/bar/src/Bar.tsx index 80e8aad80..cca9ce7fb 100644 --- a/packages/bar/src/Bar.tsx +++ b/packages/bar/src/Bar.tsx @@ -58,7 +58,7 @@ const InnerBar = ({ gridXValues, gridYValues, - layers = svgDefaultProps.layers as BarLayer[], + layers = svgDefaultProps.layers as readonly BarLayer[], barComponent = svgDefaultProps.barComponent, enableLabel = svgDefaultProps.enableLabel, diff --git a/packages/bar/src/compute/common.ts b/packages/bar/src/compute/common.ts index 406ee57cc..058ccc309 100644 --- a/packages/bar/src/compute/common.ts +++ b/packages/bar/src/compute/common.ts @@ -4,7 +4,7 @@ import { ScaleBandSpec, ScaleBand, computeScale } from '@nivo/scales' * Generates indexed scale. */ export const getIndexScale = ( - data: RawDatum[], + data: readonly RawDatum[], getIndex: (datum: RawDatum) => string, padding: number, indexScale: ScaleBandSpec, @@ -24,7 +24,7 @@ export const getIndexScale = ( /** * This method ensures all the provided keys exist in the entire series. */ -export const normalizeData = (data: RawDatum[], keys: string[]) => +export const normalizeData = (data: readonly RawDatum[], keys: readonly string[]) => data.map( item => ({ diff --git a/packages/bar/src/compute/grouped.ts b/packages/bar/src/compute/grouped.ts index 8a56ff491..9d842d84e 100644 --- a/packages/bar/src/compute/grouped.ts +++ b/packages/bar/src/compute/grouped.ts @@ -5,7 +5,7 @@ import { BarDatum, BarSvgProps, ComputedBarDatum, ComputedDatum } from '../types import { coerceValue, filterNullValues, getIndexScale, normalizeData } from './common' type Params = { - data: RawDatum[] + data: readonly RawDatum[] formatValue: (value: number) => string getColor: OrdinalColorScale> getIndex: (datum: RawDatum) => string @@ -186,7 +186,7 @@ export const generateGroupedBars = ({ getIndex: (datum: RawDatum) => string getTooltipLabel: (datum: ComputedDatum) => string margin: Margin - hiddenIds?: (string | number)[] + hiddenIds?: readonly (string | number)[] }) => { const keys = props.keys.filter(key => !hiddenIds.includes(key)) const data = normalizeData(props.data, keys) diff --git a/packages/bar/src/compute/stacked.ts b/packages/bar/src/compute/stacked.ts index 14a9778e8..50ba1f535 100644 --- a/packages/bar/src/compute/stacked.ts +++ b/packages/bar/src/compute/stacked.ts @@ -179,7 +179,7 @@ export const generateStackedBars = ({ getIndex: (datum: RawDatum) => string getTooltipLabel: (datum: ComputedDatum) => string margin: Margin - hiddenIds?: (string | number)[] + hiddenIds?: readonly (string | number)[] }) => { const keys = props.keys.filter(key => !hiddenIds.includes(key)) const stackedData = stack().keys(keys).offset(stackOffsetDiverging)( diff --git a/packages/bar/src/types.ts b/packages/bar/src/types.ts index 8644bff6c..24e8ea52e 100644 --- a/packages/bar/src/types.ts +++ b/packages/bar/src/types.ts @@ -22,7 +22,7 @@ export interface BarDatum { } export interface DataProps { - data: RawDatum[] + data: readonly RawDatum[] } export type BarDatumWithColor = BarDatum & { @@ -109,8 +109,8 @@ interface BarCustomLayerBaseProps | 'tooltip' >, Dimensions { - bars: ComputedBarDatum[] - legendData: [BarLegendProps, LegendData[]][] + bars: readonly ComputedBarDatum[] + legendData: [BarLegendProps, readonly LegendData[]][] margin: Margin innerWidth: number @@ -208,7 +208,7 @@ export type BarHandlers = { export type BarCommonProps = { indexBy: PropertyAccessor - keys: string[] + keys: readonly string[] maxValue: 'auto' | number minValue: 'auto' | number @@ -253,12 +253,12 @@ export type BarCommonProps = { colors: OrdinalColorScaleConfig> theme: Theme - annotations: AnnotationMatcher>[] - legends: BarLegendProps[] + annotations: readonly AnnotationMatcher>[] + legends: readonly BarLegendProps[] renderWrapper?: boolean - initialHiddenIds: (string | number)[] + initialHiddenIds: readonly (string | number)[] } export type BarSvgProps = Partial> & @@ -275,9 +275,9 @@ export type BarSvgProps = Partial> - markers: CartesianMarkerProps[] + markers: readonly CartesianMarkerProps[] - layers: BarLayer[] + layers: readonly BarLayer[] role: string ariaLabel?: React.AriaAttributes['aria-label'] @@ -310,6 +310,6 @@ export type BarCanvasProps = Partial export type BarAnnotationsProps = { - annotations: AnnotationMatcher>[] - bars: ComputedBarDatum[] + annotations: readonly AnnotationMatcher>[] + bars: readonly ComputedBarDatum[] }