Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: more options for handling invalid
- Loading branch information
Showing
35 changed files
with
1,673 additions
and
526 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,91 @@ | ||
{ | ||
"$schema": "https://vega.github.io/schema/vega-lite/v5.json", | ||
"description": "Testing invalid", | ||
"data": { | ||
"values": [ | ||
{"a": null, "b": 1000}, | ||
{"a": -10, "b": null}, | ||
{"a": -5, "b": 25}, | ||
{"a": -1, "b": 20}, | ||
{"a": 0, "b": null}, | ||
{"a": 1, "b": 30}, | ||
{"a": 5, "b": 40}, | ||
{"a": 10, "b": null} | ||
] | ||
}, | ||
|
||
"config": { | ||
"mark": {"invalid": "include"} | ||
}, | ||
"hconcat": [{ | ||
"title": "Quantitative X", | ||
"vconcat": [{ | ||
"width": 100, | ||
"height": 100, | ||
"mark": "point", | ||
"encoding": { | ||
"x": {"field": "a", "type": "quantitative"}, | ||
"y": {"field": "b", "type": "quantitative"} | ||
} | ||
}, { | ||
"width": 100, | ||
"height": 100, | ||
"mark": "bar", | ||
"encoding": { | ||
"x": {"field": "a", "type": "quantitative"}, | ||
"y": {"field": "b", "type": "quantitative"} | ||
} | ||
}, { | ||
"width": 100, | ||
"height": 100, | ||
"mark": "line", | ||
"encoding": { | ||
"x": {"field": "a", "type": "quantitative"}, | ||
"y": {"field": "b", "type": "quantitative"} | ||
} | ||
}, { | ||
"width": 100, | ||
"height": 100, | ||
"mark": "area", | ||
"encoding": { | ||
"x": {"field": "a", "type": "quantitative"}, | ||
"y": {"field": "b", "type": "quantitative"} | ||
} | ||
}] | ||
},{ | ||
"title": "Ordinal X", | ||
"vconcat": [{ | ||
"width": 100, | ||
"height": 100, | ||
"mark": "point", | ||
"encoding": { | ||
"x": {"field": "a", "type": "ordinal"}, | ||
"y": {"field": "b", "type": "quantitative"} | ||
} | ||
}, { | ||
"width": 100, | ||
"height": 100, | ||
"mark": "bar", | ||
"encoding": { | ||
"x": {"field": "a", "type": "ordinal"}, | ||
"y": {"field": "b", "type": "quantitative"} | ||
} | ||
}, { | ||
"width": 100, | ||
"height": 100, | ||
"mark": "line", | ||
"encoding": { | ||
"x": {"field": "a", "type": "ordinal"}, | ||
"y": {"field": "b", "type": "quantitative"} | ||
} | ||
}, { | ||
"width": 100, | ||
"height": 100, | ||
"mark": "area", | ||
"encoding": { | ||
"x": {"field": "a", "type": "ordinal"}, | ||
"y": {"field": "b", "type": "quantitative"} | ||
} | ||
}] | ||
}] | ||
} |
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
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,68 @@ | ||
import {SignalRef} from 'vega'; | ||
import {ScaleChannel, isPolarPositionChannel, isXorY} from '../../channel'; | ||
import {Config} from '../../config'; | ||
import {ScaleInvalidDataIncludeAs} from '../../invalid'; | ||
import {MarkDef, isPathMark} from '../../mark'; | ||
import {ScaleType, hasContinuousDomain} from '../../scale'; | ||
import {getMarkPropOrConfig} from '../common'; | ||
import {normalizeInvalidDataMode} from './normalizeInvalidDataMode'; | ||
|
||
export type ScaleInvalidDataMode<C extends ScaleChannel> = | ||
| 'always-valid' | ||
| 'filter' | ||
| 'break-paths' | ||
| 'break-paths-keep-domains' | ||
| ScaleInvalidDataInclude<C>; | ||
|
||
export interface ScaleInvalidDataInclude<C extends ScaleChannel> { | ||
includeAs: ScaleInvalidDataIncludeAs<C>; | ||
} | ||
|
||
export function isScaleInvalidDataInclude<C extends ScaleChannel>( | ||
invalidDataMode: ScaleInvalidDataMode<C> | ||
): invalidDataMode is ScaleInvalidDataInclude<C> { | ||
return (invalidDataMode as ScaleInvalidDataInclude<C>).includeAs !== undefined; | ||
} | ||
|
||
export function getScaleInvalidDataMode<C extends ScaleChannel>({ | ||
markDef, | ||
config, | ||
scaleChannel, | ||
scaleType, | ||
isCountAggregate | ||
}: { | ||
markDef: MarkDef; | ||
config: Config<SignalRef>; | ||
scaleChannel: C; | ||
scaleType: ScaleType; | ||
isCountAggregate: boolean; | ||
}): ScaleInvalidDataMode<C> { | ||
if (!scaleType || !hasContinuousDomain(scaleType) || isCountAggregate) { | ||
// - Discrete scales can always display null as another category | ||
// - Count cannot output null values | ||
return 'always-valid'; | ||
} | ||
|
||
const invalidMode = normalizeInvalidDataMode(getMarkPropOrConfig('invalid', markDef, config), { | ||
isPath: isPathMark(markDef.type) | ||
}); | ||
|
||
const scaleOutputForInvalid = config.scale?.invalid?.[scaleChannel]; | ||
if (scaleOutputForInvalid !== undefined) { | ||
// Regardless of the current invalid mode, if the channel has a default value, we consider the field valid. | ||
return {includeAs: scaleOutputForInvalid}; | ||
} | ||
|
||
if (invalidMode === 'include') { | ||
// TODO: it's arguable if we should make the behavior inconsistent between position and non-position. | ||
// But this initial PR, we keep the behavior consistent (no breaking changes). | ||
if (isXorY(scaleChannel) || isPolarPositionChannel(scaleChannel)) { | ||
return {includeAs: 'min'}; | ||
} | ||
return {includeAs: 'zero-or-min'}; | ||
} | ||
return invalidMode; | ||
} | ||
export function shouldBreakPath(mode: ScaleInvalidDataMode<any>): boolean { | ||
return mode === 'break-paths' || mode === 'break-paths-keep-domains'; | ||
} |
Oops, something went wrong.