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(HotMap): 更新hotmap #380

Merged
merged 5 commits into from
Apr 9, 2024
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
6 changes: 5 additions & 1 deletion src/core/framework.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ export const fetchConfig = (chart: Chart | View, options: ChartOptions, config:
}

// We don't use default legend
chart.legend(false);
if (config.legend) {
chart.legend(config.legend);
} else {
chart.legend(false);
}
chart.interaction('element-active', {
start: [{ trigger: 'element:mouseenter', action: 'cursor:pointer' }],
end: [{ trigger: 'element:mouseleave', action: 'cursor:pointer' }],
Expand Down
52 changes: 48 additions & 4 deletions src/hot-map/demos/HotMap.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ const sourceData = [
},
{
rowDimensionValue: 'N/A',
colDimensionValue: '1*****0',
colDimensionValue:
'1*****01*****01*****01*****01*****01*****01*****01*****01*****01*****01*****01*****01*****01*****01*****0',
userCount: 6,
userRatio: 0.0116,
name: '用户量',
Expand Down Expand Up @@ -165,12 +166,55 @@ const BaseHotMapArgs = {
height: 276,
},
scale: [
'userRatio',
{
nice: true,
colDimensionValue: {
type: 'cat',
},
rowDimensionValue: {
type: 'cat',
},
},
],
axises: [['userRatio', {}]],
axises: [
[
'colDimensionValue',
{
tickLine: null,
grid: {
alignTick: false,
line: {
style: {
lineWidth: 1,
lineDash: null,
stroke: '#f0f0f0',
},
},
},
label: {
style: {
width: 120,
},
autoEllipsis: true,
},
},
],
[
'rowDimensionValue',
{
title: null,
grid: {
alignTick: false,
line: {
style: {
lineWidth: 1,
lineDash: null,
stroke: '#f0f0f0',
},
},
},
},
],
],
hotMap: {
xField: 'rowDimensionValue',
yField: 'colDimensionValue',
Expand Down
56 changes: 17 additions & 39 deletions src/hot-map/framework.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { isEmpty } from 'lodash';
import { ChartConfig, ChartOptions, ChartType } from '../interfaces';
import { BaseChart, generateChart } from '../core/framework';
import { BaseChart, fetchConfig, generateChart } from '../core/framework';
import { getShapeConfig } from '../utils/tools/shapeConfig';
import { formatNumber, formatPercent } from '../utils';
import { formatPercent } from '../utils';

export class HotMap extends BaseChart {
render = (options: ChartOptions, config: ChartConfig = {}) => {
Expand All @@ -13,63 +13,41 @@ export class HotMap extends BaseChart {
if (!id || isEmpty(data)) {
return {};
}
this.instance = generateChart(options, config);

const shapeConfig = getShapeConfig(config, ChartType.HotMap);

const { xField, yField, zField } = shapeConfig;

const { source } = (data || {}) as any;

this.instance.data(source);
this.instance.scale(xField, {
type: 'cat',
values: (data as any)?.[xField] || [],
});
this.instance.scale(yField, {
type: 'cat',
values: (data as any)?.[yField] || [],
});
this.instance.scale('value', {
nice: true,
});
this.instance.axis(xField, {
tickLine: null,
grid: {
alignTick: false,
line: {
if (!isEmpty(source) && source?.length >= 1) {
config.legend = {
position: 'bottom-left',
label: {
formatter: (text: any) => `${formatPercent(text || 0)}`,
style: {
lineWidth: 1,
lineDash: null,
stroke: '#f0f0f0',
fill: '#313E75',
},
},
},
});

this.instance.axis(yField, {
title: null,
grid: {
alignTick: false,
line: {
rail: {
size: 16,
style: {
lineWidth: 1,
lineDash: null,
stroke: '#f0f0f0',
fill: '#fff',
},
},
},
});
};
}

this.instance.tooltip(config.tooltip);
this.instance = generateChart(options, config);
fetchConfig(this.instance, options, config);

this.instance.data(source);

this.instance
.polygon()
.position(`${xField}*${yField}`)
.color(zField, '#F2F3FF-#8EABFF-#0052D9')
.label(zField, {
offset: -2,

style: {
fill: '#fff',
fontSize: 14,
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export interface ChartConfig extends LooseObject {
* 用来显示或隐藏Legend图例
* 在gio-design-charts中,legend被重新定义,G2默认的legend配置将无效,在这里配置legend: false可用来隐藏Legend
*/
legend?: boolean;
legend?: boolean | LooseObject;

legendOptions?: LegendOptions;

Expand Down
Loading