-
Notifications
You must be signed in to change notification settings - Fork 608
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add rangeStep normalizer to provide backward compatibility
- Loading branch information
Showing
3 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Encoding<string>, any>; // this is not accurate, but it's not worth making it accurate | ||
|
||
export class RangeStepNormalizer implements NonFacetUnitNormalizer<UnitSpecWithRangeStep> { | ||
public name = 'RangeStep'; | ||
|
||
public hasMatchingType(spec: GenericSpec<any, any>): 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 | ||
); | ||
} | ||
} |