@alicloud/cloud-charts
Version:

106 lines (102 loc) • 3.1 kB
JavaScript
;
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import Base from '../common/Base';
import { DataSet } from '@antv/data-set/lib/data-set';
import errorWrap from '../common/errorWrap';
import themes from '../themes/index';
import { propertyAssign, propertyMap } from '../common/common';
import rectXAxis from '../common/rectXAxis';
import rectYAxis from '../common/rectYAxis';
import rectTooltip from '../common/rectTooltip';
import rectLegend from '../common/rectLegend';
import geomSize from '../common/geomSize';
import geomStyle from '../common/geomStyle';
import '@antv/data-set/lib/api/statistics';
import '@antv/data-set/lib/transform/bin/hexagon';
export var Hexagonal = /*#__PURE__*/function (_Base) {
_inheritsLoose(Hexagonal, _Base);
function Hexagonal() {
var _this;
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _Base.call.apply(_Base, [this].concat(args)) || this;
_this.chartName = 'G2Hexagonal';
return _this;
}
var _proto = Hexagonal.prototype;
_proto.getDefaultConfig = function getDefaultConfig() {
return {
colors: themes.order_10,
tooltip: {
titleFormatter: null,
nameFormatter: null,
valueFormatter: null
},
legend: {
align: 'left',
nameFormatter: null // 可以强制覆盖,手动设置label
}
};
};
_proto.init = function init(chart, config, data) {
// 设置数据度量
var defs = {
// x: propertyAssign(
// propertyMap.axis,
// {
// type: 'cat',
// },
// {
// visible: false,
// },
// ),
y: propertyAssign(propertyMap.axis, {}, {
visible: false,
nice: true
}),
count: {
nice: true
}
};
chart.scale(defs);
var ds = new DataSet({
state: {
sizeEncoding: false
}
});
var hexagonalDataView = ds.createView().source(this.rawData).transform({
// sizeByCount: '$state.sizeEncoding', // calculate bin size by binning count
type: 'bin.hexagon',
fields: ['x', 'y'],
// 对应坐标轴上的一个点
bins: [10, 5]
});
chart.data(hexagonalDataView.rows);
// 设置X轴
rectXAxis(this, chart, config);
rectYAxis(this, chart, config);
// 设置图例
rectLegend(this, chart, config, {}, 'multiple', 'count');
// tooltip
rectTooltip(this, chart, config, {}, null, {
showCrosshairs: false,
showMarkers: false
});
drawHexagonal(chart, config, config.colors);
};
return Hexagonal;
}(Base);
var Whexagonal = errorWrap(Hexagonal);
export default Whexagonal;
function drawHexagonal(chart, config, colors, field) {
if (field === void 0) {
field = 'count';
}
var size = config.size;
var geom = chart.polygon().position(['x', 'y']).color(field, colors);
geomSize(geom, size, null, 'y', 'y*count*extra');
geomStyle(geom, config.geomStyle, {
lineWidth: 2
}, 'y*count*extra');
}