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: remove tiny default formatter & mask in axis not work #1947

Merged
merged 2 commits into from
Nov 19, 2020
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
35 changes: 35 additions & 0 deletions __tests__/bugs/issue-1944-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Line } from '../../src';
import { createDiv } from '../utils/dom';

describe('#1944', () => {
it('xAxis mask', () => {
const uv = [
{ time: '2019-03', value: 35 },
{ time: '2019-04', value: 90 },
{ time: '2019-05', value: 30 },
{ time: '2019-06', value: 45 },
{ time: '2019-07', value: 47 },
];

const line = new Line(createDiv(), {
data: uv,
xField: 'time',
yField: 'value',
xAxis: {
type: 'time',
mask: 'YYYY-MM-DD HH:mm:ss',
},
});

line.render();

// @ts-ignore mask 是放入到 scale 中
expect(line.chart.getXScale().mask).toBe('YYYY-MM-DD HH:mm:ss');
// label tick 是经过格式化的
expect(line.chart.getController('axis').getComponents()[0].component.get('ticks')[0].name).toBe(
'2019-03-01 00:00:00'
);

line.destroy();
});
});
7 changes: 5 additions & 2 deletions __tests__/unit/plots/tiny-column/index-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { partySupport } from '../../../data/party-support';
import { createDiv } from '../../../utils/dom';

describe('tiny-column', () => {
it.only('data', () => {
it('data', () => {
const tinyColumn = new TinyColumn(createDiv(), {
width: 200,
height: 100,
Expand All @@ -26,7 +26,7 @@ describe('tiny-column', () => {
expect(tinyColumn.chart.geometries[0].elements.length).toBe(52);

tinyColumn.chart.showTooltip({ x: 10, y: 10 });
expect(tinyColumn.container.querySelector('.g2-tooltip').innerHTML).toBe('4600.0');
expect(tinyColumn.container.querySelector('.g2-tooltip').innerHTML).toBe('4600');

tinyColumn.destroy();
});
Expand Down Expand Up @@ -157,6 +157,9 @@ describe('tiny-column', () => {
const { position } = geometry.attributeOption;
expect(position.fields).toEqual(['x', 'y']);

tinyColumn.chart.showTooltip({ x: 10, y: 10 });
expect(tinyColumn.container.querySelector('.g2-tooltip').innerHTML).toBe('有4.1千');

tinyColumn.destroy();
});

Expand Down
5 changes: 4 additions & 1 deletion __tests__/unit/plots/tiny-line/index-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('tiny-line', () => {
expect(tinyLine.chart.geometries[0].elements.length).toBe(1);

tinyLine.chart.showTooltip({ x: 10, y: 10 });
expect(tinyLine.container.querySelector('.g2-tooltip').innerHTML).toBe('4100.0');
expect(tinyLine.container.querySelector('.g2-tooltip').innerHTML).toBe('4100');

tinyLine.destroy();
});
Expand Down Expand Up @@ -163,6 +163,9 @@ describe('tiny-line', () => {
const { position } = geometry.attributeOption;
expect(position.fields).toEqual(['x', 'y']);

tinyLine.chart.showTooltip({ x: 10, y: 10 });
expect(tinyLine.container.querySelector('.g2-tooltip').innerHTML).toBe('有4.1千');

tinyLine.destroy();
});

Expand Down
2 changes: 2 additions & 0 deletions src/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export const AXIS_META_CONFIG_KEYS = [
'base',
// type: 'exp' 的指数
'exponent',
// time 类型的格式化
'mask',
];

/**
Expand Down
2 changes: 1 addition & 1 deletion src/plots/tiny-column/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const DEFAULT_TOOLTIP_OPTIONS = {
showTitle: false,
shared: true,
showMarkers: false,
customContent: (x: string, data: any[]) => `${get(data, [0, 'data', 'y'], 0).toFixed(1)}`, // 默认给个格式化
customContent: (x: string, data: any[]) => `${get(data, [0, 'data', 'y'], 0)}`, // 默认显示原始数据
containerTpl: '<div class="g2-tooltip"><div class="g2-tooltip-list"></div></div>',
itemTpl: '<span>{value}</span>',
domStyles: {
Expand Down
2 changes: 1 addition & 1 deletion src/plots/tiny-line/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const DEFAULT_TOOLTIP_OPTIONS = {
showTitle: false,
shared: true,
showMarkers: false,
customContent: (x: string, data: any[]) => `${get(data, [0, 'data', 'y'], 0).toFixed(1)}`, // 默认给个格式化
customContent: (x: string, data: any[]) => `${get(data, [0, 'data', 'y'], 0)}`, // 默认显示原始数据
containerTpl: '<div class="g2-tooltip"><div class="g2-tooltip-list"></div></div>',
itemTpl: '<span>{value}</span>',
domStyles: {
Expand Down