in src/Wheatmap/index.tsx [62:167]
init(chart: Chart, config: WheatmapConfig, data: any) {
const defs: Record<string, Types.ScaleOption> = {
x: propertyAssign(
propertyMap.axis,
{
type: 'cat',
},
config.xAxis,
),
y: propertyAssign(
propertyMap.axis,
{
type: 'cat',
},
config.yAxis,
),
type: {
type: 'cat',
},
};
chart.scale(defs);
chart.data(data);
if (config.coordinate) {
const { type = 'rect', reflect } = config.coordinate;
const coord = chart.coordinate(type);
if (reflect) {
coord.reflect(reflect);
}
}
// 设置单个Y轴
rectYAxis(this, chart, config, undefined, {
grid: null,
});
// 设置X轴
rectXAxis(this, chart, config);
chart.legend('x', false);
chart.legend('y', false);
// 设置图例
rectLegend(this, chart, config, {}, 'multiple', 'type');
legendFilter(this, chart);
// tooltip
rectTooltip(
this,
chart,
config,
{
showMarkers: false,
showCrosshairs: false,
},
null,
{
showTitle: false,
showMarkers: false,
showCrosshairs: false,
},
);
// 绘制辅助线,辅助背景区域
guide(chart, config);
const geom = chart
.polygon()
.position('x*y')
.color('type', config.colors)
.tooltip('x*y*extra', (x, y, extra) => {
const val = Array.isArray(extra) ? extra[0] : extra.value;
return {
name: `${x} - ${y}`,
value: val || val === 0 ? val : '-',
};
});
geomStyle(geom, config.geomStyle, {
lineWidth: 1,
stroke: themes['widgets-map-area-border'],
});
label({
geom: geom,
config: config,
useCustomOffset: true,
componentConfig: {
position: 'middle',
offset: 0,
content(data, item, i) {
if (!config.label) {
return;
}
const val = Array.isArray(data.extra) ? data.extra[0] : data.extra.value;
let result = val || val === 0 ? val : '-';
if (typeof config.label === 'object' && config.label.labelFormatter) {
result = config.label.labelFormatter(result, item, i);
}
return result;
},
},
});
}