UNPKG

nuke-biz-qn-chart

Version:

weex 版本千牛业务图表库,基于weex + rax,包含线图、柱状图、饼图、雷达图等,其他类型的图表正在按业务需求陆续接入。其中 native 端由客户端插件实现,h5 端使用 g2-mobile

116 lines (101 loc) 3.91 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseDataForWeex = undefined; var _lodash = require('lodash.groupby'); var _lodash2 = _interopRequireDefault(_lodash); var _lodash3 = require('lodash.foreach'); var _lodash4 = _interopRequireDefault(_lodash3); var _nukeBizChart = require('nuke-biz-chart'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * 把 antv 的数据遍历、格式化为千牛 native 可识别的数据格式。 * */ function parseData(options) { var data = options.data, cols = options.cols, colors = options.colors, _options$points = options.points, points = _options$points === undefined ? {} : _options$points, _options$lineWidth = options.lineWidth, lineWidth = _options$lineWidth === undefined ? 2 : _options$lineWidth, drawValues = options.drawValues, lineSeperator = options.lineSeperator, xAxis = options.xAxis, yAxis = options.yAxis, fill = options.fill, _options$smooth = options.smooth, smooth = _options$smooth === undefined ? false : _options$smooth; var _points$drawPoints = points.drawPoints, drawPoints = _points$drawPoints === undefined ? false : _points$drawPoints, _points$radius = points.radius, radius = _points$radius === undefined ? 3 : _points$radius, _points$holeRadius = points.holeRadius, holeRadius = _points$holeRadius === undefined ? 2 : _points$holeRadius; var colorSeries = colors || _nukeBizChart.defaultSettings.colors; var dataObj = {}; // antv 的图标数据是混杂的,必须要先分成若干个数据块 if (lineSeperator) { dataObj = (0, _lodash2.default)(data, lineSeperator); } else { dataObj[yAxis.name] = Object.assign([], data); } var labels = []; var dataResult = { dataSets: [], "drawValues": drawValues, "valueTextColor": "#000000", "valueTextSize": 15 }; var colorIndex = 0; (0, _lodash4.default)(dataObj, function (item, key) { var entries = item; labels = []; var dataSetItem = { label: key, color: colorSeries[colorIndex], circleColor: colorSeries[colorIndex], circleRadius: 3, drawCircleHole: false, drawFilled: false, drawCircles: false, drawValues: drawValues, mode: smooth ? "CUBIC_BEZIER" : "LINEAR", //LINEAR(默认值),STEPPED,CUBIC_BEZIER,HORIZONTAL_BEZIER lineWidth: lineWidth }; if (drawPoints) { dataSetItem.drawCircles = true; dataSetItem.drawCircleHole = !points.filled, dataSetItem.circleRadius = radius; dataSetItem.circleHoleRadius = holeRadius; dataSetItem.circleHoleColor = '#ffffff'; } if (fill.drawFilled) { dataSetItem.drawFilled = true; dataSetItem.fillAlpha = fill.fillAlpha || 0.5; dataSetItem.fillColor = colorSeries[colorIndex]; } for (var i = 0; i < entries.length; i++) { var x = entries[i][xAxis.name]; // entries[i] = {"x": entries[i][xAxis],"y": entries[i][yAxis]}; entries[i] = { "x": i, "y": entries[i][yAxis.name] }; labels.push(x.toString()); } dataSetItem['entries'] = entries; dataResult['dataSets'].push(dataSetItem); colorIndex++; }); var result = { dataResult: dataResult, labels: labels, colors: colorSeries }; return result; } function parseDataForWeex(options) { // const {data,cols,lineSeperator,xAxis,yAxis} = options; var dataArr = parseData(options); return dataArr; } exports.parseDataForWeex = parseDataForWeex;