diff --git a/src/normalize/core.ts b/src/normalize/core.ts index 4d9ffe077e..1ada42824e 100644 --- a/src/normalize/core.ts +++ b/src/normalize/core.ts @@ -28,7 +28,6 @@ import {isEmpty, keys, omit, varName} from '../util'; import {isSignalRef} from '../vega.schema'; import {NonFacetUnitNormalizer, NormalizerParams} from './base'; import {PathOverlayNormalizer} from './pathoverlay'; -import {RangeStepNormalizer} from './rangestep'; import {replaceRepeaterInEncoding, replaceRepeaterInFacet} from './repeater'; import {RuleForRangedLineNormalizer} from './ruleforrangedline'; @@ -38,8 +37,7 @@ export class CoreNormalizer extends SpecMapper, params: NormalizerParams) { diff --git a/src/normalize/rangestep.ts b/src/normalize/rangestep.ts deleted file mode 100644 index 332ddb3e92..0000000000 --- a/src/normalize/rangestep.ts +++ /dev/null @@ -1,62 +0,0 @@ -import {getSizeChannel, POSITION_SCALE_CHANNELS} from '../channel'; -import {isFieldOrDatumDef} from '../channeldef'; -import {Encoding} from '../encoding'; -import * as log from '../log'; -import {Scale} from '../scale'; -import {GenericSpec} from '../spec'; -import {GenericUnitSpec, isUnitSpec, NormalizedUnitSpec} from '../spec/unit'; -import {isEmpty} from '../util'; -import {NonFacetUnitNormalizer} 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) && spec.encoding) { - for (const channel of POSITION_SCALE_CHANNELS) { - const def = spec.encoding[channel]; - if (def && isFieldOrDatumDef(def)) { - if (def?.scale?.['rangeStep']) { - return true; - } - } - } - } - return false; - } - - public run(spec: UnitSpecWithRangeStep): NormalizedUnitSpec { - const sizeMixins = {}; - let encoding = {...spec.encoding}; - - for (const channel of POSITION_SCALE_CHANNELS) { - const sizeType = getSizeChannel(channel); - const def = encoding[channel]; - if (def && isFieldOrDatumDef(def)) { - if (def?.scale?.['rangeStep']) { - const {scale, ...defWithoutScale} = def; - - const {rangeStep, ...scaleWithoutRangeStep} = scale as Scale & {rangeStep: number}; - sizeMixins[sizeType] = {step: scale['rangeStep']}; - - log.warn(log.message.RANGE_STEP_DEPRECATED); - - encoding = { - ...encoding, - [channel]: { - ...defWithoutScale, - ...(isEmpty(scaleWithoutRangeStep) ? {} : {scale: scaleWithoutRangeStep}) - } - }; - } - } - } - return { - ...sizeMixins, - ...spec, - encoding - }; - } -} diff --git a/test/normalize/rangestep.test.ts b/test/normalize/rangestep.test.ts deleted file mode 100644 index d88bc0313d..0000000000 --- a/test/normalize/rangestep.test.ts +++ /dev/null @@ -1,47 +0,0 @@ -import * as log from '../../src/log'; -import {normalize} from '../../src/normalize/index'; -import {RangeStepNormalizer} from '../../src/normalize/rangestep'; -import {Scale} from '../../src/scale'; -import {TopLevelUnitSpec} from '../../src/spec/unit'; - -describe('RangeStepNormalizer', () => { - const rangeStepNormalizer = new RangeStepNormalizer(); - - it( - 'converts rangeStep to width/height.step', - log.wrap(locallogger => { - const spec: TopLevelUnitSpec = { - data: {name: 'test'}, - mark: 'rect', - encoding: { - x: { - field: 'date', - type: 'nominal', - scale: {rangeStep: 12} as Scale // Need to cast as rangeStep is no longer an official scale property - }, - y: { - field: 'price', - type: 'nominal', - scale: {rangeStep: 24} as Scale // Need to cast as rangeStep is no longer an official scale property - } - } - }; - - expect(rangeStepNormalizer.hasMatchingType(spec)).toBeTruthy(); - - const normalizedSpec = normalize(spec); - expect(normalizedSpec).toEqual({ - data: {name: 'test'}, - width: {step: 12}, - height: {step: 24}, - mark: 'rect', - encoding: { - x: {field: 'date', type: 'nominal'}, - y: {field: 'price', type: 'nominal'} - } - }); - - expect(locallogger.warns[0]).toEqual(log.message.RANGE_STEP_DEPRECATED); - }) - ); -});