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

chore: 迷你图走查 + demo #1528

Merged
merged 7 commits into from
Sep 5, 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
37 changes: 20 additions & 17 deletions __tests__/unit/plots/progress/index-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ describe('progress', () => {
expect(progress.chart.geometries[0].elements[1].shape.attr('fill')).toBe('#E8EDF3');

progress.update({
width: 200,
height: 100,
...progress.options,
percent: 0.5,
autoFit: false,
});
expect(progress.chart.geometries[0].elements[0].getData().type).toBe('current');
expect(progress.chart.geometries[0].elements[0].getData().percent).toBe(0.5);
Expand Down Expand Up @@ -50,11 +48,8 @@ describe('progress', () => {
expect(progress.chart.geometries[0].elements[1].shape.attr('fill')).toBe('#654321');

progress.update({
width: 200,
height: 100,
percent: 0.6,
color: () => ['#654321', '#123456'],
autoFit: false,
...progress.options,
color: ['#654321', '#123456'],
});
expect(progress.chart.geometries[0].elements[0].getData().type).toBe('current');
expect(progress.chart.geometries[0].elements[0].getData().percent).toBe(0.6);
Expand Down Expand Up @@ -91,7 +86,7 @@ describe('progress', () => {
expect(progress.chart.geometries[0].elements[1].shape.attr('lineWidth')).toBe(2);
expect(progress.chart.geometries[0].elements[1].shape.attr('lineDash')).toEqual([2, 2]);

const progressStyle = (x, percent, type) => {
const progressStyle = (percent, type) => {
if (type === 'current') {
return percent > 0.5
? {
Expand Down Expand Up @@ -120,11 +115,8 @@ describe('progress', () => {
};

progress.update({
width: 200,
height: 100,
percent: 0.6,
...progress.options,
progressStyle,
autoFit: false,
});
expect(progress.chart.geometries[0].elements[0].getData().type).toBe('current');
expect(progress.chart.geometries[0].elements[0].getData().percent).toBe(0.6);
Expand All @@ -140,11 +132,8 @@ describe('progress', () => {
expect(progress.chart.geometries[0].elements[1].shape.attr('lineDash')).toEqual([4, 4]);

progress.update({
width: 200,
height: 100,
...progress.options,
percent: 0.4,
progressStyle,
autoFit: false,
});

expect(progress.chart.geometries[0].elements[0].getData().type).toBe('current');
Expand All @@ -160,4 +149,18 @@ describe('progress', () => {
expect(progress.chart.geometries[0].elements[1].shape.attr('lineWidth')).toBe(4);
expect(progress.chart.geometries[0].elements[1].shape.attr('lineDash')).toEqual([4, 4]);
});

it('barWidthRatio', () => {
const progress = new Progress(createDiv(), {
width: 200,
height: 100,
percent: 0.6,
barWidthRatio: 0.1,
autoFit: false,
});

progress.render();

expect(progress.chart.getTheme().columnWidthRatio).toBe(0.1);
});
});
208 changes: 96 additions & 112 deletions __tests__/unit/plots/ring-progress/index-spec.ts

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions __tests__/unit/plots/tiny-area/index-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ describe('tiny-area', () => {
return item.value;
}),
autoFit: false,
tooltip: true,
});

tinyArea.render();
Expand All @@ -127,7 +126,7 @@ describe('tiny-area', () => {
expect(tooltipOption.containerTpl).toBe('<div class="g2-tooltip"><div class="g2-tooltip-list"></div></div>');
expect(tooltipOption.domStyles).toEqual({
'g2-tooltip': {
padding: '2px',
padding: '2px 4px',
fontSize: '10px',
},
});
Expand Down
28 changes: 25 additions & 3 deletions __tests__/unit/plots/tiny-column/index-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('tiny-column', () => {
width: 200,
height: 100,
meta: {
value: {
y: {
min: 0,
max: 5000,
},
Expand Down Expand Up @@ -86,7 +86,6 @@ describe('tiny-column', () => {
return item.value;
}),
autoFit: false,
tooltip: true,
});

tinyColumn.render();
Expand All @@ -100,7 +99,7 @@ describe('tiny-column', () => {
expect(tooltipOption.containerTpl).toBe('<div class="g2-tooltip"><div class="g2-tooltip-list"></div></div>');
expect(tooltipOption.domStyles).toEqual({
'g2-tooltip': {
padding: '2px',
padding: '2px 4px',
fontSize: '10px',
},
});
Expand Down Expand Up @@ -150,4 +149,27 @@ describe('tiny-column', () => {
expect(geometryTooltipOption.fields).toEqual(['x', 'y']);
expect(geometryTooltipOption.callback(1, '3000')).toEqual({ value: '有3千' });
});

it('columnWidthRatio', () => {
const tinyColumn = new TinyColumn(createDiv(), {
width: 400,
height: 100,
meta: {
y: {
min: 0,
max: 5000,
},
},
data: partySupport
.filter((o) => o.type === 'FF')
.map((item) => {
return item.value;
}),
autoFit: false,
columnWidthRatio: 0.9,
});

tinyColumn.render();
expect(tinyColumn.chart.getTheme().columnWidthRatio).toBe(0.9);
});
});
23 changes: 10 additions & 13 deletions __tests__/unit/plots/tiny-line/index-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,12 @@ describe('tiny-line', () => {
const tinyLine = new TinyLine(createDiv(), {
width: 80,
height: 40,
meta: {
value: {
min: 0,
max: 5000,
},
},
data: partySupport
.filter((o) => o.type === 'FF')
.map((item) => {
return item.value;
}),
autoFit: false,
autoFit: true,
});

tinyLine.render();
Expand All @@ -32,7 +26,7 @@ describe('tiny-line', () => {
width: 80,
height: 40,
meta: {
value: {
y: {
min: 0,
max: 5000,
},
Expand All @@ -42,7 +36,7 @@ describe('tiny-line', () => {
.map((item) => {
return item.value;
}),
autoFit: false,
autoFit: true,
smooth: true,
});

Expand All @@ -63,7 +57,11 @@ describe('tiny-line', () => {
lineStyle: {
lineDash: [2, 2],
},
autoFit: false,
tooltip: {
showCrosshairs: true,
showMarkers: true,
},
autoFit: true,
appendPadding: 10,
});

Expand Down Expand Up @@ -91,8 +89,7 @@ describe('tiny-line', () => {
.map((item) => {
return item.value;
}),
autoFit: false,
tooltip: true,
autoFit: true,
});

tinyLine.render();
Expand All @@ -106,7 +103,7 @@ describe('tiny-line', () => {
expect(tooltipOption.containerTpl).toBe('<div class="g2-tooltip"><div class="g2-tooltip-list"></div></div>');
expect(tooltipOption.domStyles).toEqual({
'g2-tooltip': {
padding: '2px',
padding: '2px 4px',
fontSize: '10px',
},
});
Expand Down
40 changes: 40 additions & 0 deletions examples/progress/basic/demo/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"title": {
"zh": "中文分类",
"en": "Category"
},
"demos": [
{
"filename": "progress.ts",
"title": {
"zh": "迷你进度条图",
"en": "basic Progress chart"
},
"screenshot": "https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*nBhpT5HbGOAAAAAAAAAAAABkARQnAQ"
},
{
"filename": "progress-style.ts",
"title": {
"zh": "迷你进度条图样式",
"en": "Tiny Progress style"
},
"screenshot": "https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*fQihRrLMIWsAAAAAAAAAAABkARQnAQ"
},
{
"filename": "progress-style-callback.ts",
"title": {
"zh": "迷你进度条图回调样式",
"en": "Tiny Progress style callback"
},
"screenshot": "https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*lSOiS4lGCaIAAAAAAAAAAABkARQnAQ"
},
{
"filename": "progress-width.ts",
"title": {
"zh": "迷你进度条图大小",
"en": "Tiny Progress width"
},
"screenshot": "https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*4NmuSaVRZ44AAAAAAAAAAABkARQnAQ"
}
]
}
16 changes: 16 additions & 0 deletions examples/progress/basic/demo/progress-style-callback.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Progress } from '@antv/g2plot';

const progress = new Progress('container', {
height: 100,
width: 300,
autoFit: false,
hustcc marked this conversation as resolved.
Show resolved Hide resolved
percent: 0.7,
progressStyle: (percent: number, type: string) => {
if (type === 'current') {
return { fill: 'green' };
}
return { fill: '#999', lineDash: [1, 1], stroke: '#333' };
},
});

progress.render();
15 changes: 15 additions & 0 deletions examples/progress/basic/demo/progress-style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Progress } from '@antv/g2plot';

const progress = new Progress('container', {
height: 100,
width: 300,
autoFit: false,
percent: 0.7,
progressStyle: {
stroke: 'grey',
lineDash: [4, 4],
lineWidth: 1,
},
});

progress.render();
11 changes: 11 additions & 0 deletions examples/progress/basic/demo/progress-width.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Progress } from '@antv/g2plot';

const progress = new Progress('container', {
height: 100,
width: 300,
autoFit: false,
percent: 0.7,
barWidthRatio: 0.1,
});

progress.render();
10 changes: 10 additions & 0 deletions examples/progress/basic/demo/progress.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Progress } from '@antv/g2plot';

const progress = new Progress('container', {
height: 100,
width: 300,
autoFit: false,
percent: 0.7,
});

progress.render();
5 changes: 5 additions & 0 deletions examples/progress/basic/design.en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: 设计规范
---

设计规范
5 changes: 5 additions & 0 deletions examples/progress/basic/design.zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: 设计规范
---

设计规范
4 changes: 4 additions & 0 deletions examples/progress/basic/index.en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
title: 进度条图
order: 0
---
4 changes: 4 additions & 0 deletions examples/progress/basic/index.zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
title: 进度条图
order: 0
---
40 changes: 40 additions & 0 deletions examples/ring-progress/basic/demo/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"title": {
"zh": "中文分类",
"en": "Category"
},
"demos": [
{
"filename": "ring-progress.ts",
"title": {
"zh": "迷你进度环图",
"en": "basic Ring chart"
},
"screenshot": "https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*nBhpT5HbGOAAAAAAAAAAAABkARQnAQ"
},
{
"filename": "ring-progress-style.ts",
"title": {
"zh": "迷你进度环图样式",
"en": "Tiny Ring style"
},
"screenshot": "https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*fQihRrLMIWsAAAAAAAAAAABkARQnAQ"
},
{
"filename": "ring-progress-style-callback.ts",
"title": {
"zh": "迷你进度环图回调样式",
"en": "Tiny Ring style callback"
},
"screenshot": "https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*lSOiS4lGCaIAAAAAAAAAAABkARQnAQ"
},
{
"filename": "ring-progress-radius.ts",
"title": {
"zh": "迷你进度环图半径大小",
"en": "Tiny Ring radius"
},
"screenshot": "https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*4NmuSaVRZ44AAAAAAAAAAABkARQnAQ"
}
]
}
12 changes: 12 additions & 0 deletions examples/ring-progress/basic/demo/ring-progress-radius.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { RingProgress } from '@antv/g2plot';

const ringProgress = new RingProgress('container', {
height: 100,
width: 100,
autoFit: false,
percent: 0.7,
innerRadius: 0.95,
radius: 0.95,
});

ringProgress.render();
Loading