UNPKG

@alicloud/cloud-charts

Version:

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

147 lines (127 loc) 3.9 kB
'use strict'; // 引入所需要的库和样式 import _extends from "@babel/runtime/helpers/extends"; import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose"; import Base from "../common/Base"; 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 geomSize from '../common/geomSize'; import geomStyle from '../common/geomStyle'; import errorWrap from '../common/errorWrap'; import themes from '../themes/index'; import { propertyAssign, propertyMap } from '../common/common'; import autoTimeMask from '../common/autoTimeMask'; import legendFilter from '../common/legendFilter'; export var Scatter = /*#__PURE__*/function (_Base) { _inheritsLoose(Scatter, _Base); function Scatter() { 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 = 'G2Scatter'; return _this; } var _proto = Scatter.prototype; _proto.getDefaultConfig = function getDefaultConfig() { return { // padding: ['auto', 'auto', 'auto', 'auto'], colors: themes.category_12, xAxis: { mask: 'auto', autoRotate: false }, yAxis: { min: 0 }, size: 4, jitter: false, tooltip: true, legend: true, label: false }; }; _proto.init = function init(chart, config, data) { // const config = userConfig; var colors = config.colors, jitter = config.jitter; var defs = { x: propertyAssign(propertyMap.axis, { type: config.jitter ? 'cat' : 'linear' }, config.xAxis), type: { type: 'cat' } }; defs.y = propertyAssign(propertyMap.axis, { type: 'linear', tickCount: 5, nice: true }, config.yAxis); autoTimeMask(defs, this.rawData); // rectAutoTickCount(chart, config, defs, false); // chart.source(data, defs); chart.scale(defs); chart.data(data); // 设置X轴 var xAxis = {}; if (config.jitter) { xAxis.grid = { align: 'center', // 网格顶点从两个刻度中间开始 line: { style: { stroke: themes['widgets-axis-grid'], lineWidth: 1 // lineDash: [3, 3] } } }; } // 扰动点图不能打开垂直网格线 if (config.grid && !config.jitter) { xAxis.grid = { line: { style: { stroke: themes['widgets-axis-grid'], lineWidth: 1 } } }; } rectXAxis(this, chart, config, xAxis); // 设置单个Y轴 rectYAxis(this, chart, config); rectTooltip(this, chart, config, { crosshairs: null }, null, { crosshairs: { type: 'xy' } }); legendFilter(this, chart); // 绘制辅助线,辅助背景区域 guide(chart, config); var geom = chart.point().color('type', colors).position('x*y').shape('circle'); if (jitter) { if (typeof jitter === 'object') { geom.adjust(_extends({ type: 'jitter' }, jitter)); } else { geom.adjust('jitter'); } } geomStyle(geom, config.geomStyle); label({ geom: geom, config: config }); geomSize(geom, config.size, 4, 'y', 'x*y*type*extra'); chart.legend('x', false); chart.legend('y', false); chart.legend('extra', false); // fix: 设置 rectLegend 后如果再调用 chart.legend 会生成默认图例 rectLegend(this, chart, config, null, false, 'type'); }; return Scatter; }(Base); var Wscatter = errorWrap(Scatter); export default Wscatter;