Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(xy): scale type improvements #1381

Merged
merged 30 commits into from
Sep 16, 2021
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
543c33c
chore: tick values are numbers
monfera Sep 16, 2021
915c86f
chore: showing any via the generic type
monfera Sep 16, 2021
9ed546a
chore: converting more any to unknown
monfera Sep 16, 2021
12ef5a8
chore: converting more any to unknown 02
monfera Sep 16, 2021
c7f89b2
chore: converting more any to unknown 03
monfera Sep 16, 2021
26d9935
chore: converting more any to unknown 04
monfera Sep 16, 2021
8675664
chore: converting more any to unknown 05
monfera Sep 16, 2021
2ae39b3
chore: converting more any to real type 06
monfera Sep 16, 2021
57c5c8f
chore: converting more any to real type 07
monfera Sep 16, 2021
3607f0a
chore: converting more any to real type 08
monfera Sep 16, 2021
ae17f5c
chore: converting more any to real type 09
monfera Sep 16, 2021
bb93b5a
chore: converting more any to real type 10
monfera Sep 16, 2021
432238d
chore: converting more any to real type 11
monfera Sep 16, 2021
9be0b6a
chore: converting more any to real type 12
monfera Sep 16, 2021
770f3a6
chore: generic ScaleBand 01
monfera Sep 16, 2021
44af026
chore: generic ScaleBand 02
monfera Sep 16, 2021
6eea0f7
chore: generic ScaleBand 03
monfera Sep 16, 2021
0ec33ef
chore: converting more any to real type 13
monfera Sep 16, 2021
7272653
chore: converting more any to real type 14
monfera Sep 16, 2021
5bc5c0a
chore: converting more any to real type 15
monfera Sep 16, 2021
3e30380
chore: converting more any to real type 16
monfera Sep 16, 2021
09bed4a
refactor: drive by removal of verbose code
monfera Sep 16, 2021
c20cef9
chore: converting more any to real type 17
monfera Sep 16, 2021
0ac3fd2
test: type improvement round ht MarcoV NickP
monfera Sep 16, 2021
8cd6cda
test: generic typing for isBandScale
monfera Sep 16, 2021
afaceb6
test: doing away with the unknown
monfera Sep 16, 2021
b59e2e0
test: more assertion removals due to review update ripple-down
monfera Sep 16, 2021
b36aefb
test: more any removals
monfera Sep 16, 2021
640d644
test: all yScale occurrences are numeric
monfera Sep 16, 2021
36d1596
test: minor other unifications
monfera Sep 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: generic ScaleBand 01
monfera committed Sep 16, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 770f3a60db7f667a481d7418ea024291afa955f3
Original file line number Diff line number Diff line change
@@ -16,8 +16,8 @@ import { computeSeriesDomainsSelector } from './compute_series_domains';

/** @internal */
export interface SmallMultipleScales {
horizontal: ScaleBand;
vertical: ScaleBand;
horizontal: ScaleBand<string | number>;
vertical: ScaleBand<string | number>;
}

/**
@@ -43,6 +43,10 @@ export function getScale(
padding: RelativeBandsPadding = DEFAULT_SM_PANEL_PADDING,
) {
const singlePanelSmallMultiple = domain.length <= 1;
const defaultDomain = domain.length === 0 ? [undefined] : domain;
return new ScaleBand(defaultDomain, [0, maxRange], undefined, singlePanelSmallMultiple ? 0 : padding);
return new ScaleBand(
domain.length > 0 ? domain : [(undefined as unknown) as number],
Copy link
Contributor Author

@monfera monfera Sep 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we've already been cheating to comply with the D3 scale typedef file and the D3 doc, but now we're clear about it. I'll try to solve it in a next PR, it's only partially addressed in this one

[0, maxRange],
undefined,
singlePanelSmallMultiple ? 0 : padding,
);
}
6 changes: 3 additions & 3 deletions packages/charts/src/scales/scale_band.ts
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ import { ScaleType } from './constants';
* Categorical scale
* @internal
*/
export class ScaleBand implements Scale<unknown> {
export class ScaleBand<T extends number | string> implements Scale<T> {
readonly bandwidth: number;

readonly bandwidthPadding: number;
@@ -50,7 +50,7 @@ export class ScaleBand implements Scale<unknown> {
private readonly d3Scale: D3ScaleBand<NonNullable<PrimitiveValue>>;

constructor(
domain: any[],
domain: T[],
range: Range,
overrideBandwidth?: number,
/**
@@ -81,7 +81,7 @@ export class ScaleBand implements Scale<unknown> {
this.bandwidth = this.d3Scale.bandwidth() || 0;
this.originalBandwidth = this.d3Scale.bandwidth() || 0;
this.step = this.d3Scale.step();
this.domain = this.d3Scale.domain();
this.domain = [...new Set(domain)];
monfera marked this conversation as resolved.
Show resolved Hide resolved
this.range = range.slice();
if (overrideBandwidth) {
this.bandwidth = overrideBandwidth * (1 - safeBarPadding);