Skip to content

Commit

Permalink
chord: 单测更新
Browse files Browse the repository at this point in the history
  • Loading branch information
Leannechn committed Jan 26, 2021
1 parent fe4170c commit 1cc477b
Show file tree
Hide file tree
Showing 17 changed files with 95 additions and 86 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bizcharts",
"version": "4.1.4-beta.1",
"version": "4.1.4",
"description": "bizcharts",
"keywords": [
"bizcharts",
Expand Down
2 changes: 1 addition & 1 deletion src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ registerEngine('svg', SVGEngine);

// @ts-ignore
export * from '@antv/g2/lib/core';
export const VERSION = '4.1.4-beta.1';
export const VERSION = '4.1.4';


// fixme: supportCSSTransform 在[email protected] 后支持
Expand Down
33 changes: 21 additions & 12 deletions src/createPlot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const DEFAULT_PLACEHOLDER = (
暂无数据
</div>
);
const TITLE_HEIGHT = 30;
const DESCRIPTION_HEIGHT = 34;

const DESCRIPTION_STYLE: CSSProperties = {
padding: '8px 24px 10px 10px',
Expand All @@ -36,18 +38,22 @@ const DESCRIPTION_STYLE: CSSProperties = {
color: 'grey',
textAlign: 'left',
lineHeight: '16px',
position: 'absolute',
top: 0,
left: 0,
height: TITLE_HEIGHT,
};

const TITLE_HEIGHT = 30;
const DESCRIPTION_HEIGHT = 34;

const TITLE_STYLE: CSSProperties = {
padding: '10px 0 0 10px',
fontFamily: 'PingFang SC',
fontSize: 18,
color: 'black',
textAlign: 'left',
lineHeight: '20px',
position: 'absolute',
left: 0,
height: DESCRIPTION_HEIGHT,
};

interface BasePlotOptions {
Expand Down Expand Up @@ -240,11 +246,12 @@ function createPlot<IPlotConfig extends Record<string, any>>(
const descriptionCfg = visibleHelper(description, false) as any;

let diffHeight = 0;
const titleStyle = {...TITLE_STYLE, ...titleCfg.style};
const descStyle = { ...DESCRIPTION_STYLE, ...descriptionCfg.style, top: titleStyle.height };

if (titleCfg.visible) {
// 兼容1.0 plot title的高度, 简单兼容
realCfg.height && (realCfg.height -= TITLE_HEIGHT);
diffHeight += TITLE_HEIGHT;
diffHeight += titleStyle.height;
}

if (!isNil(forceFit)) {
Expand All @@ -253,25 +260,27 @@ function createPlot<IPlotConfig extends Record<string, any>>(

if (descriptionCfg.visible) {
// 兼容1.0 plot description的高度
realCfg.height && (realCfg.height -= DESCRIPTION_HEIGHT);
diffHeight += DESCRIPTION_HEIGHT;
diffHeight += descStyle.height;
}

return <ErrorBoundary FallbackComponent={FallbackComponent} {...ErrorBoundaryProps}>
<div className="bizcharts-plot" style={{ position:'relative', height: props.height || '100%', width: props.width || '100%' }}>
<div className="bizcharts-plot" style={{ position:'relative', display: 'flex', flexDirection: 'column', height: props.height || '100%', width: props.width || '100%' }}>
{/* title 不一定有 */}
{ titleCfg.visible && <div {...polyfillTitleEvent(realCfg)} className="bizcharts-plot-title" style={{...TITLE_STYLE, ...titleCfg.style}}>{titleCfg.text}</div> }
{ titleCfg.visible && <div {...polyfillTitleEvent(realCfg)} className="bizcharts-plot-title" style={titleStyle}>{titleCfg.text}</div> }
{/* description 不一定有 */}
{ descriptionCfg.visible && <div {...polyfillDescriptionEvent(realCfg)} className="bizcharts-plot-description" style={{ ...DESCRIPTION_STYLE, ...descriptionCfg.style}}>{descriptionCfg.text}</div> }
{ descriptionCfg.visible && <div {...polyfillDescriptionEvent(realCfg)} className="bizcharts-plot-description" style={descStyle}>{descriptionCfg.text}</div> }
<BxPlot
// API 统一
appendPadding={[10, 5, 10, 10]}
appendPadding={[10 + diffHeight, 5, 10, 10]}
autoFit={isNil(autoFit) ? forceFit : autoFit}
ref={ref}
{...realCfg}
PlotClass={Plot}
containerStyle={{
height: `calc(100% - ${diffHeight}px)`
// 精度有误差
top: 0,
left: 0,
position: 'absolute'
}}
/>
</div>
Expand Down
2 changes: 1 addition & 1 deletion unittest/plots-base/BasePlot-spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe('基础功能-以AreaChart为demo', () => {

test('title、 description 高度计算和dom渲染', () => {
// 图表高度
expect(chart.options.height).toBe(336);
expect(chart.options.height).toBe(400);
// dom 快照
expect(container).toMatchSnapshot();
cleanup();
Expand Down
4 changes: 2 additions & 2 deletions unittest/plots/__snapshots__/CalendarChart-spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports[`Plots-CalendarChart 1.0日历图 1`] = `
Object {
"animation": true,
"appendPadding": Array [
10,
44,
5,
10,
10,
Expand Down Expand Up @@ -1433,7 +1433,7 @@ exports[`Plots-CalendarChart 新版日历图 1`] = `
Object {
"animation": true,
"appendPadding": Array [
10,
44,
5,
10,
10,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports[`Plots-DensityHeatmapChart 基础密度热力图 1`] = `
Object {
"animation": true,
"appendPadding": Array [
10,
44,
5,
10,
10,
Expand Down Expand Up @@ -69,7 +69,7 @@ exports[`Plots-DensityHeatmapChart 旧版密度热力图 1`] = `
Object {
"animation": true,
"appendPadding": Array [
10,
44,
5,
10,
10,
Expand Down
8 changes: 4 additions & 4 deletions unittest/plots/__snapshots__/GaugeChart-spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports[`Plots-GaugeChart 基础仪表图 1`] = `
Object {
"animation": false,
"appendPadding": Array [
10,
44,
5,
10,
10,
Expand All @@ -29,7 +29,7 @@ Object {
},
"data": 0.75,
"endAngle": 0.5235987755982988,
"height": 370,
"height": 400,
"indicator": Object {
"pin": Object {
"style": Object {
Expand Down Expand Up @@ -86,7 +86,7 @@ exports[`Plots-GaugeChart 旧版仪表图 1`] = `
Object {
"animation": false,
"appendPadding": Array [
10,
44,
5,
10,
10,
Expand Down Expand Up @@ -117,7 +117,7 @@ Object {
],
"data": 0.78,
"endAngle": 0.5235987755982988,
"height": 370,
"height": 400,
"indicator": Object {
"pin": Object {
"style": Object {
Expand Down
10 changes: 5 additions & 5 deletions unittest/plots/__snapshots__/GroupedRoseChart-spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports[`Plots-GroupedRoseChart label-inner-bug 1`] = `
Object {
"animation": true,
"appendPadding": Array [
10,
44,
5,
10,
10,
Expand Down Expand Up @@ -129,7 +129,7 @@ exports[`Plots-GroupedRoseChart label-outer-bug 1`] = `
Object {
"animation": true,
"appendPadding": Array [
10,
44,
5,
10,
10,
Expand Down Expand Up @@ -253,7 +253,7 @@ exports[`Plots-GroupedRoseChart label-分组玫瑰图 1`] = `
Object {
"animation": true,
"appendPadding": Array [
10,
44,
5,
10,
10,
Expand Down Expand Up @@ -385,7 +385,7 @@ exports[`Plots-GroupedRoseChart legend-分组玫瑰图 1`] = `
Object {
"animation": true,
"appendPadding": Array [
10,
44,
5,
10,
10,
Expand Down Expand Up @@ -721,7 +721,7 @@ exports[`Plots-GroupedRoseChart tooltip-分组玫瑰图 1`] = `
Object {
"animation": true,
"appendPadding": Array [
10,
44,
5,
10,
10,
Expand Down
4 changes: 2 additions & 2 deletions unittest/plots/__snapshots__/HeatmapChart-spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports[`Plots-HeatmapChart 兼容旧版热力图 1`] = `
Object {
"animation": true,
"appendPadding": Array [
10,
44,
5,
10,
10,
Expand Down Expand Up @@ -577,7 +577,7 @@ exports[`Plots-HeatmapChart 新版热力图基础用法 1`] = `
Object {
"animation": true,
"appendPadding": Array [
10,
44,
5,
10,
10,
Expand Down
4 changes: 2 additions & 2 deletions unittest/plots/__snapshots__/LiquidChart-spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`Plots-LiquidChart 兼容旧版LiquidChart 1`] = `
Object {
"appendPadding": Array [
10,
44,
5,
10,
10,
Expand Down Expand Up @@ -39,7 +39,7 @@ Object {
exports[`Plots-LiquidChart 新版使用 1`] = `
Object {
"appendPadding": Array [
10,
44,
5,
10,
10,
Expand Down
12 changes: 6 additions & 6 deletions unittest/plots/__snapshots__/PieChart-spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Object {
"angleField": "value",
"animation": true,
"appendPadding": Array [
10,
44,
5,
10,
10,
Expand Down Expand Up @@ -38,7 +38,7 @@ Object {
"value": 1.234567898767891e+35,
},
],
"height": 470,
"height": 500,
"label": Object {
"autoHide": false,
"autoRotate": true,
Expand Down Expand Up @@ -127,7 +127,7 @@ Object {
"angleField": "value",
"animation": true,
"appendPadding": Array [
10,
44,
5,
10,
10,
Expand Down Expand Up @@ -160,7 +160,7 @@ Object {
"value": 1.234567898767891e+35,
},
],
"height": 470,
"height": 500,
"label": Object {
"layout": Object {
"cfg": Object {
Expand Down Expand Up @@ -256,7 +256,7 @@ Object {
"angleField": "value",
"animation": true,
"appendPadding": Array [
10,
44,
5,
10,
10,
Expand Down Expand Up @@ -296,7 +296,7 @@ Object {
"value": 1.234567898767891e+35,
},
],
"height": 470,
"height": 500,
"label": Object {
"layout": Object {
"cfg": Object {
Expand Down
Loading

0 comments on commit 1cc477b

Please sign in to comment.