-
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): micro interval (#5260)
- Loading branch information
Showing
5 changed files
with
117 additions
and
0 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.
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,49 @@ | ||
import { G2Spec } from '../../../src'; | ||
|
||
export function mockLineSmallInterval(): G2Spec { | ||
const floatTimestamp = (s) => +new Date(s) + +`0.${s.slice(s.length - 3)}`; | ||
return { | ||
type: 'interval', | ||
padding: 'auto', | ||
data: [ | ||
{ | ||
task: 'task0', | ||
startTime: '2023-06-28 03:30:33.900123', | ||
endTime: '2023-06-28 03:30:33.900678', | ||
status: '0', | ||
}, | ||
{ | ||
task: 'task0', | ||
startTime: '2023-06-28 03:30:33.901123', | ||
endTime: '2023-06-28 03:30:33.902678', | ||
status: '1', | ||
}, | ||
], | ||
encode: { | ||
x: 'task', | ||
y: (d) => floatTimestamp(d.startTime), | ||
y1: (d) => floatTimestamp(d.endTime), | ||
}, | ||
scale: { | ||
y: { | ||
type: 'time', | ||
domain: [ | ||
new Date('2023-06-28 03:30:33.900'), | ||
new Date('2023-06-28 03:30:33.903'), | ||
], | ||
}, | ||
}, | ||
coordinate: { transform: [{ type: 'transpose' }] }, | ||
}; | ||
} | ||
|
||
let toString; | ||
|
||
mockLineSmallInterval.before = () => { | ||
toString = Date.prototype.toString; | ||
Date.prototype.toString = Date.prototype.toUTCString; | ||
}; | ||
|
||
mockLineSmallInterval.after = () => { | ||
Date.prototype.toString = toString; | ||
}; |
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,59 @@ | ||
import { Chart } from '@antv/g2'; | ||
|
||
const floatTimestamp = (s) => +new Date(s) + +`0.${s.slice(s.length - 3)}`; | ||
|
||
const format = (n) => { | ||
const x = Math.floor(n); | ||
const s = n + ''; | ||
const d = new Date(x); | ||
const Y = d.getFullYear(); | ||
const M = d.getMonth() + 1; | ||
const D = d.getDate(); | ||
const H = d.getHours(); | ||
const MN = d.getMinutes(); | ||
const S = d.getSeconds(); | ||
const MS = d.getMilliseconds(); | ||
const MCM = s.slice(s.length - 3); | ||
return `${Y}-${M}-${D} ${H}:${MN}:${S}.${MS}${MCM}`; | ||
}; | ||
|
||
const chart = new Chart({ | ||
container: 'container', | ||
theme: 'classic', | ||
autoFit: true, | ||
padding: 'auto', | ||
}); | ||
|
||
chart | ||
.interval() | ||
.data([ | ||
{ | ||
task: 'task0', | ||
startTime: '2023-06-28 03:30:33.900123', // micro seconds | ||
endTime: '2023-06-28 03:30:33.900678', // micro seconds | ||
status: '0', | ||
}, | ||
{ | ||
task: 'task0', | ||
startTime: '2023-06-28 03:30:33.901123', | ||
endTime: '2023-06-28 03:30:33.902678', | ||
status: '1', | ||
}, | ||
]) | ||
.encode('x', 'task') | ||
// Add float part to distinguish y and y1 | ||
.encode('y', (d) => floatTimestamp(d.startTime)) | ||
.encode('y1', (d) => floatTimestamp(d.endTime)) | ||
.encode('color', 'status') | ||
.scale('y', { | ||
type: 'time', | ||
domain: [ | ||
new Date('2023-06-28 03:30:33.900'), | ||
new Date('2023-06-28 03:30:33.903'), | ||
], | ||
}) | ||
.coordinate({ transform: [{ type: 'transpose' }] }) | ||
.tooltip({ channel: 'y', valueFormatter: format }) | ||
.tooltip({ channel: 'y1', valueFormatter: format }); | ||
|
||
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