base.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823
  1. import * as Attr from '../attr/index';
  2. const Util = require('../util/common');
  3. const Base = require('../base');
  4. const GROUP_ATTRS = [ 'color', 'size', 'shape' ];
  5. const FIELD_ORIGIN = '_origin';
  6. const FIELD_ORIGIN_Y = '_originY';
  7. const Global = require('../global');
  8. const GeometryShape = require('./shape/shape');
  9. const Adjust = require('@antv/adjust/lib/base');
  10. function parseFields(field) {
  11. if (Util.isArray(field)) {
  12. return field;
  13. }
  14. if (Util.isString(field)) {
  15. return field.split('*');
  16. }
  17. return [ field ];
  18. }
  19. /**
  20. * The parent class for Geometry
  21. * @class Geom
  22. */
  23. class Geom extends Base {
  24. getDefaultCfg() {
  25. return {
  26. /**
  27. * geometry type
  28. * @type {String}
  29. */
  30. type: null,
  31. /**
  32. * the data of geometry
  33. * @type {Array}
  34. */
  35. data: null,
  36. /**
  37. * the attrs of geo,etry
  38. * @type {Object}
  39. */
  40. attrs: {},
  41. scales: {},
  42. /**
  43. * group for storing the shapes
  44. * @type {Canvas}
  45. */
  46. container: null,
  47. /**
  48. * style options
  49. * @type {Object}
  50. */
  51. styleOptions: null,
  52. chart: null,
  53. shapeType: '',
  54. /**
  55. * wether to generate key points for each shape
  56. * @protected
  57. * @type {Boolean}
  58. */
  59. generatePoints: false,
  60. attrOptions: {},
  61. sortable: false,
  62. startOnZero: true,
  63. visible: true,
  64. connectNulls: false,
  65. // 是否丢弃没有值的分组。
  66. ignoreEmptyGroup: false
  67. };
  68. }
  69. init() {
  70. const self = this;
  71. self._initAttrs();
  72. self._processData();
  73. }
  74. _getGroupScales() {
  75. const self = this;
  76. const scales = [];
  77. Util.each(GROUP_ATTRS, function(attrName) {
  78. const attr = self.getAttr(attrName);
  79. if (attr) {
  80. const attrScales = attr.scales;
  81. Util.each(attrScales, function(scale) {
  82. if (scale && scale.isCategory && scales.indexOf(scale) === -1) {
  83. scales.push(scale);
  84. }
  85. });
  86. }
  87. });
  88. return scales;
  89. }
  90. _groupData(data) {
  91. const self = this;
  92. const colDefs = self.get('colDefs');
  93. const groupScales = self._getGroupScales();
  94. if (groupScales.length) {
  95. const appendConditions = {};
  96. const names = [];
  97. Util.each(groupScales, scale => {
  98. const field = scale.field;
  99. names.push(field);
  100. if (colDefs && colDefs[field] && colDefs[field].values) { // users have defined
  101. appendConditions[scale.field] = colDefs[field].values;
  102. }
  103. });
  104. return Util.Array.group(data, names, appendConditions);
  105. }
  106. return [ data ];
  107. }
  108. _setAttrOptions(attrName, attrCfg) {
  109. const options = this.get('attrOptions');
  110. options[attrName] = attrCfg;
  111. const attrs = this.get('attrs');
  112. // 说明已经初始化过了
  113. if (Object.keys(attrs).length) {
  114. this._createAttr(attrName, attrCfg);
  115. }
  116. }
  117. _createAttrOption(attrName, field, cfg, defaultValues) {
  118. const attrCfg = {};
  119. attrCfg.field = field;
  120. if (cfg) {
  121. if (Util.isFunction(cfg)) {
  122. attrCfg.callback = cfg;
  123. } else {
  124. attrCfg.values = cfg;
  125. }
  126. } else {
  127. attrCfg.values = defaultValues;
  128. }
  129. this._setAttrOptions(attrName, attrCfg);
  130. }
  131. _createAttr(type, option) {
  132. const self = this;
  133. const attrs = self.get('attrs');
  134. const coord = self.get('coord');
  135. const className = Util.upperFirst(type);
  136. const fields = parseFields(option.field);
  137. if (type === 'position') {
  138. option.coord = coord;
  139. }
  140. const scales = [];
  141. for (let i = 0, len = fields.length; i < len; i++) {
  142. const field = fields[i];
  143. const scale = self._createScale(field);
  144. scales.push(scale);
  145. }
  146. if (type === 'position') {
  147. const yScale = scales[1];
  148. // 饼图的处理,但是还不知道为啥
  149. if (coord.type === 'polar' && coord.transposed && self.hasAdjust('stack')) {
  150. if (yScale.values.length) {
  151. yScale.change({
  152. nice: false,
  153. min: 0,
  154. max: Math.max.apply(null, yScale.values)
  155. });
  156. }
  157. }
  158. }
  159. option.scales = scales;
  160. const attr = new Attr[className](option);
  161. attrs[type] = attr;
  162. return attr;
  163. }
  164. _initAttrs() {
  165. const self = this;
  166. const attrOptions = self.get('attrOptions');
  167. for (const type in attrOptions) {
  168. if (attrOptions.hasOwnProperty(type)) {
  169. this._createAttr(type, attrOptions[type]);
  170. }
  171. }
  172. }
  173. _createScale(field) {
  174. const scales = this.get('scales');
  175. let scale = scales[field];
  176. if (!scale) {
  177. scale = this.get('chart').createScale(field);
  178. scales[field] = scale;
  179. }
  180. return scale;
  181. }
  182. _processData() {
  183. const self = this;
  184. const data = this.get('data');
  185. const dataArray = [];
  186. let groupedArray = this._groupData(data);
  187. if (this.get('ignoreEmptyGroup')) {
  188. const yScale = this.getYScale();
  189. groupedArray = groupedArray.filter(group =>
  190. group.some(item => typeof item[yScale.field] !== 'undefined')
  191. );
  192. }
  193. for (let i = 0, len = groupedArray.length; i < len; i++) {
  194. const subData = groupedArray[i];
  195. const tempData = self._saveOrigin(subData);
  196. if (this.hasAdjust('dodge')) {
  197. self._numberic(tempData);
  198. }
  199. dataArray.push(tempData);
  200. }
  201. if (self.get('adjust')) {
  202. self._adjustData(dataArray);
  203. }
  204. if (self.get('sortable')) {
  205. self._sort(dataArray);
  206. }
  207. self.set('dataArray', dataArray);
  208. return dataArray;
  209. }
  210. _saveOrigin(data) {
  211. const rst = [];
  212. for (let i = 0, len = data.length; i < len; i++) {
  213. const origin = data[i];
  214. const obj = {};
  215. for (const k in origin) {
  216. obj[k] = origin[k];
  217. }
  218. obj[FIELD_ORIGIN] = origin;
  219. rst.push(obj);
  220. }
  221. return rst;
  222. }
  223. _numberic(data) {
  224. const positionAttr = this.getAttr('position');
  225. const scales = positionAttr.scales;
  226. for (let j = 0, len = data.length; j < len; j++) {
  227. const obj = data[j];
  228. const count = Math.min(2, scales.length);
  229. for (let i = 0; i < count; i++) {
  230. const scale = scales[i];
  231. if (scale.isCategory) {
  232. const field = scale.field;
  233. obj[field] = scale.translate(obj[field]);
  234. }
  235. }
  236. }
  237. }
  238. _adjustData(dataArray) {
  239. const self = this;
  240. const adjust = self.get('adjust');
  241. if (adjust) {
  242. const adjustType = Util.upperFirst(adjust.type);
  243. if (!Adjust[adjustType]) {
  244. throw new Error('not support such adjust : ' + adjust);
  245. }
  246. const xScale = self.getXScale();
  247. const yScale = self.getYScale();
  248. const cfg = Util.mix({
  249. xField: xScale.field,
  250. yField: yScale.field
  251. }, adjust);
  252. const adjustObject = new Adjust[adjustType](cfg);
  253. adjustObject.processAdjust(dataArray);
  254. if (adjustType === 'Stack') {
  255. self._updateStackRange(yScale.field, yScale, dataArray);
  256. }
  257. }
  258. }
  259. _updateStackRange(field, scale, dataArray) {
  260. const mergeArray = Util.Array.merge(dataArray);
  261. let min = scale.min;
  262. let max = scale.max;
  263. for (let i = 0, len = mergeArray.length; i < len; i++) {
  264. const obj = mergeArray[i];
  265. const tmpMin = Math.min.apply(null, obj[field]);
  266. const tmpMax = Math.max.apply(null, obj[field]);
  267. if (tmpMin < min) {
  268. min = tmpMin;
  269. }
  270. if (tmpMax > max) {
  271. max = tmpMax;
  272. }
  273. }
  274. if (min < scale.min || max > scale.max) {
  275. scale.change({
  276. min,
  277. max
  278. });
  279. }
  280. }
  281. _sort(mappedArray) {
  282. const self = this;
  283. const xScale = self.getXScale();
  284. const { field, type } = xScale;
  285. if (type !== 'identity' && xScale.values.length > 1) {
  286. Util.each(mappedArray, itemArr => {
  287. itemArr.sort((obj1, obj2) => {
  288. if (type === 'timeCat') {
  289. return xScale._toTimeStamp(obj1[FIELD_ORIGIN][field]) - xScale._toTimeStamp(obj2[FIELD_ORIGIN][field]);
  290. }
  291. return xScale.translate(obj1[FIELD_ORIGIN][field]) - xScale.translate(obj2[FIELD_ORIGIN][field]);
  292. });
  293. });
  294. }
  295. self.set('hasSorted', true);
  296. self.set('dataArray', mappedArray);
  297. }
  298. paint() {
  299. const self = this;
  300. const dataArray = self.get('dataArray');
  301. const mappedArray = [];
  302. const shapeFactory = self.getShapeFactory();
  303. shapeFactory.setCoord(self.get('coord'));
  304. self._beforeMapping(dataArray);
  305. for (let i = 0, len = dataArray.length; i < len; i++) {
  306. let data = dataArray[i];
  307. if (data.length) {
  308. data = self._mapping(data);
  309. mappedArray.push(data);
  310. self.draw(data, shapeFactory);
  311. }
  312. }
  313. self.set('dataArray', mappedArray);
  314. }
  315. getShapeFactory() {
  316. let shapeFactory = this.get('shapeFactory');
  317. if (!shapeFactory) {
  318. const shapeType = this.get('shapeType');
  319. shapeFactory = GeometryShape.getShapeFactory(shapeType);
  320. this.set('shapeFactory', shapeFactory);
  321. }
  322. return shapeFactory;
  323. }
  324. _mapping(data) {
  325. const self = this;
  326. const attrs = self.get('attrs');
  327. const yField = self.getYScale().field;
  328. // 用来缓存转换的值,减少mapping耗时
  329. const mappedCache = {};
  330. for (const k in attrs) {
  331. if (attrs.hasOwnProperty(k)) {
  332. const attr = attrs[k];
  333. const names = attr.names;
  334. const scales = attr.scales;
  335. for (let i = 0, len = data.length; i < len; i++) {
  336. const record = data[i];
  337. record[FIELD_ORIGIN_Y] = record[yField];
  338. // 获取视觉属性对应的value值
  339. // 位置的缓存命中率低,还是每次单独计算
  340. if (attr.type === 'position') {
  341. const values = self._getAttrValues(attr, record);
  342. for (let j = 0, len = values.length; j < len; j++) {
  343. const val = values[j];
  344. const name = names[j];
  345. record[name] = (Util.isArray(val) && val.length === 1) ? val[0] : val;
  346. }
  347. } else {
  348. // 除了position其他都只有一项
  349. const name = names[0];
  350. const field = scales[0].field;
  351. const value = record[field];
  352. const key = `${name}${value}`;
  353. let values = mappedCache[key];
  354. if (!values) {
  355. values = self._getAttrValues(attr, record);
  356. mappedCache[key] = values;
  357. }
  358. record[name] = values[0];
  359. }
  360. }
  361. }
  362. }
  363. return data;
  364. }
  365. _getAttrValues(attr, record) {
  366. const scales = attr.scales;
  367. const params = [];
  368. for (let i = 0, len = scales.length; i < len; i++) {
  369. const scale = scales[i];
  370. const field = scale.field;
  371. if (scale.type === 'identity') {
  372. params.push(scale.value);
  373. } else {
  374. params.push(record[field]);
  375. }
  376. }
  377. const values = attr.mapping(...params);
  378. return values;
  379. }
  380. getAttrValue(attrName, record) {
  381. const attr = this.getAttr(attrName);
  382. let rst = null;
  383. if (attr) {
  384. const values = this._getAttrValues(attr, record);
  385. rst = values[0];
  386. }
  387. return rst;
  388. }
  389. _beforeMapping(dataArray) {
  390. const self = this;
  391. if (self.get('generatePoints')) {
  392. self._generatePoints(dataArray);
  393. }
  394. }
  395. isInCircle() {
  396. const coord = this.get('coord');
  397. return coord && coord.isPolar;
  398. }
  399. getCallbackCfg(fields, cfg, origin) {
  400. if (!fields) {
  401. return cfg;
  402. }
  403. const tmpCfg = {};
  404. const params = fields.map(function(field) {
  405. return origin[field];
  406. });
  407. Util.each(cfg, function(v, k) {
  408. if (Util.isFunction(v)) {
  409. tmpCfg[k] = v.apply(null, params);
  410. } else {
  411. tmpCfg[k] = v;
  412. }
  413. });
  414. return tmpCfg;
  415. }
  416. getDrawCfg(obj) {
  417. const self = this;
  418. const isInCircle = self.isInCircle();
  419. const cfg = {
  420. origin: obj,
  421. x: obj.x,
  422. y: obj.y,
  423. color: obj.color,
  424. size: obj.size,
  425. shape: obj.shape,
  426. isInCircle,
  427. opacity: obj.opacity
  428. };
  429. const styleOptions = self.get('styleOptions');
  430. if (styleOptions && styleOptions.style) {
  431. cfg.style = self.getCallbackCfg(styleOptions.fields, styleOptions.style, obj[FIELD_ORIGIN]);
  432. }
  433. if (self.get('generatePoints')) {
  434. cfg.points = obj.points;
  435. cfg.nextPoints = obj.nextPoints;
  436. }
  437. if (isInCircle) {
  438. cfg.center = self.get('coord').center;
  439. }
  440. return cfg;
  441. }
  442. draw(data, shapeFactory) {
  443. const self = this;
  444. const container = self.get('container');
  445. const yScale = self.getYScale();
  446. Util.each(data, function(obj, index) {
  447. if (yScale && Util.isNil(obj._origin[yScale.field])) {
  448. return;
  449. }
  450. obj.index = index;
  451. const cfg = self.getDrawCfg(obj);
  452. const shape = obj.shape;
  453. self.drawShape(shape, obj, cfg, container, shapeFactory);
  454. });
  455. }
  456. drawShape(shape, shapeData, cfg, container, shapeFactory) {
  457. const gShape = shapeFactory.drawShape(shape, cfg, container);
  458. if (gShape) {
  459. Util.each([].concat(gShape), s => {
  460. s.set('origin', shapeData);
  461. });
  462. }
  463. }
  464. _generatePoints(dataArray) {
  465. const self = this;
  466. const shapeFactory = self.getShapeFactory();
  467. const shapeAttr = self.getAttr('shape');
  468. Util.each(dataArray, function(data) {
  469. for (let i = 0, len = data.length; i < len; i++) {
  470. const obj = data[i];
  471. const cfg = self.createShapePointsCfg(obj);
  472. const shape = shapeAttr ? self._getAttrValues(shapeAttr, obj) : null;
  473. const points = shapeFactory.getShapePoints(shape, cfg);
  474. obj.points = points;
  475. }
  476. });
  477. // 添加nextPoints
  478. Util.each(dataArray, (data, index) => {
  479. const nextData = dataArray[index + 1];
  480. if (nextData) {
  481. data[0].nextPoints = nextData[0].points;
  482. }
  483. });
  484. }
  485. /**
  486. * get the info of each shape
  487. * @protected
  488. * @param {Object} obj the data item
  489. * @return {Object} cfg return the result
  490. */
  491. createShapePointsCfg(obj) {
  492. const xScale = this.getXScale();
  493. const yScale = this.getYScale();
  494. const x = this._normalizeValues(obj[xScale.field], xScale);
  495. let y;
  496. if (yScale) {
  497. y = this._normalizeValues(obj[yScale.field], yScale);
  498. } else {
  499. y = obj.y ? obj.y : 0.1;
  500. }
  501. return {
  502. x,
  503. y,
  504. y0: yScale ? yScale.scale(this.getYMinValue()) : undefined
  505. };
  506. }
  507. getYMinValue() {
  508. const yScale = this.getYScale();
  509. const { min, max } = yScale;
  510. let value;
  511. if (this.get('startOnZero')) {
  512. if (max <= 0 && min <= 0) {
  513. value = max;
  514. } else {
  515. value = min >= 0 ? min : 0;
  516. }
  517. } else {
  518. value = min;
  519. }
  520. return value;
  521. }
  522. _normalizeValues(values, scale) {
  523. let rst = [];
  524. if (Util.isArray(values)) {
  525. for (let i = 0, len = values.length; i < len; i++) {
  526. const v = values[i];
  527. rst.push(scale.scale(v));
  528. }
  529. } else {
  530. rst = scale.scale(values);
  531. }
  532. return rst;
  533. }
  534. getAttr(name) {
  535. return this.get('attrs')[name];
  536. }
  537. getXScale() {
  538. return this.getAttr('position').scales[0];
  539. }
  540. getYScale() {
  541. return this.getAttr('position').scales[1];
  542. }
  543. hasAdjust(adjust) {
  544. return this.get('adjust') && (this.get('adjust').type === adjust);
  545. }
  546. _getSnap(scale, item, arr) {
  547. let i = 0;
  548. let values;
  549. const yField = this.getYScale().field; // 叠加的维度
  550. if (this.hasAdjust('stack') && scale.field === yField) {
  551. values = [];
  552. arr.forEach(function(obj) {
  553. values.push(obj[FIELD_ORIGIN_Y]);
  554. });
  555. for (let len = values.length; i < len; i++) {
  556. if (values[0][0] > item) {
  557. break;
  558. }
  559. if (values[values.length - 1][1] <= item) {
  560. i = values.length - 1;
  561. break;
  562. }
  563. if (values[i][0] <= item && values[i][1] > item) {
  564. break;
  565. }
  566. }
  567. } else {
  568. values = scale.values;
  569. values.sort((a, b) => {
  570. return a - b;
  571. });
  572. for (let len = values.length; i < len; i++) {
  573. // 如果只有1个点直接返回第1个点
  574. if (len <= 1) {
  575. break;
  576. }
  577. // 第1个点和第2个点之间
  578. if ((values[0] + values[1]) / 2 > item) {
  579. break;
  580. }
  581. // 中间的点
  582. if ((values[i - 1] + values[i]) / 2 <= item && (values[i + 1] + values[i]) / 2 > item) {
  583. break;
  584. }
  585. // 最后2个点
  586. if ((values[values.length - 2] + values[values.length - 1]) / 2 <= item) {
  587. i = values.length - 1;
  588. break;
  589. }
  590. }
  591. }
  592. const result = values[i];
  593. return result;
  594. }
  595. getSnapRecords(point) {
  596. const self = this;
  597. const coord = self.get('coord');
  598. const xScale = self.getXScale();
  599. const yScale = self.getYScale();
  600. const xfield = xScale.field;
  601. const dataArray = self.get('dataArray');
  602. if (!this.get('hasSorted')) {
  603. this._sort(dataArray);
  604. }
  605. let rst = [];
  606. const invertPoint = coord.invertPoint(point);
  607. let invertPointX = invertPoint.x;
  608. if (self.isInCircle() && !coord.transposed && invertPointX > (1 + xScale.rangeMax()) / 2) {
  609. invertPointX = xScale.rangeMin();
  610. }
  611. let xValue = xScale.invert(invertPointX);
  612. if (!xScale.isCategory) {
  613. xValue = self._getSnap(xScale, xValue);
  614. }
  615. const tmp = [];
  616. dataArray.forEach(function(data) {
  617. data.forEach(function(obj) {
  618. const originValue = Util.isNil(obj[FIELD_ORIGIN]) ? obj[xfield] : obj[FIELD_ORIGIN][xfield];
  619. if (self._isEqual(originValue, xValue, xScale)) {
  620. tmp.push(obj);
  621. }
  622. });
  623. });
  624. // special for pie chart
  625. if (this.hasAdjust('stack') && coord.isPolar && coord.transposed) {
  626. if (invertPointX >= 0 && invertPointX <= 1) {
  627. let yValue = yScale.invert(invertPoint.y);
  628. yValue = self._getSnap(yScale, yValue, tmp);
  629. tmp.forEach(obj => {
  630. if (Util.isArray(yValue) ? obj[FIELD_ORIGIN_Y].toString() === yValue.toString() : obj[FIELD_ORIGIN_Y] === yValue) {
  631. rst.push(obj);
  632. }
  633. });
  634. }
  635. } else {
  636. rst = tmp;
  637. }
  638. return rst;
  639. }
  640. _isEqual(originValue, value, scale) {
  641. if (scale.type === 'timeCat') {
  642. return scale._toTimeStamp(originValue) === value;
  643. }
  644. return value === originValue;
  645. }
  646. position(field) {
  647. this._setAttrOptions('position', {
  648. field
  649. });
  650. return this;
  651. }
  652. color(field, values) {
  653. this._createAttrOption('color', field, values, Global.colors);
  654. return this;
  655. }
  656. size(field, values) {
  657. this._createAttrOption('size', field, values, Global.sizes);
  658. return this;
  659. }
  660. shape(field, values) {
  661. const type = this.get('type');
  662. const shapes = Global.shapes[type] || [];
  663. this._createAttrOption('shape', field, values, shapes);
  664. return this;
  665. }
  666. style(field, cfg) {
  667. let styleOptions = this.get('styleOptions');
  668. if (!styleOptions) {
  669. styleOptions = {};
  670. this.set('styleOptions', styleOptions);
  671. }
  672. if (Util.isObject(field)) {
  673. cfg = field;
  674. field = null;
  675. }
  676. let fields;
  677. if (field) {
  678. fields = parseFields(field);
  679. }
  680. styleOptions.fields = fields;
  681. styleOptions.style = cfg;
  682. return this;
  683. }
  684. adjust(type) {
  685. if (Util.isString(type)) {
  686. type = { type };
  687. }
  688. this.set('adjust', type);
  689. return this;
  690. }
  691. animate(cfg) {
  692. this.set('animateCfg', cfg);
  693. return this;
  694. }
  695. changeData(data) {
  696. this.set('data', data);
  697. // 改变数据后,情况度量,因为需要重新实例化
  698. this.set('scales', {});
  699. this.init();
  700. }
  701. clearInner() {
  702. const container = this.get('container');
  703. if (container) {
  704. container.clear();
  705. // container.setMatrix([ 1, 0, 0, 1, 0, 0 ]);
  706. }
  707. }
  708. reset() {
  709. this.set('attrs', {});
  710. this.set('attrOptions', {});
  711. this.set('adjust', null);
  712. this.clearInner();
  713. }
  714. clear() {
  715. this.clearInner();
  716. }
  717. destroy() {
  718. this.clear();
  719. super.destroy();
  720. }
  721. _display(visible) {
  722. this.set('visible', visible);
  723. const container = this.get('container');
  724. const canvas = container.get('canvas');
  725. container.set('visible', visible);
  726. canvas.draw();
  727. }
  728. show() {
  729. this._display(true);
  730. }
  731. hide() {
  732. this._display(false);
  733. }
  734. }
  735. module.exports = Geom;