-
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.
- Loading branch information
1 parent
249a3f0
commit 9f823ad
Showing
20 changed files
with
318 additions
and
1 deletion.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,21 @@ | ||
import { G2Spec } from '../../../src'; | ||
|
||
export function bulletCustomColor(): G2Spec { | ||
return { | ||
type: 'bullet', | ||
coordinate: { transform: [{ type: 'transpose' }] }, | ||
data: [ | ||
{ | ||
title: '閲嶅簡', | ||
ranges: [30, 90, 120], | ||
measures: [65], | ||
target: [80], | ||
}, | ||
], | ||
scale: { | ||
rangesColor: { | ||
ranges: ['#ccc', '#aaa', '#555', '#000'], | ||
}, | ||
}, | ||
}; | ||
} |
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,16 @@ | ||
import { G2Spec } from '../../../src'; | ||
|
||
export function bulletDefault(): G2Spec { | ||
return { | ||
type: 'bullet', | ||
coordinate: { transform: [{ type: 'transpose' }] }, | ||
data: [ | ||
{ | ||
title: '閲嶅簡', | ||
ranges: [30, 90, 120], | ||
measures: [65], | ||
target: [80], | ||
}, | ||
], | ||
}; | ||
} |
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,34 @@ | ||
import { G2Spec } from '../../../src'; | ||
|
||
export function bulletGroup(): G2Spec { | ||
return { | ||
type: 'bullet', | ||
coordinate: { transform: [{ type: 'transpose' }] }, | ||
data: [ | ||
{ | ||
title: '閲嶅簡', | ||
ranges: [30, 90, 120], | ||
measures: [65], | ||
target: [80], | ||
}, | ||
{ | ||
title: '鏉窞', | ||
ranges: [30, 90, 150], | ||
measures: [50], | ||
target: [100], | ||
}, | ||
{ | ||
title: '骞垮窞', | ||
ranges: [30, 90, 120], | ||
measures: [40], | ||
target: [85], | ||
}, | ||
{ | ||
title: '娣卞湷', | ||
ranges: [30, 90, 120], | ||
measures: [50], | ||
target: [100], | ||
}, | ||
], | ||
}; | ||
} |
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,53 @@ | ||
import { G2Spec } from '../../../src'; | ||
|
||
export function bulletSpace(): G2Spec { | ||
return { | ||
type: 'spaceFlex', | ||
children: [ | ||
{ | ||
type: 'bullet', | ||
data: [ | ||
{ | ||
title: 'Revenue', | ||
ranges: [150, 225, 300], | ||
measures: [220, 270], | ||
target: [250], | ||
}, | ||
], | ||
}, | ||
{ | ||
type: 'bullet', | ||
data: [ | ||
{ | ||
title: 'Profit', | ||
ranges: [20, 25, 60], | ||
measures: [21, 23], | ||
target: [55], | ||
}, | ||
], | ||
}, | ||
{ | ||
type: 'bullet', | ||
data: [ | ||
{ | ||
title: 'Order Size', | ||
ranges: [350, 500, 600], | ||
measures: [100, 320], | ||
target: [550], | ||
}, | ||
], | ||
}, | ||
{ | ||
type: 'bullet', | ||
data: [ | ||
{ | ||
title: 'Satisfaction', | ||
ranges: [1400, 2000, 2600], | ||
measures: [1000, 1650], | ||
target: [2100], | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
} |
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,156 @@ | ||
import { deepMix } from '@antv/util'; | ||
import { subObject } from '../utils/helper'; | ||
import { CompositionComponent as CC } from '../runtime'; | ||
import { BulletMark } from '../spec'; | ||
import { maybeAnimation } from '../utils/mark'; | ||
|
||
export type BulletOptions = Omit<BulletMark, 'type'>; | ||
|
||
function dataTransform(data, encode) { | ||
const { | ||
target = 'target', | ||
measures = 'measures', | ||
ranges = 'ranges', | ||
} = encode || {}; | ||
|
||
const dataMap = (data, key: string) => { | ||
return data.flatMap((d) => { | ||
const keyMeasure = d[key] || []; | ||
return keyMeasure.map((m, i) => ({ | ||
x: d.title, | ||
y: m, | ||
color: `${key}-${i}`, | ||
})); | ||
}); | ||
}; | ||
|
||
return { | ||
measuresData: dataMap(data, measures), | ||
targetData: dataMap(data, target), | ||
rangesData: dataMap(data, ranges), | ||
}; | ||
} | ||
|
||
export const Bullet: CC<BulletOptions> = (options) => { | ||
const PUBLIC_OPTIONS = { | ||
encode: { | ||
x: 'x', | ||
y: 'y', | ||
color: 'color', | ||
}, | ||
}; | ||
const DEFAULT_RANGES_OPTIONS = { | ||
type: 'interval', | ||
transform: [{ type: 'stackY' }], | ||
encode: { | ||
size: 50, | ||
}, | ||
scale: { | ||
color: { | ||
range: ['#FFBCB8', '#FFE0B0', '#BFEEC8'], | ||
independent: true, | ||
}, | ||
}, | ||
axis: { | ||
x: { | ||
title: '', | ||
tick: null, | ||
labelFontWeight: 600, | ||
}, | ||
y: { | ||
grid: null, | ||
title: null, | ||
}, | ||
}, | ||
legend: false, | ||
style: { | ||
fillOpacity: 0.5, | ||
}, | ||
}; | ||
const DEFAULT_MEASURES_OPTIONS = { | ||
type: 'interval', | ||
transform: [{ type: 'stackY' }], | ||
scale: { | ||
color: { | ||
range: ['#5B8FF9', '#61DDAA'], | ||
independent: true, | ||
}, | ||
}, | ||
encode: { | ||
size: 40, | ||
}, | ||
labels: [ | ||
{ | ||
text: 'y', | ||
position: 'inside', | ||
}, | ||
], | ||
legend: false, | ||
}; | ||
const DEFAULT_TARGET_OPTIONS = { | ||
type: 'point', | ||
encode: { | ||
size: 10, | ||
}, | ||
scale: { | ||
color: { | ||
range: '#39a3f4', | ||
independent: true, | ||
}, | ||
}, | ||
style: { | ||
lineWidth: 2, | ||
}, | ||
legend: false, | ||
}; | ||
return (viewOptions) => { | ||
const { coordinate = {} } = viewOptions; | ||
const { | ||
data = {}, | ||
encode = {}, | ||
scale = {}, | ||
style = {}, | ||
animate = {}, | ||
...rest | ||
} = options; | ||
|
||
const { measuresData, targetData, rangesData } = dataTransform( | ||
data, | ||
encode, | ||
); | ||
const isTranspose = coordinate?.transform?.some( | ||
(tran) => tran.type === 'transpose', | ||
); | ||
return [ | ||
deepMix({}, PUBLIC_OPTIONS, DEFAULT_RANGES_OPTIONS, { | ||
data: rangesData, | ||
encode: subObject(encode, 'ranges'), | ||
scale: subObject(scale, 'ranges'), | ||
style: subObject(style, 'ranges'), | ||
animate: maybeAnimation(animate, 'ranges'), | ||
...rest, | ||
}), | ||
deepMix({}, PUBLIC_OPTIONS, DEFAULT_MEASURES_OPTIONS, { | ||
data: measuresData, | ||
encode: subObject(encode, 'measures'), | ||
scale: subObject(scale, 'measures'), | ||
style: subObject(style, 'measures'), | ||
animate: maybeAnimation(animate, 'measures'), | ||
...rest, | ||
}), | ||
deepMix({}, PUBLIC_OPTIONS, DEFAULT_TARGET_OPTIONS, { | ||
data: targetData, | ||
encode: { | ||
shape: isTranspose ? 'line' : 'hyphen', | ||
...subObject(encode, 'target'), | ||
}, | ||
scale: subObject(scale, 'target'), | ||
style: subObject(style, 'target'), | ||
animate: maybeAnimation(animate, 'target'), | ||
...rest, | ||
}), | ||
]; | ||
}; | ||
}; | ||
|
||
Bullet.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
Oops, something went wrong.