Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(label): support date label #5077

Merged
merged 1 commit into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion __tests__/integration/spec-static.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ describe('Charts', () => {
it(`[Canvas]: ${name}`, async () => {
try {
// @ts-ignore
const { maxError = 0 } = generateOptions;
const { maxError = 0, before, after } = generateOptions;
before?.();
gCanvas = await renderSpec(generateOptions);
after?.();
const dir = `${__dirname}/snapshots/static`;
await expect(gCanvas).toMatchCanvasSnapshot(dir, name, { maxError });
} finally {
Expand Down
29 changes: 29 additions & 0 deletions __tests__/plots/static/aapl-interval-date-encode-x.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { G2Spec } from '../../../src';

export function aaplIntervalDateEncodeX(): G2Spec {
return {
type: 'interval',
padding: 'auto',
height: 720,
data: {
type: 'fetch',
value: 'data/aapl.csv',
transform: [{ type: 'slice', start: 0, end: 10 }],
},
encode: {
x: 'date',
y: 'close',
},
};
}

let toString;

aaplIntervalDateEncodeX.before = () => {
toString = Date.prototype.toString;
Date.prototype.toString = Date.prototype.toUTCString;
};

aaplIntervalDateEncodeX.after = () => {
Date.prototype.toString = toString;
};
1 change: 1 addition & 0 deletions __tests__/plots/static/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,4 @@ export { populationIntervalDivergingAutoPaddingUndefinedTitle } from './populati
export { tranLineMultiAxesAutoPaddingTickMethod } from './train-line-multi-axes-auto-padding-tick-method';
export { vaccinesCellScaleRelationAutoPaddingTickFilter } from './vaccines-cell-scale-relation-auto-padding-tick-filter';
export { marketIntervalMarimekkoAutoPaddingFlex } from './market-interval-marimekko-auto-padding-flex';
export { aaplIntervalDateEncodeX } from './aapl-interval-date-encode-x';
7 changes: 6 additions & 1 deletion src/component/axis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,12 @@ function getData(

const ticks = ticksOf(scale, domain, tickMethod);
const filteredTicks = tickFilter ? ticks.filter(tickFilter) : ticks;
const toString = (d) => (typeof d === 'object' && !!d ? d : String(d));
const toString = (d) =>
d instanceof Date
? String(d)
pearmini marked this conversation as resolved.
Show resolved Hide resolved
: typeof d === 'object' && !!d
? d
: String(d);
const labelFormatter =
defaultTickFormatter || scale.getFormatter?.() || toString;
const applyInset = createInset(position, coordinate);
Expand Down