Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { ChartType } from '../../src';
import { getChartSpecWithContext } from '../../src/atom/chartGenerator/spec';
import { parseCSVData } from '../../src/utils/dataTable';

describe('getChartSpecWithContext', () => {
it('should generate correct basic treemap spec', () => {
const { dataset } = parseCSVData(`Category-0,Category-1,Category-2,Category-3,value
query,methods,add,,593
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

模拟数据输入的时候,可以不用这么多数据

query,AggregateExpression,,,1616
util,math,DenseMatrix,,3165
animate,interpolate,ArrayInterpolator,,1983
flex,FlareVis,,,4116`);
const context = {
chartTypeList: Object.values(ChartType),
dataTable: dataset,
command: 'Genarate a basic treemap chart',
cell: {
color: ['Category-0', 'Category-1', 'Category-2', 'Category-3'],
size: 'value'
},
chartType: ChartType.TreemapChart.toUpperCase()
};
const { chartType, spec } = getChartSpecWithContext(context);
expect(chartType).toBe(ChartType.TreemapChart);
expect(spec.type).toBe('treemap');
expect(spec.categoryField).toBe('name');
expect(spec.valueField).toBe('value');
expect(spec.label.visible).toBe(true);
});

it('should generate correct basic treemap spec with one color', () => {
const { dataset } = parseCSVData(`Category-0,value
add,593
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

模拟数据输入的时候,可以不用这么多数据

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改

average,287
count,277
FlareVis,4116`);
const context = {
chartTypeList: Object.values(ChartType),
dataTable: dataset,
command: 'Genarate a basic treemap chart',
cell: {
color: 'Category-0',
size: 'value'
},
chartType: ChartType.TreemapChart.toUpperCase()
};
const { chartType, spec } = getChartSpecWithContext(context);
expect(chartType).toBe(ChartType.TreemapChart);
expect(spec.type).toBe('treemap');
expect(spec.categoryField).toBe('name');
expect(spec.valueField).toBe('value');
expect(spec.label.visible).toBe(true);
});
});