-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: interval shape has max/min width (#5123)
* feat(interval): add minWidth maxWidth options for interval shape * docs: add docs and demo * test: add test case screenshots
- Loading branch information
Showing
16 changed files
with
203 additions
and
7 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.91 KB
__tests__/integration/snapshots/static/alphabetIntervalMaxWidthTransposed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12.2 KB
__tests__/integration/snapshots/static/alphabetIntervalMinWidthTransposed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions
33
__tests__/plots/static/alphabet-interval-max-width-transposed.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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { G2Spec } from '../../../src'; | ||
|
||
export function alphabetIntervalMaxWidthTransposed(): G2Spec { | ||
return { | ||
type: 'interval', | ||
coordinate: { transform: [{ type: 'transpose' }] }, | ||
data: { | ||
type: 'fetch', | ||
value: 'data/alphabet.csv', | ||
transform: [ | ||
{ | ||
type: 'slice', | ||
start: 0, | ||
end: 3, | ||
}, | ||
], | ||
}, | ||
encode: { | ||
x: 'letter', | ||
y: 'frequency', | ||
color: 'steelblue', | ||
}, | ||
scale: { | ||
x: { padding: 0.1 }, | ||
}, | ||
style: { | ||
maxWidth: 10, | ||
}, | ||
axis: { | ||
y: { labelFormatter: '.0%' }, | ||
}, | ||
}; | ||
} |
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,32 @@ | ||
import { G2Spec } from '../../../src'; | ||
|
||
export function alphabetIntervalMaxWidth(): G2Spec { | ||
return { | ||
type: 'interval', | ||
data: { | ||
type: 'fetch', | ||
value: 'data/alphabet.csv', | ||
transform: [ | ||
{ | ||
type: 'slice', | ||
start: 0, | ||
end: 3, | ||
}, | ||
], | ||
}, | ||
encode: { | ||
x: 'letter', | ||
y: 'frequency', | ||
color: 'steelblue', | ||
}, | ||
scale: { | ||
x: { padding: 0.1 }, | ||
}, | ||
style: { | ||
maxWidth: 10, | ||
}, | ||
axis: { | ||
y: { labelFormatter: '.0%' }, | ||
}, | ||
}; | ||
} |
26 changes: 26 additions & 0 deletions
26
__tests__/plots/static/alphabet-interval-min-width-transposed.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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { G2Spec } from '../../../src'; | ||
|
||
export function alphabetIntervalMinWidthTransposed(): G2Spec { | ||
return { | ||
type: 'interval', | ||
coordinate: { transform: [{ type: 'transpose' }] }, | ||
data: { | ||
type: 'fetch', | ||
value: 'data/alphabet.csv', | ||
}, | ||
encode: { | ||
x: 'letter', | ||
y: 'frequency', | ||
color: 'steelblue', | ||
}, | ||
scale: { | ||
x: { padding: 0.9 }, | ||
}, | ||
style: { | ||
minWidth: 10, | ||
}, | ||
axis: { | ||
y: { labelFormatter: '.0%' }, | ||
}, | ||
}; | ||
} |
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,25 @@ | ||
import { G2Spec } from '../../../src'; | ||
|
||
export function alphabetIntervalMinWidth(): G2Spec { | ||
return { | ||
type: 'interval', | ||
data: { | ||
type: 'fetch', | ||
value: 'data/alphabet.csv', | ||
}, | ||
encode: { | ||
x: 'letter', | ||
y: 'frequency', | ||
color: 'steelblue', | ||
}, | ||
scale: { | ||
x: { padding: 0.9 }, | ||
}, | ||
style: { | ||
minWidth: 16, | ||
}, | ||
axis: { | ||
y: { labelFormatter: '.0%' }, | ||
}, | ||
}; | ||
} |
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,9 @@ | ||
import { clamp } from '../../../src/utils/number'; | ||
|
||
describe('number', () => { | ||
it('clame should return value between lower and upper', () => { | ||
expect(clamp(1, 0, 2)).toBe(1); | ||
expect(clamp(1, 2, 3)).toBe(2); | ||
expect(clamp(5, 2, 3)).toBe(3); | ||
}); | ||
}); |
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,18 @@ | ||
import { Chart } from '@antv/g2'; | ||
|
||
const chart = new Chart({ | ||
container: 'container', | ||
theme: 'classic', | ||
autoFit: true, | ||
}); | ||
|
||
chart | ||
.interval() | ||
.data([{ letter: 'A', frequency: 120 }]) | ||
.encode('x', 'letter') | ||
.encode('y', 'frequency') | ||
.scale('x', { padding: 0.5 }) | ||
// .style('minWidth', 500) | ||
.style('maxWidth', 200); | ||
|
||
chart.render(); |
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,6 @@ | ||
/** | ||
* Clamp number within the inclusive range within the lower and upper bounds. | ||
*/ | ||
export function clamp(v: number, lower: number, upper: number): number { | ||
return Math.max(lower, Math.min(v, upper)); | ||
} |