diff --git a/src/log/message.ts b/src/log/message.ts index ed93e05e9d4..17b550f4dfc 100644 --- a/src/log/message.ts +++ b/src/log/message.ts @@ -189,6 +189,8 @@ export function orientOverridden(original: string, actual: string) { export const CANNOT_UNION_CUSTOM_DOMAIN_WITH_FIELD_DOMAIN = 'custom domain scale cannot be unioned with default field-based domain'; +export const RANGE_STEP_DEPRECATED = `Scale's "rangeStep" is deprecated and will be removed in Vega-Lite 5.0. Please use "width"/"height": {"step": ...} instead. See https://vega.github.io/vega-lite/docs/size.html`; + export function cannotUseScalePropertyWithNonColor(prop: string) { return `Cannot use the scale property "${prop}" with non-color channel.`; } diff --git a/src/normalize/core.ts b/src/normalize/core.ts index db5540ba1cc..c40da7d746e 100644 --- a/src/normalize/core.ts +++ b/src/normalize/core.ts @@ -15,6 +15,7 @@ import {isUnitSpec, NormalizedUnitSpec} from '../spec/unit'; import {keys, omit} from '../util'; import {NonFacetUnitNormalizer, NormalizerParams} from './base'; import {PathOverlayNormalizer} from './pathoverlay'; +import {RangeStepNormalizer} from './rangestep'; import {RuleForRangedLineNormalizer} from './ruleforrangedline'; export class CoreNormalizer extends SpecMapper { @@ -23,7 +24,8 @@ export class CoreNormalizer extends SpecMapper, params: NormalizerParams) { diff --git a/src/normalize/rangestep.ts b/src/normalize/rangestep.ts new file mode 100644 index 00000000000..e6c4135a8e0 --- /dev/null +++ b/src/normalize/rangestep.ts @@ -0,0 +1,62 @@ +import {getSizeType, POSITION_SCALE_CHANNELS} from '../channel'; +import {isFieldDef} from '../channeldef'; +import {Encoding} from '../encoding'; +import * as log from '../log'; +import {Scale} from '../scale'; +import {GenericSpec} from '../spec/index'; +import {GenericUnitSpec, isUnitSpec} from '../spec/unit'; +import {NonFacetUnitNormalizer, NormalizeLayerOrUnit, NormalizerParams} from './base'; + +type UnitSpecWithRangeStep = GenericUnitSpec, any>; // this is not accurate, but it's not worth making it accurate + +export class RangeStepNormalizer implements NonFacetUnitNormalizer { + public name = 'RangeStep'; + + public hasMatchingType(spec: GenericSpec): spec is UnitSpecWithRangeStep { + if (isUnitSpec(spec)) { + for (const channel of POSITION_SCALE_CHANNELS) { + const def = spec.encoding[channel]; + if (def && isFieldDef(def)) { + if (def && def.scale && def.scale['rangeStep']) { + return true; + } + } + } + } + return false; + } + + public run(spec: UnitSpecWithRangeStep, params: NormalizerParams, normalize: NormalizeLayerOrUnit) { + const sizeMixins = {}; + let encoding = {...spec.encoding}; + + for (const channel of POSITION_SCALE_CHANNELS) { + const sizeType = getSizeType(channel); + const def = spec.encoding[channel]; + if (def && isFieldDef(def)) { + if (def && def.scale && def.scale['rangeStep']) { + const {rangeStep, ...scaleWithoutRangeStep} = def.scale as Scale & {rangeStep: number}; + sizeMixins[sizeType] = {step: def.scale['rangeStep']}; + + log.warn(log.message.RANGE_STEP_DEPRECATED); + + encoding = { + ...encoding, + [channel]: { + ...encoding[channel], + scale: scaleWithoutRangeStep + } + }; + } + } + } + return normalize( + { + ...sizeMixins, + ...spec, + encoding + }, + params + ); + } +}