-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(encodable): only set scale domain if both bounds are defined (#250)
* feat: only set scale domain if both bounds are presented * fix: unit test * fix: more optimize
- Loading branch information
1 parent
f5f876f
commit b672373
Showing
7 changed files
with
105 additions
and
12 deletions.
There are no files selected for viewing
24 changes: 14 additions & 10 deletions
24
...y_superset_ui/superset-ui/packages/superset-ui-encodable/src/parsers/scale/applyDomain.ts
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 |
---|---|---|
@@ -1,21 +1,25 @@ | ||
import { isDateTime } from 'vega-lite/build/src/datetime'; | ||
import { Value } from '../../types/VegaLite'; | ||
import { ScaleConfig, D3Scale, TimeScaleConfig } from '../../types/Scale'; | ||
import { ScaleConfig, D3Scale } from '../../types/Scale'; | ||
import parseDateTime from '../parseDateTime'; | ||
import inferElementTypeFromUnionOfArrayTypes from '../../utils/inferElementTypeFromUnionOfArrayTypes'; | ||
import { isTimeScale } from '../../typeGuards/Scale'; | ||
import { isEveryElementDefined } from '../../typeGuards/Base'; | ||
|
||
export default function applyDomain<Output extends Value>( | ||
config: ScaleConfig<Output>, | ||
scale: D3Scale<Output>, | ||
) { | ||
const { domain, reverse, type } = config; | ||
if (typeof domain !== 'undefined') { | ||
const processedDomain = reverse ? domain.slice().reverse() : domain; | ||
if (isTimeScale(scale, type)) { | ||
const timeDomain = processedDomain as TimeScaleConfig['domain']; | ||
scale.domain(inferElementTypeFromUnionOfArrayTypes(timeDomain).map(d => parseDateTime(d))); | ||
} else { | ||
scale.domain(processedDomain); | ||
const { domain, reverse } = config; | ||
if (typeof domain !== 'undefined' && domain.length > 0) { | ||
const processedDomain = inferElementTypeFromUnionOfArrayTypes(domain); | ||
|
||
// Only set domain if all items are defined | ||
if (isEveryElementDefined(processedDomain)) { | ||
scale.domain( | ||
(reverse ? processedDomain.slice().reverse() : processedDomain).map(d => | ||
isDateTime(d) ? parseDateTime(d) : d, | ||
), | ||
); | ||
} | ||
} | ||
} |
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