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

feat: add polar attribute to heatmap #2425

Merged
merged 7 commits into from
Mar 17, 2021
4 changes: 4 additions & 0 deletions docs/api/plots/heatmap.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ Axis mapping.
<description>**optional** _rect | square | circle_</description>

Shapes in thermal grids, density heat maps are not specified.
#### polar
hustcc marked this conversation as resolved.
Show resolved Hide resolved

<description>**optional** _true | false_ </description>

Whether or not we need polar coordinates, default false.
#### sizeRatio
hustcc marked this conversation as resolved.
Show resolved Hide resolved

<description>**optional** _number_</description>
Expand Down
5 changes: 5 additions & 0 deletions docs/api/plots/heatmap.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ order: 23
<description>**可选** _rect | square | circle_</description>

热力格子中的形状,密度热力图不用指定。
#### polar
hustcc marked this conversation as resolved.
Show resolved Hide resolved

<description>**可选** _true | false_ </description>

是否需要极坐标,默认 false。

#### sizeRatio

Expand Down
8 changes: 8 additions & 0 deletions examples/heatmap/basic/demo/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@
"en": "Calendar heatmap plot"
},
"screenshot": "https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*aLbWR5ioU2UAAAAAAAAAAAAAARQnAQ"
},
{
"filename": "polar.ts",
"title": {
"zh": "极坐标色块图",
"en": "Polar heatmap plot"
},
"screenshot": "https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*cNrISYzITTcAAAAAAAAAAAAAARQnAQ"
}
]
}
61 changes: 61 additions & 0 deletions examples/heatmap/basic/demo/polar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { Heatmap } from '@antv/g2plot';

fetch('https://gw.alipayobjects.com/os/antvdemo/assets/data/polar-heatmap.json')
.then((res) => res.json())
.then((data) => {
const heatmapPlot = new Heatmap(document.getElementById('container'), {
data,
xField: 'time',
yField: 'week',
colorField: 'value',
polar: true, // 极坐标属性
legend: true,
color: '#BAE7FF-#1890FF-#1028ff',
heatmapStyle: {
stroke: '#f5f5f5',
opacity: 0.8,
},
meta: {
time: {
type: 'cat',
},
value: {
min: 0,
max: 1,
},
},
xAxis: {
line: null,
grid: null,
tickLine: null,
label: {
offset: 12,
style: {
fill: '#666',
fontSize: 12,
textBaseline: 'top',
},
},
},
yAxis: {
top: true,
line: null,
grid: null,
tickLine: null,
label: {
offset: 0,
style: {
fill: '#fff',
textAlign: 'center',
shadowBlur: 2,
shadowColor: 'rgba(0, 0, 0, .45)',
},
},
},
tooltip: {
showMarkers: false,
},
interactions: [{ type: 'element-active' }],
});
heatmapPlot.render();
});
20 changes: 19 additions & 1 deletion src/plots/heatmap/adaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,23 @@ function label(params: Params<HeatmapOptions>): Params<HeatmapOptions> {
return params;
}

/**
* 极坐标
* @param params
*/
function coordinate(params: Params<HeatmapOptions>): Params<HeatmapOptions> {
const { chart, options } = params;
const { polar } = options;

if (polar) {
chart.coordinate('polar', {
hustcc marked this conversation as resolved.
Show resolved Hide resolved
innerRadius: 0.2,
});
}

return params;
}

/**
* 热力图适配器
* @param chart
Expand All @@ -192,6 +209,7 @@ export function adaptor(params: Params<HeatmapOptions>) {
annotation(),
interaction,
animation,
state
state,
coordinate
)(params);
}
2 changes: 2 additions & 0 deletions src/plots/heatmap/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ export interface HeatmapOptions extends Options {
readonly heatmapStyle?: StyleAttr;
/** 坐标轴映射 */
readonly reflect?: 'x' | 'y';
visiky marked this conversation as resolved.
Show resolved Hide resolved
/** 极坐标属性 */
readonly polar?: boolean;
}