UNPKG

@alicloud/cloud-charts

Version:

![](https://img.shields.io/npm/v/@alicloud/cloud-charts?color=%23ff8200)

154 lines (133 loc) 4.21 kB
'use strict'; import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose"; import Base from '../common/Base'; import errorWrap from '../common/errorWrap'; import rectXAxis from '../common/rectXAxis'; import rectYAxis from '../common/rectYAxis'; import rectTooltip from '../common/rectTooltip'; import rectLegend from '../common/rectLegend'; import guide from '../common/guide'; import label from '../common/label'; import themes from '../themes/index'; import { propertyAssign, propertyMap } from '../common/common'; import legendFilter from '../common/legendFilter'; import geomStyle from '../common/geomStyle'; import "./index.css"; // 3.x代码 export var Heatmap = /*#__PURE__*/function (_Base) { _inheritsLoose(Heatmap, _Base); function Heatmap() { 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 = 'G2Heatmap'; return _this; } var _proto = Heatmap.prototype; _proto.getDefaultConfig = function getDefaultConfig() { return { colors: themes.category_12, // padding: ['auto', 'auto', 'auto', 'auto'], xAxis: { type: 'cat', labelFormatter: null, // 可以强制覆盖,手动设置label categories: null, autoRotate: false }, yAxis: { labelFormatter: null, // 可以强制覆盖,手动设置label max: null, min: null }, legend: { align: 'left', nameFormatter: null // 可以强制覆盖,手动设置label }, tooltip: { titleFormatter: null, nameFormatter: null, valueFormatter: null }, // grid: false, label: false, coordinate: null }; }; _proto.init = function init(chart, config, data) { var defs = { 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) { var _config$coordinate = config.coordinate, _config$coordinate$ty = _config$coordinate.type, type = _config$coordinate$ty === void 0 ? 'rect' : _config$coordinate$ty, reflect = _config$coordinate.reflect; var 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, {}, false, 'type'); legendFilter(this, chart); // tooltip rectTooltip(this, chart, config, { showMarkers: false, showCrosshairs: false }, null, { showTitle: false, showMarkers: false, showCrosshairs: false }); // 绘制辅助线,辅助背景区域 guide(chart, config); var geom = chart.polygon().position('x*y').color('type', config.colors).tooltip('x*y*extra', function (x, y, extra) { return { name: x + " - " + y, value: (Array.isArray(extra) ? extra[0] : extra.value) || '-' }; }); 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: function content(data, item, i) { if (!config.label) { return; } var result = (Array.isArray(data.extra) ? data.extra[0] : data.extra.value) || '-'; if (typeof config.label === 'object' && config.label.labelFormatter) { result = config.label.labelFormatter(result, item, i); } return result; } } }); }; return Heatmap; }(Base); var Wheatmap = errorWrap(Heatmap); export default Wheatmap;