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(tiny): tiny 图的 tooltip 默认给一个格式化,修改 demo 和单测 #1666

Merged
merged 2 commits into from
Sep 29, 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
2 changes: 1 addition & 1 deletion __tests__/unit/plots/tiny-area/index-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ describe('tiny-area', () => {
tooltip: {
showCrosshairs: true,
customContent: (...arg) => {
return `<div class="g2-tooltip">有${arg[1][0]?.value / 1000}千</div>`;
return `有${arg[1][0]?.value / 1000}千`;
},
position: 'bottom',
offset: 0,
Expand Down
2 changes: 1 addition & 1 deletion __tests__/unit/plots/tiny-column/index-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ describe('tiny-column', () => {
tooltip: {
showCrosshairs: true,
customContent: (...arg) => {
return `<div class="g2-tooltip">有${arg[1][0]?.value / 1000}千</div>`;
return `有${arg[1][0]?.value / 1000}千`;
},
position: 'bottom',
offset: 0,
Expand Down
2 changes: 1 addition & 1 deletion __tests__/unit/plots/tiny-line/index-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ describe('tiny-line', () => {
tooltip: {
showCrosshairs: true,
customContent: (...arg) => {
return `<div class="g2-tooltip">有${arg[1][0]?.value / 1000}千</div>`;
return `有${arg[1][0]?.value / 1000}千`;
},
position: 'bottom',
offset: 0,
Expand Down
9 changes: 6 additions & 3 deletions examples/tiny-area/basic/demo/area-style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ const tinyArea = new TinyArea('container', {
autoFit: false,
data: new Array(100).fill(0).map(() => Math.random() * 100),
smooth: true,
lineStyle: {
lineDash: [2, 2],
stroke: 'l(0) 0:#ffffff 0.5:#7ec2f3 1:#1890ff',
line: {
size: 1,
style: {
lineDash: [2, 2],
stroke: 'l(0) 0:#ffffff 0.5:#7ec2f3 1:#1890ff',
},
},
areaStyle: {
fill: 'l(0) 0:#ffffff 0.5:#7ec2f3 1:#1890ff',
Expand Down
4 changes: 3 additions & 1 deletion examples/tiny-area/basic/demo/area.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ const tinyArea = new TinyArea('container', {
data: new Array(100).fill(0).map(() => Math.random() * 100),
smooth: true,
tooltip: {
formatter: (x, y) => `NO.${x}: ${y.toFixed(2)}`,
customContent: function (x, data) {
return `NO.${x}: ${data[0]?.data?.y.toFixed(2)}`;
},
},
});

Expand Down
4 changes: 3 additions & 1 deletion examples/tiny-column/basic/demo/column.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ const tinyColumn = new TinyColumn('container', {
autoFit: false,
data: new Array(100).fill(0).map(() => Math.random() * 100),
tooltip: {
formatter: ({ x, y }) => `NO.${x}: ${y.toFixed(2)}`,
customContent: function (x, data) {
return `NO.${x}: ${data[0]?.data?.y.toFixed(2)}`;
},
},
});

Expand Down
4 changes: 3 additions & 1 deletion examples/tiny-line/basic/demo/line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ const tinyLine = new TinyLine('container', {
data: new Array(100).fill(0).map(() => Math.random() * 100),
smooth: true,
tooltip: {
formatter: ({ x, y }) => `NO.${x}: ${y.toFixed(2)}`,
customContent: function (x, data) {
return `NO.${x}: ${data[0]?.data?.y.toFixed(2)}`;
},
},
});

Expand Down
16 changes: 8 additions & 8 deletions gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ module.exports = {
en: 'Funnel Charts',
},
},
{
slug: 'liquid',
icon: 'other',
title: {
zh: '水波图',
en: 'Liquid Charts',
},
},
{
slug: 'tiny-line',
icon: 'line',
Expand All @@ -168,14 +176,6 @@ module.exports = {
en: 'Tiny Area',
},
},
{
slug: 'liquid',
icon: 'other',
title: {
zh: '水波图',
en: 'Liquid Charts',
},
},
{
slug: 'tiny-column',
icon: 'column',
Expand Down
4 changes: 4 additions & 0 deletions src/plots/tiny-line/constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { get } from '@antv/util';
import { Data } from '../../types';

export const DEFAULT_TOOLTIP_OPTIONS = {
showTitle: false,
shared: true,
showMarkers: false,
customContent: (x: string, data: any[]) => `${get(data, [0, 'data', 'y'], 0).toFixed(1)}`, // 默认给个格式化
containerTpl: '<div class="g2-tooltip"><div class="g2-tooltip-list"></div></div>',
itemTpl: '<span>{value}</span>',
domStyles: {
Expand Down