Skip to content
This repository has been archived by the owner on Oct 7, 2023. It is now read-only.

Commit

Permalink
feat(timebar): add timebar
Browse files Browse the repository at this point in the history
  • Loading branch information
Aarebecca committed Aug 28, 2023
1 parent 77b62a3 commit 268b1e5
Show file tree
Hide file tree
Showing 15 changed files with 674 additions and 26 deletions.
2 changes: 1 addition & 1 deletion __tests__/integration/components/timebar/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const TimebarController = it((group) => {
height: 50,
speed: 2,
align: 'right',
chartType: 'bar',
chartType: 'column',
selectionType: 'value',
},
})
Expand Down
3 changes: 3 additions & 0 deletions __tests__/integration/components/timebar/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
export * from './icons';
export * from './handle';
export * from './controller';
export * from './timebar-basic';
export * from './timebar-time';
export * from './timebar-chart';
51 changes: 51 additions & 0 deletions __tests__/integration/components/timebar/timebar-basic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { it } from '../../utils';
import { Timebar } from '../../../../src/ui/timebar';

export const TimebarBasic = it({ width: 500, height: 150 }, (group) => {
const start = new Date('2023-08-01');
const interval = 'day';
const diff = 3600 * 24 * 1000;
const data = [10, 2, 3, 4, 15, 10, 5, 0, 3, 1].map((value, index) => ({
time: new Date(start.getTime() + index * diff),
value,
}));
group.appendChild(
new Timebar({
style: {
type: 'chart',
width: 500,
height: 150,
data,
interval,
values: [0.25, 0.75],
onChange: (value) => {
console.log('onChange', value);
},
onReset: () => {
console.log('onReset');
},
onSpeedChange: (speed) => {
console.log('onSpeedChange', speed);
},
onBackward: () => {
console.log('onBackward');
},
onPlay: () => {
console.log('onPlay');
},
onPause: () => {
console.log('onPause');
},
onForward: () => {
console.log('onForward');
},
onSelectionTypeChange: (type) => {
console.log('onSelectionTypeChange', type);
},
onChartTypeChange: (type) => {
console.log('onChartTypeChange', type);
},
},
})
);
});
75 changes: 75 additions & 0 deletions __tests__/integration/components/timebar/timebar-chart.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { it } from '../../utils';
import { Timebar } from '../../../../src/ui/timebar';

export const TimebarChart = it((group) => {
const start = new Date('2023-08-01');
const interval = 'day';
const diff = 3600 * 24 * 1000;
const data = [10, 2, 3, 4, 15, 10, 5, 0, 3, 1].map((value, index) => ({
time: new Date(start.getTime() + index * diff),
value,
}));
group.appendChild(
new Timebar({
style: {
x: 0,
y: 0,
type: 'chart',
height: 100,
width: 500,
interval,
data,
values: [0.25, 0.75],
},
})
);

group.appendChild(
new Timebar({
style: {
x: 0,
y: 110,
height: 100,
width: 500,
data,
interval,
values: [0, 0.4],
type: 'chart',
selectionType: 'value',
},
})
);

group.appendChild(
new Timebar({
style: {
x: 0,
y: 220,
height: 100,
width: 500,
data,
interval,
values: [0.1, 0.9],
type: 'chart',
chartType: 'column',
},
})
);

group.appendChild(
new Timebar({
style: {
x: 0,
y: 330,
height: 100,
width: 500,
data,
interval,
values: [0, 0.6],
type: 'chart',
chartType: 'column',
selectionType: 'value',
},
})
);
});
47 changes: 47 additions & 0 deletions __tests__/integration/components/timebar/timebar-time.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { it } from '../../utils';
import { Timebar } from '../../../../src/ui/timebar';

export const TimebarTime = it((group) => {
group.appendChild(
new Timebar({
style: {
x: 10,
y: 20,
type: 'time',
height: 50,
width: 500,
values: [0.25, 0.75],
},
})
);

group.appendChild(
new Timebar({
style: {
x: 10,
y: 90,
type: 'time',
height: 50,
width: 500,
values: [0, 0.5],
selectionType: 'value',
},
})
);

group.appendChild(
new Timebar({
style: {
x: 10,
y: 160,
type: 'time',
height: 50,
width: 500,
values: [0, 0.5],
selectionType: 'value',
speed: 1.5,
playing: true,
},
})
);
});
Binary file added __tests__/integration/snapshots/TimebarBasic.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added __tests__/integration/snapshots/TimebarChart.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added __tests__/integration/snapshots/TimebarTime.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@
"devDependencies": {
"@antv/g": "^5.14.1",
"@antv/g-canvas": "^1.9.18",
"@antv/g-plugin-control": "^1.9.6",
"@antv/g-svg": "^1.8.27",
"@antv/g-webgl": "^1.9.6",
"@antv/g-plugin-control": "^1.9.6",
"@babel/plugin-proposal-decorators": "^7.20.5",
"@babel/plugin-transform-runtime": "^7.17.0",
"@babel/preset-env": "^7.16.11",
Expand All @@ -83,12 +83,13 @@
"@typescript-eslint/parser": "^4.19.0",
"@vitejs/plugin-react": "^2.2.0",
"ali-oss": "^6.17.1",
"archiver": "^5.3.1",
"antd": "^5.0.2",
"archiver": "^5.3.1",
"babel-loader": "^8.2.3",
"canvas": "2.11.0",
"core-js": "^3.14.0",
"cross-env": "^7.0.3",
"dayjs": "^1.11.9",
"eslint": "^7.22.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-config-prettier": "^8.1.0",
Expand Down
2 changes: 1 addition & 1 deletion src/ui/timebar/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class Controller extends GUI<ControllerStyleProps> {
style.onChange = (value: any) => this.handleFunctionChange(name, { value });
if (Ctor === PlayPause) style.type = this.attributes.playing ? 'pause' : 'play';
if (Ctor === SelectionType) style.type = this.attributes.selectionType === 'range' ? 'value' : 'range';
if (Ctor === ChartType) style.type = this.attributes.chartType === 'line' ? 'bar' : 'line';
if (Ctor === ChartType) style.type = this.attributes.chartType === 'line' ? 'column' : 'line';
} else {
// IconBase
style.onClick = () => this.handleFunctionChange(name, { value: name });
Expand Down

0 comments on commit 268b1e5

Please sign in to comment.