Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修改rollup最新打包规则和添加opts.tickCount轴稀数量 #444

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions dist/wxcharts-min.js

Large diffs are not rendered by default.

68 changes: 46 additions & 22 deletions dist/wxcharts.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
/*
* charts for WeChat small app v1.0
*
* https://github.com/xiaolin3303/wx-charts
* 2016-11-28
*
* Designed and built with all the love of Web
*/

'use strict';

var config = {
Expand Down Expand Up @@ -92,6 +83,20 @@ var util = {
var flag = obj2.start.x > obj1.end.x || obj2.end.x < obj1.start.x || obj2.end.y > obj1.start.y || obj2.start.y < obj1.end.y;

return !flag;
},
sparseArray: function sparseArray(arr, num) {
var numIdx = []; // 所需数量的索引
if (num > 1) {
var group = num - 1; // 把数组分成除去头尾剩余的num - 1组
var length = arr.length;
var groupIdx = parseInt(length / group);
numIdx.push(0);
for (var i = 1; i < group; i++) {
numIdx.push(i * groupIdx);
}
numIdx.push(length - 1);
}
return numIdx;
}
};

Expand Down Expand Up @@ -336,8 +341,6 @@ function getSeriesDataItem(series, index) {
return data;
}



function getMaxTextListLength(list) {
var lengthList = list.map(function (item) {
return measureText(item);
Expand Down Expand Up @@ -849,6 +852,7 @@ function drawRadarLabel(angleList, radius, centerPosition, opts, config, context

function drawPieText(series, opts, config, context, radius, center) {
var lineRadius = radius + config.pieChartLinePadding;
lineRadius + config.pieChartTextPadding;
var textObjectCollection = [];
var lastTextObject = null;

Expand Down Expand Up @@ -1057,6 +1061,8 @@ function drawColumnDataPoints(series, opts, config, context) {

var minRange = ranges.pop();
var maxRange = ranges.shift();
opts.height - config.padding - config.xAxisHeight - config.legendHeight;

context.save();
if (opts._scrollDistance_ && opts._scrollDistance_ !== 0 && opts.enableScroll === true) {
context.translate(opts._scrollDistance_, 0);
Expand Down Expand Up @@ -1286,8 +1292,6 @@ function drawToolTipBridge(opts, config, context, process) {
function drawXAxis(categories, opts, config, context) {
var _getXAxisPoints4 = getXAxisPoints(categories, opts, config),
xAxisPoints = _getXAxisPoints4.xAxisPoints,
startX = _getXAxisPoints4.startX,
endX = _getXAxisPoints4.endX,
eachSpacing = _getXAxisPoints4.eachSpacing;

var startY = opts.height - config.padding - config.xAxisHeight - config.legendHeight;
Expand All @@ -1310,9 +1314,17 @@ function drawXAxis(categories, opts, config, context) {
}
});
} else {
var tickCountArr = util.sparseArray(xAxisPoints, opts.tickCount); // x轴下划线索引
xAxisPoints.forEach(function (item, index) {
context.moveTo(item, startY);
context.lineTo(item, endY);
if (opts.tickCount > 1) {
if (tickCountArr.includes(index)) {
context.moveTo(item, startY);
context.lineTo(item, endY);
}
} else {
context.moveTo(item, startY);
context.lineTo(item, endY);
}
});
}
}
Expand All @@ -1324,8 +1336,17 @@ function drawXAxis(categories, opts, config, context) {
var maxXAxisListLength = Math.min(categories.length, Math.ceil(validWidth / config.fontSize / 1.5));
var ratio = Math.ceil(categories.length / maxXAxisListLength);

var tickCountArr2 = util.sparseArray(categories, opts.tickCount); // x轴文字索引
categories = categories.map(function (item, index) {
return index % ratio !== 0 ? '' : item;
if (opts.tickCount > 1) {
if (tickCountArr2.includes(index)) {
return item;
} else {
return '';
}
} else {
return index % ratio !== 0 ? '' : item;
}
});

if (config._xAxisTextAngle_ === 0) {
Expand Down Expand Up @@ -1401,6 +1422,7 @@ function drawYAxis(series, opts, config, context) {
var eachSpacing = Math.floor(spacingValid / config.yAxisSplit);
var startX = config.padding + yAxisTotalWidth;
var endX = opts.width - config.padding;
config.padding;
var endY = opts.height - config.padding - config.xAxisHeight - config.legendHeight;

// set YAxis background
Expand Down Expand Up @@ -1442,6 +1464,7 @@ function drawLegend(series, opts, config, context) {

var _calLegendData = calLegendData(series, opts, config),
legendList = _calLegendData.legendList;
_calLegendData.legendHeight;

var padding = 5;
var marginTop = 8;
Expand Down Expand Up @@ -1918,13 +1941,14 @@ var Charts = function Charts(opts) {
opts.extra = opts.extra || {};
opts.legend = opts.legend === false ? false : true;
opts.animation = opts.animation === false ? false : true;
var config$$1 = assign({}, config);
config$$1.yAxisTitleWidth = opts.yAxis.disabled !== true && opts.yAxis.title ? config$$1.yAxisTitleWidth : 0;
config$$1.pieChartLinePadding = opts.dataLabel === false ? 0 : config$$1.pieChartLinePadding;
config$$1.pieChartTextPadding = opts.dataLabel === false ? 0 : config$$1.pieChartTextPadding;
opts.tickCount = opts.tickCount || null;
var config$1 = assign({}, config);
config$1.yAxisTitleWidth = opts.yAxis.disabled !== true && opts.yAxis.title ? config$1.yAxisTitleWidth : 0;
config$1.pieChartLinePadding = opts.dataLabel === false ? 0 : config$1.pieChartLinePadding;
config$1.pieChartTextPadding = opts.dataLabel === false ? 0 : config$1.pieChartTextPadding;

this.opts = opts;
this.config = config$$1;
this.config = config$1;
this.context = wx.createCanvasContext(opts.canvasId);
// store calcuated chart data
// such as chart point coordinate
Expand All @@ -1936,7 +1960,7 @@ var Charts = function Charts(opts) {
distance: 0
};

drawCharts.call(this, opts.type, opts, config$$1, this.context);
drawCharts.call(this, opts.type, opts, config$1, this.context);
};

Charts.prototype.updateData = function () {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"babel-plugin-external-helpers": "^6.18.0",
"babel-preset-es2015": "^6.18.0",
"rollup-plugin-babel": "^2.6.1",
"rollup-plugin-uglify": "^1.0.1"
"rollup-plugin-uglify": "^6.0.4"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
Expand Down
8 changes: 5 additions & 3 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ let banner = `/*
`;

export default {
entry: 'src/app.js',
format: 'cjs',
dest: 'dist/wxcharts.js',
input: 'src/app.js',
output: {
file: 'dist/wxcharts.js',
format: 'cjs'
},
plugins: [
babel({
exclude: 'node_modules/**',
Expand Down
10 changes: 6 additions & 4 deletions rollup.config.prod.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import babel from 'rollup-plugin-babel';
import uglify from 'rollup-plugin-uglify';
import { uglify } from "rollup-plugin-uglify";

let banner = `/*
* charts for WeChat small app v1.0
Expand All @@ -12,9 +12,11 @@ let banner = `/*
`;

export default {
entry: 'src/app.js',
format: 'cjs',
dest: 'dist/wxcharts-min.js',
input: 'src/app.js',
output: {
file: 'dist/wxcharts-min.js',
format: 'cjs'
},
plugins: [
babel({
exclude: 'node_modules/**',
Expand Down
1 change: 1 addition & 0 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ let Charts = function(opts) {
opts.extra = opts.extra || {};
opts.legend = opts.legend === false ? false : true;
opts.animation = opts.animation === false ? false : true;
opts.tickCount = opts.tickCount || null;
let config = assign({}, Config);
config.yAxisTitleWidth = opts.yAxis.disabled !== true && opts.yAxis.title ? config.yAxisTitleWidth : 0;
config.pieChartLinePadding = opts.dataLabel === false ? 0 : config.pieChartLinePadding;
Expand Down
23 changes: 20 additions & 3 deletions src/components/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,17 @@ export function drawXAxis (categories, opts, config, context) {
}
});
} else {
const tickCountArr = Util.sparseArray(xAxisPoints, opts.tickCount) // x轴下划线索引
xAxisPoints.forEach(function(item, index) {
context.moveTo(item, startY);
context.lineTo(item, endY);
if (opts.tickCount > 1) {
if (tickCountArr.includes(index)) {
context.moveTo(item, startY);
context.lineTo(item, endY);
}
} else {
context.moveTo(item, startY);
context.lineTo(item, endY);
}
});
}
}
Expand All @@ -277,8 +285,17 @@ export function drawXAxis (categories, opts, config, context) {
let maxXAxisListLength = Math.min(categories.length, Math.ceil(validWidth / config.fontSize / 1.5));
let ratio = Math.ceil(categories.length / maxXAxisListLength);

const tickCountArr2 = Util.sparseArray(categories, opts.tickCount) // x轴文字索引
categories = categories.map((item, index) => {
return index % ratio !== 0 ? '' : item;
if (opts.tickCount > 1) {
if (tickCountArr2.includes(index)) {
return item
} else {
return ''
}
} else {
return index % ratio !== 0 ? '' : item;
}
});

if (config._xAxisTextAngle_ === 0) {
Expand Down
14 changes: 14 additions & 0 deletions src/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ let util = {

return !flag;
},
sparseArray: function (arr, num) {
const numIdx = []; // 所需数量的索引
if (num > 1) {
let group = num - 1; // 把数组分成除去头尾剩余的num - 1组
let length = arr.length;
let groupIdx = parseInt(length / group);
numIdx.push(0);
for (let i = 1; i < group; i++) {
numIdx.push(i * groupIdx)
}
numIdx.push(length - 1);
}
return numIdx;
}
}

export default util;