Skip to content

Commit

Permalink
feat(interval): micro interval (#5260)
Browse files Browse the repository at this point in the history
  • Loading branch information
pearmini authored Jul 3, 2023
1 parent 48873ba commit 5190059
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 0 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions __tests__/plots/static/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,4 @@ export { aaplLineMissingDataTrial } from './aapl-line-missing-data-trial';
export { mockAreaMissingData } from './mock-area-missing-data';
export { mockIntervalFacetRectPolar } from './mock-interval-facet-rect-polar';
export { alphabetIntervalAutoRotate } from './alphabet-interval-auto-padding-rotate';
export { mockLineSmallInterval } from './mock-line-small-interval';
49 changes: 49 additions & 0 deletions __tests__/plots/static/mock-line-small-interval.ts
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;
};
59 changes: 59 additions & 0 deletions site/examples/general/interval/demo/bar-range-micro.ts
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();
8 changes: 8 additions & 0 deletions site/examples/general/interval/demo/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@
},
"screenshot": "https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*hTfETY0ObOsAAAAAAAAAAAAADmJ7AQ/original"
},
{
"filename": "bar-range-micro.ts",
"title": {
"zh": "微妙级区间条形图",
"en": "Micro Range Bar Chart"
},
"screenshot": "https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*RGwxTI9J6fwAAAAAAAAAAAAADmJ7AQ/original"
},
{
"filename": "bar-stacked.ts",
"title": {
Expand Down

0 comments on commit 5190059

Please sign in to comment.