-
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(rangeX and rangeY): add syntactic sugar for data (#5914)
* feat(rangeX and rangeY): add syntactic sugar for data * docs(rangeX and rangeY): add syntactic sugar content
- Loading branch information
1 parent
690cf80
commit 1a28b3d
Showing
10 changed files
with
1,176 additions
and
2 deletions.
There are no files selected for viewing
1,041 changes: 1,041 additions & 0 deletions
1,041
__tests__/integration/snapshots/static/aaplLineRrangeXY.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,28 @@ | ||
import { G2Spec } from '../../../src'; | ||
|
||
export function aaplLineRrangeXY(): G2Spec { | ||
return { | ||
type: 'view', | ||
children: [ | ||
{ | ||
type: 'line', | ||
data: { | ||
type: 'fetch', | ||
value: 'data/aapl.csv', | ||
}, | ||
encode: { x: 'date', y: 'close' }, | ||
}, | ||
{ | ||
type: 'rangeX', | ||
data: [new Date('2010'), new Date('2011')], | ||
}, | ||
{ | ||
type: 'rangeY', | ||
data: [ | ||
[350, 400], | ||
[500, 600], | ||
], | ||
}, | ||
], | ||
}; | ||
} |
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
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,36 @@ | ||
import { deepMix } from '@antv/util'; | ||
import { TransformComponent as TC } from '../runtime'; | ||
import { column, isObject } from './utils/helper'; | ||
|
||
export type MaybeDefaultXOptions = Record<string, never>; | ||
|
||
/** | ||
* Add a default encode for rangeX | ||
* when data is just an array | ||
*/ | ||
export const MaybeDefaultX: TC<MaybeDefaultXOptions> = () => { | ||
return (I, mark) => { | ||
const { data } = mark; | ||
if ( | ||
Array.isArray(data) && | ||
(data.every(Array.isArray) || !data.some(isObject)) | ||
) { | ||
const extractX = (data, index: number) => | ||
Array.isArray(data[0]) | ||
? data.map((item) => item[index]) | ||
: [data[index]]; | ||
return [ | ||
I, | ||
deepMix({}, mark, { | ||
encode: { | ||
x: column(extractX(data, 0)), | ||
x1: column(extractX(data, 1)), | ||
}, | ||
}), | ||
]; | ||
} | ||
return [I, mark]; | ||
}; | ||
}; | ||
|
||
MaybeDefaultX.props = {}; |
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,36 @@ | ||
import { deepMix } from '@antv/util'; | ||
import { Primitive, TransformComponent as TC } from '../runtime'; | ||
import { column, isObject } from './utils/helper'; | ||
|
||
export type MaybeDefaultYOptions = Record<string, never>; | ||
|
||
/** | ||
* Add a default encode for rangeY | ||
* when data is just an array | ||
*/ | ||
export const MaybeDefaultY: TC<MaybeDefaultYOptions> = () => { | ||
return (I, mark) => { | ||
const { data } = mark; | ||
if ( | ||
Array.isArray(data) && | ||
(data.every(Array.isArray) || !data.some(isObject)) | ||
) { | ||
const extractY = (data, index: number) => | ||
Array.isArray(data[0]) | ||
? data.map((item) => item[index]) | ||
: [data[index]]; | ||
return [ | ||
I, | ||
deepMix({}, mark, { | ||
encode: { | ||
y: column(extractY(data, 0)), | ||
y1: column(extractY(data, 1)), | ||
}, | ||
}), | ||
]; | ||
} | ||
return [I, mark]; | ||
}; | ||
}; | ||
|
||
MaybeDefaultY.props = {}; |