Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
hinikai committed Dec 2, 2016
1 parent 29fd78c commit 8ba241e
Show file tree
Hide file tree
Showing 21 changed files with 4,060 additions and 41 deletions.
144 changes: 130 additions & 14 deletions build/mapv.js
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,48 @@
}
};

/**
* 获取当前列的最大值
*/
DataSet.prototype.getMax = function (columnName) {
var data = this._data;

if (!data || data.length <= 0) {
return;
}

var max = data[0][columnName];

for (var i = 1; i < data.length; i++) {
if (data[i][columnName] > max) {
max = data[i][columnName];
}
}

return max;
};

/**
* 获取当前列的最小值
*/
DataSet.prototype.getMin = function (columnName) {
var data = this._data;

if (!data || data.length <= 0) {
return;
}

var min = data[0][columnName];

for (var i = 1; i < data.length; i++) {
if (data[i][columnName] < min) {
min = data[i][columnName];
}
}

return min;
};

var pathSimple = {
drawDataSet: function drawDataSet(context, dataSet, options) {

Expand All @@ -1045,7 +1087,7 @@
var size = data._size || data.size || options._size || options.size || 5;
context.moveTo(data.x, data.y);
if (options.symbol === 'rect') {
context.rect(coordinates[0], coordinates[1], size, size);
context.rect(coordinates[0] - size / 2, coordinates[1] - size / 2, size, size);
} else {
context.arc(coordinates[0], coordinates[1], size, 0, Math.PI * 2);
}
Expand Down Expand Up @@ -1121,7 +1163,7 @@

context.fill();

if (item.strokeStyle || options.strokeStyle) {
if ((item.strokeStyle || options.strokeStyle) && options.lineWidth) {
context.stroke();
}
} else if (type == 'LineString') {
Expand Down Expand Up @@ -1154,7 +1196,7 @@

context.fill();

if (item.strokeStyle || options.strokeStyle) {
if ((item.strokeStyle || options.strokeStyle) && options.lineWidth) {
context.stroke();
}
} else if (type == 'LineString') {
Expand Down Expand Up @@ -1368,14 +1410,14 @@
});

context.beginPath();
context.rect(gridKey[0] * size + .5 + offset.x, gridKey[1] * size + .5 + offset.y, size - 1, size - 1);
context.rect(gridKey[0] * size + .5 + offset.x, gridKey[1] * size + .5 + offset.y, size, size);
context.fillStyle = intensity.getColor(grids[gridKey]);
context.fill();
if (options.showText) {
context.fillStyle = 'white';
context.fillText(grids[gridKey], gridKey[0] * size + .5 + offset.x + size / 2 - 1, gridKey[1] * size + .5 + offset.y + size / 2 - 1);
context.fillText(grids[gridKey], gridKey[0] * size + .5 + offset.x + size / 2, gridKey[1] * size + .5 + offset.y + size / 2);
}
if (options.strokeStyle || options.lineWidth) {
if (options.strokeStyle && options.lineWidth) {
context.stroke();
}
}
Expand Down Expand Up @@ -1477,7 +1519,7 @@

context.fillStyle = intensity.getColor(count);
context.fill();
if (options.strokeStyle || options.lineWidth) {
if (options.strokeStyle && options.lineWidth) {
context.stroke();
}
}
Expand Down Expand Up @@ -2073,6 +2115,27 @@
return value;
};

/**
* 根据DataSet自动生成对应的splitList
*/
Category.prototype.generateByDataSet = function (dataSet) {
var colors = ['rgba(255, 255, 0, 0.8)', 'rgba(253, 98, 104, 0.8)', 'rgba(255, 146, 149, 0.8)', 'rgba(255, 241, 193, 0.8)', 'rgba(110, 176, 253, 0.8)', 'rgba(52, 139, 251, 0.8)', 'rgba(17, 102, 252, 0.8)'];
var data = dataSet.get();
this.splitList = {};
var count = 0;
for (var i = 0; i < data.length; i++) {
if (this.splitList[data[i].count] === undefined) {
this.splitList[data[i].count] = colors[count];
count++;
}
if (count >= colors.length - 1) {
break;
}
}

this.splitList['other'] = colors[colors.length - 1];
};

/**
* @author kyle / http://nikai.us/
*/
Expand Down Expand Up @@ -2118,6 +2181,37 @@
return value;
};

/**
* 根据DataSet自动生成对应的splitList
*/
Choropleth.prototype.generateByDataSet = function (dataSet) {

var min = dataSet.getMin('count');
var max = dataSet.getMax('count');

this.generateByMinMax(min, max);
};

/**
* 根据DataSet自动生成对应的splitList
*/
Choropleth.prototype.generateByMinMax = function (min, max) {
var colors = ['rgba(255, 255, 0, 0.8)', 'rgba(253, 98, 104, 0.8)', 'rgba(255, 146, 149, 0.8)', 'rgba(255, 241, 193, 0.8)', 'rgba(110, 176, 253, 0.8)', 'rgba(52, 139, 251, 0.8)', 'rgba(17, 102, 252, 0.8)'];
var splitNum = (max - min) / 7;
var index = min;
this.splitList = [];
var count = 0;
while (index < max) {
this.splitList.push({
start: index,
end: index + splitNum,
value: colors[count]
});
count++;
index += splitNum;
}
};

/**
* Timer
* @author kyle / http://nikai.us/
Expand Down Expand Up @@ -2235,7 +2329,12 @@
this.options.maxDelta = 0.2;
this.options.loop = options.loop === undefined ? true : options.loop;

this.steps(options.steps);
options.stepsRange = options.stepsRange || {
start: 0,
end: 100
};

this.steps(options.stepsRange.start || 0, options.stepsRange.end || 100);
if (options.stepsRange && options.stepsRange.start !== undefined && options.stepsRange.end !== undefined) {
this.stepsRange(options.stepsRange.start, options.stepsRange.end);
}
Expand Down Expand Up @@ -2298,9 +2397,8 @@
return this;
},

steps: function steps(_) {
this.options.steps = _;
this._defaultStepsRange = new AnimatorStepsRange(0, _);
steps: function steps(start, end) {
this._defaultStepsRange = new AnimatorStepsRange(start, end);
return this.rescale();
},

Expand Down Expand Up @@ -2536,9 +2634,11 @@
y: 0
};

var textKey = options.textKey || 'text';

for (var i = 0, len = data.length; i < len; i++) {
var coordinates = data[i].geometry._coordinates || data[i].geometry.coordinates;
context.fillText(data[i].text, coordinates[0] + offset.x, coordinates[1] + offset.y);
context.fillText(data[i][textKey], coordinates[0] + offset.x, coordinates[1] + offset.y);
};
}
};
Expand Down Expand Up @@ -2572,6 +2672,8 @@
dataSet = new DataSet(dataSet);
}

this.dataSet = dataSet;

var self = this;
var data = null;
options = options || {};
Expand Down Expand Up @@ -2626,7 +2728,8 @@
context.beginPath();
pathSimple.draw(context, data[i], self.options);
if (context.isPointInPath(pixel.x * canvasLayer.devicePixelRatio, pixel.y * canvasLayer.devicePixelRatio)) {
self.options.methods.click(data[i]);
self.options.methods.click(data[i], e);
return;
}
}
});
Expand Down Expand Up @@ -2807,11 +2910,24 @@
self.intensity = new Intensity({
maxSize: self.options.maxSize,
gradient: self.options.gradient,
max: self.options.max
max: self.options.max || this.dataSet.getMax('count')
});

self.category = new Category(self.options.splitList);
self.choropleth = new Choropleth(self.options.splitList);
if (self.options.splitList === undefined) {
self.category.generateByDataSet(this.dataSet);
}

if (self.options.zIndex) {
this.canvasLayer && this.canvasLayer.setZIndex(self.options.zIndex);
}

if (self.options.splitList === undefined) {
var min = self.options.min || this.dataSet.getMin('count');
var max = self.options.max || this.dataSet.getMax('count');
self.choropleth.generateByMinMax(min, max);
}
};

Layer.prototype.show = function () {
Expand Down
4 changes: 2 additions & 2 deletions build/mapv.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 8ba241e

Please sign in to comment.