ade85359624da8fd84e4400d32399ca08467cae007c613305cee064e279c7584261ebf19432b190a3fa5c329ca2200461115da0b41e63ba34fa6bf831fdbb4 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.axis = axis;
  7. var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
  8. var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
  9. var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
  10. var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
  11. var _updater = require("../class/updater.class");
  12. var _config = require("../config");
  13. var _util = require("../util");
  14. var _util2 = require("@jiaminghi/c-render/lib/plugin/util");
  15. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  16. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  17. var axisConfig = {
  18. xAxisConfig: _config.xAxisConfig,
  19. yAxisConfig: _config.yAxisConfig
  20. };
  21. var min = Math.min,
  22. max = Math.max,
  23. abs = Math.abs,
  24. pow = Math.pow;
  25. function axis(chart) {
  26. var option = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  27. var xAxis = option.xAxis,
  28. yAxis = option.yAxis,
  29. series = option.series;
  30. var allAxis = [];
  31. if (xAxis && yAxis && series) {
  32. allAxis = getAllAxis(xAxis, yAxis);
  33. allAxis = mergeDefaultAxisConfig(allAxis);
  34. allAxis = allAxis.filter(function (_ref) {
  35. var show = _ref.show;
  36. return show;
  37. });
  38. allAxis = mergeDefaultBoundaryGap(allAxis);
  39. allAxis = calcAxisLabelData(allAxis, series);
  40. allAxis = setAxisPosition(allAxis);
  41. allAxis = calcAxisLinePosition(allAxis, chart);
  42. allAxis = calcAxisTickPosition(allAxis, chart);
  43. allAxis = calcAxisNamePosition(allAxis, chart);
  44. allAxis = calcSplitLinePosition(allAxis, chart);
  45. }
  46. (0, _updater.doUpdate)({
  47. chart: chart,
  48. series: allAxis,
  49. key: 'axisLine',
  50. getGraphConfig: getLineConfig
  51. });
  52. (0, _updater.doUpdate)({
  53. chart: chart,
  54. series: allAxis,
  55. key: 'axisTick',
  56. getGraphConfig: getTickConfig
  57. });
  58. (0, _updater.doUpdate)({
  59. chart: chart,
  60. series: allAxis,
  61. key: 'axisLabel',
  62. getGraphConfig: getLabelConfig
  63. });
  64. (0, _updater.doUpdate)({
  65. chart: chart,
  66. series: allAxis,
  67. key: 'axisName',
  68. getGraphConfig: getNameConfig
  69. });
  70. (0, _updater.doUpdate)({
  71. chart: chart,
  72. series: allAxis,
  73. key: 'splitLine',
  74. getGraphConfig: getSplitLineConfig
  75. });
  76. chart.axisData = allAxis;
  77. }
  78. function getAllAxis(xAxis, yAxis) {
  79. var allXAxis = [],
  80. allYAxis = [];
  81. if (xAxis instanceof Array) {
  82. var _allXAxis;
  83. (_allXAxis = allXAxis).push.apply(_allXAxis, (0, _toConsumableArray2["default"])(xAxis));
  84. } else {
  85. allXAxis.push(xAxis);
  86. }
  87. if (yAxis instanceof Array) {
  88. var _allYAxis;
  89. (_allYAxis = allYAxis).push.apply(_allYAxis, (0, _toConsumableArray2["default"])(yAxis));
  90. } else {
  91. allYAxis.push(yAxis);
  92. }
  93. allXAxis.splice(2);
  94. allYAxis.splice(2);
  95. allXAxis = allXAxis.map(function (axis, i) {
  96. return _objectSpread(_objectSpread({}, axis), {}, {
  97. index: i,
  98. axis: 'x'
  99. });
  100. });
  101. allYAxis = allYAxis.map(function (axis, i) {
  102. return _objectSpread(_objectSpread({}, axis), {}, {
  103. index: i,
  104. axis: 'y'
  105. });
  106. });
  107. return [].concat((0, _toConsumableArray2["default"])(allXAxis), (0, _toConsumableArray2["default"])(allYAxis));
  108. }
  109. function mergeDefaultAxisConfig(allAxis) {
  110. var xAxis = allAxis.filter(function (_ref2) {
  111. var axis = _ref2.axis;
  112. return axis === 'x';
  113. });
  114. var yAxis = allAxis.filter(function (_ref3) {
  115. var axis = _ref3.axis;
  116. return axis === 'y';
  117. });
  118. xAxis = xAxis.map(function (axis) {
  119. return (0, _util.deepMerge)((0, _util2.deepClone)(_config.xAxisConfig), axis);
  120. });
  121. yAxis = yAxis.map(function (axis) {
  122. return (0, _util.deepMerge)((0, _util2.deepClone)(_config.yAxisConfig), axis);
  123. });
  124. return [].concat((0, _toConsumableArray2["default"])(xAxis), (0, _toConsumableArray2["default"])(yAxis));
  125. }
  126. function mergeDefaultBoundaryGap(allAxis) {
  127. var valueAxis = allAxis.filter(function (_ref4) {
  128. var data = _ref4.data;
  129. return data === 'value';
  130. });
  131. var labelAxis = allAxis.filter(function (_ref5) {
  132. var data = _ref5.data;
  133. return data !== 'value';
  134. });
  135. valueAxis.forEach(function (axis) {
  136. if (typeof axis.boundaryGap === 'boolean') return;
  137. axis.boundaryGap = false;
  138. });
  139. labelAxis.forEach(function (axis) {
  140. if (typeof axis.boundaryGap === 'boolean') return;
  141. axis.boundaryGap = true;
  142. });
  143. return [].concat((0, _toConsumableArray2["default"])(valueAxis), (0, _toConsumableArray2["default"])(labelAxis));
  144. }
  145. function calcAxisLabelData(allAxis, series) {
  146. var valueAxis = allAxis.filter(function (_ref6) {
  147. var data = _ref6.data;
  148. return data === 'value';
  149. });
  150. var labelAxis = allAxis.filter(function (_ref7) {
  151. var data = _ref7.data;
  152. return data instanceof Array;
  153. });
  154. valueAxis = calcValueAxisLabelData(valueAxis, series);
  155. labelAxis = calcLabelAxisLabelData(labelAxis);
  156. return [].concat((0, _toConsumableArray2["default"])(valueAxis), (0, _toConsumableArray2["default"])(labelAxis));
  157. }
  158. function calcValueAxisLabelData(valueAxis, series) {
  159. return valueAxis.map(function (axis) {
  160. var minMaxValue = getValueAxisMaxMinValue(axis, series);
  161. var _getTrueMinMax = getTrueMinMax(axis, minMaxValue),
  162. _getTrueMinMax2 = (0, _slicedToArray2["default"])(_getTrueMinMax, 2),
  163. min = _getTrueMinMax2[0],
  164. max = _getTrueMinMax2[1];
  165. var interval = getValueInterval(min, max, axis);
  166. var formatter = axis.axisLabel.formatter;
  167. var label = [];
  168. if (min < 0 && max > 0) {
  169. label = getValueAxisLabelFromZero(min, max, interval);
  170. } else {
  171. label = getValueAxisLabelFromMin(min, max, interval);
  172. }
  173. label = label.map(function (l) {
  174. return parseFloat(l.toFixed(2));
  175. });
  176. return _objectSpread(_objectSpread({}, axis), {}, {
  177. maxValue: label.slice(-1)[0],
  178. minValue: label[0],
  179. label: getAfterFormatterLabel(label, formatter)
  180. });
  181. });
  182. }
  183. function getValueAxisMaxMinValue(axis, series) {
  184. series = series.filter(function (_ref8) {
  185. var show = _ref8.show,
  186. type = _ref8.type;
  187. if (show === false) return false;
  188. if (type === 'pie') return false;
  189. return true;
  190. });
  191. if (series.length === 0) return [0, 0];
  192. var index = axis.index,
  193. axisType = axis.axis;
  194. series = mergeStackData(series);
  195. var axisName = axisType + 'Axis';
  196. var valueSeries = series.filter(function (s) {
  197. return s[axisName] === index;
  198. });
  199. if (!valueSeries.length) valueSeries = series;
  200. return getSeriesMinMaxValue(valueSeries);
  201. }
  202. function getSeriesMinMaxValue(series) {
  203. if (!series) return;
  204. var minValue = Math.min.apply(Math, (0, _toConsumableArray2["default"])(series.map(function (_ref9) {
  205. var data = _ref9.data;
  206. return Math.min.apply(Math, (0, _toConsumableArray2["default"])((0, _util.filterNonNumber)(data)));
  207. })));
  208. var maxValue = Math.max.apply(Math, (0, _toConsumableArray2["default"])(series.map(function (_ref10) {
  209. var data = _ref10.data;
  210. return Math.max.apply(Math, (0, _toConsumableArray2["default"])((0, _util.filterNonNumber)(data)));
  211. })));
  212. return [minValue, maxValue];
  213. }
  214. function mergeStackData(series) {
  215. var seriesCloned = (0, _util2.deepClone)(series, true);
  216. series.forEach(function (item, i) {
  217. var data = (0, _util.mergeSameStackData)(item, series);
  218. seriesCloned[i].data = data;
  219. });
  220. return seriesCloned;
  221. }
  222. function getTrueMinMax(_ref11, _ref12) {
  223. var min = _ref11.min,
  224. max = _ref11.max,
  225. axis = _ref11.axis;
  226. var _ref13 = (0, _slicedToArray2["default"])(_ref12, 2),
  227. minValue = _ref13[0],
  228. maxValue = _ref13[1];
  229. var minType = (0, _typeof2["default"])(min),
  230. maxType = (0, _typeof2["default"])(max);
  231. if (!testMinMaxType(min)) {
  232. min = axisConfig[axis + 'AxisConfig'].min;
  233. minType = 'string';
  234. }
  235. if (!testMinMaxType(max)) {
  236. max = axisConfig[axis + 'AxisConfig'].max;
  237. maxType = 'string';
  238. }
  239. if (minType === 'string') {
  240. min = parseInt(minValue - abs(minValue * parseFloat(min) / 100));
  241. var lever = getValueLever(min);
  242. min = parseFloat((min / lever - 0.1).toFixed(1)) * lever;
  243. }
  244. if (maxType === 'string') {
  245. max = parseInt(maxValue + abs(maxValue * parseFloat(max) / 100));
  246. var _lever = getValueLever(max);
  247. max = parseFloat((max / _lever + 0.1).toFixed(1)) * _lever;
  248. }
  249. return [min, max];
  250. }
  251. function getValueLever(value) {
  252. var valueString = abs(value).toString();
  253. var valueLength = valueString.length;
  254. var firstZeroIndex = valueString.replace(/0*$/g, '').indexOf('0');
  255. var pow10Num = valueLength - 1;
  256. if (firstZeroIndex !== -1) pow10Num -= firstZeroIndex;
  257. return pow(10, pow10Num);
  258. }
  259. function testMinMaxType(val) {
  260. var valType = (0, _typeof2["default"])(val);
  261. var isValidString = valType === 'string' && /^\d+%$/.test(val);
  262. var isValidNumber = valType === 'number';
  263. return isValidString || isValidNumber;
  264. }
  265. function getValueAxisLabelFromZero(min, max, interval) {
  266. var negative = [],
  267. positive = [];
  268. var currentNegative = 0,
  269. currentPositive = 0;
  270. do {
  271. negative.push(currentNegative -= interval);
  272. } while (currentNegative > min);
  273. do {
  274. positive.push(currentPositive += interval);
  275. } while (currentPositive < max);
  276. return [].concat((0, _toConsumableArray2["default"])(negative.reverse()), [0], (0, _toConsumableArray2["default"])(positive));
  277. }
  278. function getValueAxisLabelFromMin(min, max, interval) {
  279. var label = [min],
  280. currentValue = min;
  281. do {
  282. label.push(currentValue += interval);
  283. } while (currentValue < max);
  284. return label;
  285. }
  286. function getAfterFormatterLabel(label, formatter) {
  287. if (!formatter) return label;
  288. if (typeof formatter === 'string') label = label.map(function (l) {
  289. return formatter.replace('{value}', l);
  290. });
  291. if (typeof formatter === 'function') label = label.map(function (value, index) {
  292. return formatter({
  293. value: value,
  294. index: index
  295. });
  296. });
  297. return label;
  298. }
  299. function calcLabelAxisLabelData(labelAxis) {
  300. return labelAxis.map(function (axis) {
  301. var data = axis.data,
  302. formatter = axis.axisLabel.formatter;
  303. return _objectSpread(_objectSpread({}, axis), {}, {
  304. label: getAfterFormatterLabel(data, formatter)
  305. });
  306. });
  307. }
  308. function getValueInterval(min, max, axis) {
  309. var interval = axis.interval,
  310. minInterval = axis.minInterval,
  311. maxInterval = axis.maxInterval,
  312. splitNumber = axis.splitNumber,
  313. axisType = axis.axis;
  314. var config = axisConfig[axisType + 'AxisConfig'];
  315. if (typeof interval !== 'number') interval = config.interval;
  316. if (typeof minInterval !== 'number') minInterval = config.minInterval;
  317. if (typeof maxInterval !== 'number') maxInterval = config.maxInterval;
  318. if (typeof splitNumber !== 'number') splitNumber = config.splitNumber;
  319. if (typeof interval === 'number') return interval;
  320. var valueInterval = parseInt((max - min) / (splitNumber - 1));
  321. if (valueInterval.toString().length > 1) valueInterval = parseInt(valueInterval.toString().replace(/\d$/, '0'));
  322. if (valueInterval === 0) valueInterval = 1;
  323. if (typeof minInterval === 'number' && valueInterval < minInterval) return minInterval;
  324. if (typeof maxInterval === 'number' && valueInterval > maxInterval) return maxInterval;
  325. return valueInterval;
  326. }
  327. function setAxisPosition(allAxis) {
  328. var xAxis = allAxis.filter(function (_ref14) {
  329. var axis = _ref14.axis;
  330. return axis === 'x';
  331. });
  332. var yAxis = allAxis.filter(function (_ref15) {
  333. var axis = _ref15.axis;
  334. return axis === 'y';
  335. });
  336. if (xAxis[0] && !xAxis[0].position) xAxis[0].position = _config.xAxisConfig.position;
  337. if (xAxis[1] && !xAxis[1].position) {
  338. xAxis[1].position = xAxis[0].position === 'bottom' ? 'top' : 'bottom';
  339. }
  340. if (yAxis[0] && !yAxis[0].position) yAxis[0].position = _config.yAxisConfig.position;
  341. if (yAxis[1] && !yAxis[1].position) {
  342. yAxis[1].position = yAxis[0].position === 'left' ? 'right' : 'left';
  343. }
  344. return [].concat((0, _toConsumableArray2["default"])(xAxis), (0, _toConsumableArray2["default"])(yAxis));
  345. }
  346. function calcAxisLinePosition(allAxis, chart) {
  347. var _chart$gridArea = chart.gridArea,
  348. x = _chart$gridArea.x,
  349. y = _chart$gridArea.y,
  350. w = _chart$gridArea.w,
  351. h = _chart$gridArea.h;
  352. allAxis = allAxis.map(function (axis) {
  353. var position = axis.position;
  354. var linePosition = [];
  355. if (position === 'left') {
  356. linePosition = [[x, y], [x, y + h]].reverse();
  357. } else if (position === 'right') {
  358. linePosition = [[x + w, y], [x + w, y + h]].reverse();
  359. } else if (position === 'top') {
  360. linePosition = [[x, y], [x + w, y]];
  361. } else if (position === 'bottom') {
  362. linePosition = [[x, y + h], [x + w, y + h]];
  363. }
  364. return _objectSpread(_objectSpread({}, axis), {}, {
  365. linePosition: linePosition
  366. });
  367. });
  368. return allAxis;
  369. }
  370. function calcAxisTickPosition(allAxis, chart) {
  371. return allAxis.map(function (axisItem) {
  372. var axis = axisItem.axis,
  373. linePosition = axisItem.linePosition,
  374. position = axisItem.position,
  375. label = axisItem.label,
  376. boundaryGap = axisItem.boundaryGap;
  377. if (typeof boundaryGap !== 'boolean') boundaryGap = axisConfig[axis + 'AxisConfig'].boundaryGap;
  378. var labelNum = label.length;
  379. var _linePosition = (0, _slicedToArray2["default"])(linePosition, 2),
  380. _linePosition$ = (0, _slicedToArray2["default"])(_linePosition[0], 2),
  381. startX = _linePosition$[0],
  382. startY = _linePosition$[1],
  383. _linePosition$2 = (0, _slicedToArray2["default"])(_linePosition[1], 2),
  384. endX = _linePosition$2[0],
  385. endY = _linePosition$2[1];
  386. var gapLength = axis === 'x' ? endX - startX : endY - startY;
  387. var gap = gapLength / (boundaryGap ? labelNum : labelNum - 1);
  388. var tickPosition = new Array(labelNum).fill(0).map(function (foo, i) {
  389. if (axis === 'x') {
  390. return [startX + gap * (boundaryGap ? i + 0.5 : i), startY];
  391. }
  392. return [startX, startY + gap * (boundaryGap ? i + 0.5 : i)];
  393. });
  394. var tickLinePosition = getTickLinePosition(axis, boundaryGap, position, tickPosition, gap);
  395. return _objectSpread(_objectSpread({}, axisItem), {}, {
  396. tickPosition: tickPosition,
  397. tickLinePosition: tickLinePosition,
  398. tickGap: gap
  399. });
  400. });
  401. }
  402. function getTickLinePosition(axisType, boundaryGap, position, tickPosition, gap) {
  403. var index = axisType === 'x' ? 1 : 0;
  404. var plus = 5;
  405. if (axisType === 'x' && position === 'top') plus = -5;
  406. if (axisType === 'y' && position === 'left') plus = -5;
  407. var tickLinePosition = tickPosition.map(function (lineStart) {
  408. var lineEnd = (0, _util2.deepClone)(lineStart);
  409. lineEnd[index] += plus;
  410. return [(0, _util2.deepClone)(lineStart), lineEnd];
  411. });
  412. if (!boundaryGap) return tickLinePosition;
  413. index = axisType === 'x' ? 0 : 1;
  414. plus = gap / 2;
  415. tickLinePosition.forEach(function (_ref16) {
  416. var _ref17 = (0, _slicedToArray2["default"])(_ref16, 2),
  417. lineStart = _ref17[0],
  418. lineEnd = _ref17[1];
  419. lineStart[index] += plus;
  420. lineEnd[index] += plus;
  421. });
  422. return tickLinePosition;
  423. }
  424. function calcAxisNamePosition(allAxis, chart) {
  425. return allAxis.map(function (axisItem) {
  426. var nameGap = axisItem.nameGap,
  427. nameLocation = axisItem.nameLocation,
  428. position = axisItem.position,
  429. linePosition = axisItem.linePosition;
  430. var _linePosition2 = (0, _slicedToArray2["default"])(linePosition, 2),
  431. lineStart = _linePosition2[0],
  432. lineEnd = _linePosition2[1];
  433. var namePosition = (0, _toConsumableArray2["default"])(lineStart);
  434. if (nameLocation === 'end') namePosition = (0, _toConsumableArray2["default"])(lineEnd);
  435. if (nameLocation === 'center') {
  436. namePosition[0] = (lineStart[0] + lineEnd[0]) / 2;
  437. namePosition[1] = (lineStart[1] + lineEnd[1]) / 2;
  438. }
  439. var index = 0;
  440. if (position === 'top' && nameLocation === 'center') index = 1;
  441. if (position === 'bottom' && nameLocation === 'center') index = 1;
  442. if (position === 'left' && nameLocation !== 'center') index = 1;
  443. if (position === 'right' && nameLocation !== 'center') index = 1;
  444. var plus = nameGap;
  445. if (position === 'top' && nameLocation !== 'end') plus *= -1;
  446. if (position === 'left' && nameLocation !== 'start') plus *= -1;
  447. if (position === 'bottom' && nameLocation === 'start') plus *= -1;
  448. if (position === 'right' && nameLocation === 'end') plus *= -1;
  449. namePosition[index] += plus;
  450. return _objectSpread(_objectSpread({}, axisItem), {}, {
  451. namePosition: namePosition
  452. });
  453. });
  454. }
  455. function calcSplitLinePosition(allAxis, chart) {
  456. var _chart$gridArea2 = chart.gridArea,
  457. w = _chart$gridArea2.w,
  458. h = _chart$gridArea2.h;
  459. return allAxis.map(function (axisItem) {
  460. var tickLinePosition = axisItem.tickLinePosition,
  461. position = axisItem.position,
  462. boundaryGap = axisItem.boundaryGap;
  463. var index = 0,
  464. plus = w;
  465. if (position === 'top' || position === 'bottom') index = 1;
  466. if (position === 'top' || position === 'bottom') plus = h;
  467. if (position === 'right' || position === 'bottom') plus *= -1;
  468. var splitLinePosition = tickLinePosition.map(function (_ref18) {
  469. var _ref19 = (0, _slicedToArray2["default"])(_ref18, 1),
  470. startPoint = _ref19[0];
  471. var endPoint = (0, _toConsumableArray2["default"])(startPoint);
  472. endPoint[index] += plus;
  473. return [(0, _toConsumableArray2["default"])(startPoint), endPoint];
  474. });
  475. if (!boundaryGap) splitLinePosition.shift();
  476. return _objectSpread(_objectSpread({}, axisItem), {}, {
  477. splitLinePosition: splitLinePosition
  478. });
  479. });
  480. }
  481. function getLineConfig(axisItem) {
  482. var animationCurve = axisItem.animationCurve,
  483. animationFrame = axisItem.animationFrame,
  484. rLevel = axisItem.rLevel;
  485. return [{
  486. name: 'polyline',
  487. index: rLevel,
  488. visible: axisItem.axisLine.show,
  489. animationCurve: animationCurve,
  490. animationFrame: animationFrame,
  491. shape: getLineShape(axisItem),
  492. style: getLineStyle(axisItem)
  493. }];
  494. }
  495. function getLineShape(axisItem) {
  496. var linePosition = axisItem.linePosition;
  497. return {
  498. points: linePosition
  499. };
  500. }
  501. function getLineStyle(axisItem) {
  502. return axisItem.axisLine.style;
  503. }
  504. function getTickConfig(axisItem) {
  505. var animationCurve = axisItem.animationCurve,
  506. animationFrame = axisItem.animationFrame,
  507. rLevel = axisItem.rLevel;
  508. var shapes = getTickShapes(axisItem);
  509. var style = getTickStyle(axisItem);
  510. return shapes.map(function (shape) {
  511. return {
  512. name: 'polyline',
  513. index: rLevel,
  514. visible: axisItem.axisTick.show,
  515. animationCurve: animationCurve,
  516. animationFrame: animationFrame,
  517. shape: shape,
  518. style: style
  519. };
  520. });
  521. }
  522. function getTickShapes(axisItem) {
  523. var tickLinePosition = axisItem.tickLinePosition;
  524. return tickLinePosition.map(function (points) {
  525. return {
  526. points: points
  527. };
  528. });
  529. }
  530. function getTickStyle(axisItem) {
  531. return axisItem.axisTick.style;
  532. }
  533. function getLabelConfig(axisItem) {
  534. var animationCurve = axisItem.animationCurve,
  535. animationFrame = axisItem.animationFrame,
  536. rLevel = axisItem.rLevel;
  537. var shapes = getLabelShapes(axisItem);
  538. var styles = getLabelStyle(axisItem, shapes);
  539. return shapes.map(function (shape, i) {
  540. return {
  541. name: 'text',
  542. index: rLevel,
  543. visible: axisItem.axisLabel.show,
  544. animationCurve: animationCurve,
  545. animationFrame: animationFrame,
  546. shape: shape,
  547. style: styles[i],
  548. setGraphCenter: function setGraphCenter() {
  549. return void 0;
  550. }
  551. };
  552. });
  553. }
  554. function getLabelShapes(axisItem) {
  555. var label = axisItem.label,
  556. tickPosition = axisItem.tickPosition,
  557. position = axisItem.position;
  558. return tickPosition.map(function (point, i) {
  559. return {
  560. position: getLabelRealPosition(point, position),
  561. content: label[i].toString()
  562. };
  563. });
  564. }
  565. function getLabelRealPosition(points, position) {
  566. var index = 0,
  567. plus = 10;
  568. if (position === 'top' || position === 'bottom') index = 1;
  569. if (position === 'top' || position === 'left') plus = -10;
  570. points = (0, _util2.deepClone)(points);
  571. points[index] += plus;
  572. return points;
  573. }
  574. function getLabelStyle(axisItem, shapes) {
  575. var position = axisItem.position;
  576. var style = axisItem.axisLabel.style;
  577. var align = getAxisLabelRealAlign(position);
  578. style = (0, _util.deepMerge)(align, style);
  579. var styles = shapes.map(function (_ref20) {
  580. var position = _ref20.position;
  581. return _objectSpread(_objectSpread({}, style), {}, {
  582. graphCenter: position
  583. });
  584. });
  585. return styles;
  586. }
  587. function getAxisLabelRealAlign(position) {
  588. if (position === 'left') return {
  589. textAlign: 'right',
  590. textBaseline: 'middle'
  591. };
  592. if (position === 'right') return {
  593. textAlign: 'left',
  594. textBaseline: 'middle'
  595. };
  596. if (position === 'top') return {
  597. textAlign: 'center',
  598. textBaseline: 'bottom'
  599. };
  600. if (position === 'bottom') return {
  601. textAlign: 'center',
  602. textBaseline: 'top'
  603. };
  604. }
  605. function getNameConfig(axisItem) {
  606. var animationCurve = axisItem.animationCurve,
  607. animationFrame = axisItem.animationFrame,
  608. rLevel = axisItem.rLevel;
  609. return [{
  610. name: 'text',
  611. index: rLevel,
  612. animationCurve: animationCurve,
  613. animationFrame: animationFrame,
  614. shape: getNameShape(axisItem),
  615. style: getNameStyle(axisItem)
  616. }];
  617. }
  618. function getNameShape(axisItem) {
  619. var name = axisItem.name,
  620. namePosition = axisItem.namePosition;
  621. return {
  622. content: name,
  623. position: namePosition
  624. };
  625. }
  626. function getNameStyle(axisItem) {
  627. var nameLocation = axisItem.nameLocation,
  628. position = axisItem.position,
  629. style = axisItem.nameTextStyle;
  630. var align = getNameRealAlign(position, nameLocation);
  631. return (0, _util.deepMerge)(align, style);
  632. }
  633. function getNameRealAlign(position, location) {
  634. if (position === 'top' && location === 'start' || position === 'bottom' && location === 'start' || position === 'left' && location === 'center') return {
  635. textAlign: 'right',
  636. textBaseline: 'middle'
  637. };
  638. if (position === 'top' && location === 'end' || position === 'bottom' && location === 'end' || position === 'right' && location === 'center') return {
  639. textAlign: 'left',
  640. textBaseline: 'middle'
  641. };
  642. if (position === 'top' && location === 'center' || position === 'left' && location === 'end' || position === 'right' && location === 'end') return {
  643. textAlign: 'center',
  644. textBaseline: 'bottom'
  645. };
  646. if (position === 'bottom' && location === 'center' || position === 'left' && location === 'start' || position === 'right' && location === 'start') return {
  647. textAlign: 'center',
  648. textBaseline: 'top'
  649. };
  650. }
  651. function getSplitLineConfig(axisItem) {
  652. var animationCurve = axisItem.animationCurve,
  653. animationFrame = axisItem.animationFrame,
  654. rLevel = axisItem.rLevel;
  655. var shapes = getSplitLineShapes(axisItem);
  656. var style = getSplitLineStyle(axisItem);
  657. return shapes.map(function (shape) {
  658. return {
  659. name: 'polyline',
  660. index: rLevel,
  661. visible: axisItem.splitLine.show,
  662. animationCurve: animationCurve,
  663. animationFrame: animationFrame,
  664. shape: shape,
  665. style: style
  666. };
  667. });
  668. }
  669. function getSplitLineShapes(axisItem) {
  670. var splitLinePosition = axisItem.splitLinePosition;
  671. return splitLinePosition.map(function (points) {
  672. return {
  673. points: points
  674. };
  675. });
  676. }
  677. function getSplitLineStyle(axisItem) {
  678. return axisItem.splitLine.style;
  679. }