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

Add unit tests for the point feature. #684

Merged
merged 1 commit into from
Mar 30, 2017
Merged
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
6 changes: 6 additions & 0 deletions src/gl/pointFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ var gl_pointFeature = function (arg) {
m_pixelWidthUniform = null,
m_aspectUniform = null,
m_dynamicDraw = arg.dynamicDraw === undefined ? false : arg.dynamicDraw,
/* If you are drawing very large points, you will often get better
* performance using a different primitiveShape. The 'sprite' shape uses
* the least memory, but has hardware-specific limitations to its size.
* 'triangle' seems to be fastest on low-powered hardware, but 'square'
* visits fewer fragments. */
m_primitiveShape = 'sprite', // arg can change this, below
s_init = this._init,
s_update = this._update,
Expand Down Expand Up @@ -529,6 +534,7 @@ var gl_pointFeature = function (arg) {
////////////////////////////////////////////////////////////////////////////
this._exit = function () {
m_this.renderer().contextRenderer().removeActor(m_actor);
m_actor = null;
s_exit();
};

Expand Down
74 changes: 19 additions & 55 deletions src/pointFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,9 @@ var pointFeature = function (arg) {
m_clusterTree = null;
m_clustering = false;
s_data(m_allData);
m_allData = null;
} else if (!m_clustering && val) {
} else if (val && m_clustering !== val) {
// Generate the cluster tree
m_clustering = true;
m_clustering = val;
m_this._clusterData();
}
return m_this;
Expand Down Expand Up @@ -158,12 +157,14 @@ var pointFeature = function (arg) {
if (val === undefined) {
return m_this.style('position');
} else {
val = util.ensureFunction(val);
var isFunc = util.isFunction(val);
m_this.style('position', function (d, i) {
if (d.__cluster) {
return d;
} else {
} else if (isFunc) {
return val(d, i);
} else {
return val;
}
});
m_this.dataTime().modified();
Expand Down Expand Up @@ -224,10 +225,6 @@ var pointFeature = function (arg) {
strokeWidth = m_this.style.get('strokeWidth'),
radius = m_this.style.get('radius');

if (!m_this.selectionAPI()) {
return [];
}

data = m_this.data();
if (!data || !data.length) {
return {
Expand All @@ -236,6 +233,10 @@ var pointFeature = function (arg) {
};
}

// We need to do this before we find corners, since the max radius is
// determined then
m_this._updateRangeTree();

map = m_this.layer().map();
pt = map.gcsToDisplay(p);
// check all corners to make sure we handle rotations
Expand All @@ -259,7 +260,6 @@ var pointFeature = function (arg) {
wigglemaps.vect(min.x, min.y),
wigglemaps.vect(max.x, max.y)
);
m_this._updateRangeTree();
m_rangeTree.search(box).forEach(function (q) {
idx.push(q.idx);
});
Expand Down Expand Up @@ -319,8 +319,10 @@ var pointFeature = function (arg) {
if (data === undefined) {
return s_data();
}
if (m_clustering && !m_ignoreData) {
if (!m_ignoreData) {
m_allData = data;
}
if (m_clustering && !m_ignoreData) {
m_this._clusterData();
} else {
s_data(data);
Expand All @@ -329,55 +331,13 @@ var pointFeature = function (arg) {
return m_this;
};

////////////////////////////////////////////////////////////////////////////
/**
* Returns the bounding box for a given datum in screen coordinates as an
* object: ::
*
* {
* min: {
* x: value,
* y: value
* },
* max: {
* x: value,
* y: value
* }
* }
*
* @returns {object}
*/
////////////////////////////////////////////////////////////////////////////
this._boundingBox = function (d) {
var pt, radius;

// get the position in geo coordinates
pt = m_this.position()(d);

// convert to screen coordinates
pt = m_this.layer().map().gcsToDisplay(pt);

// get the radius of the points (should we add stroke width?)
radius = m_this.style().radius(d);

return {
min: {
x: pt.x - radius,
y: pt.y - radius
},
max: {
x: pt.x + radius,
y: pt.y + radius
}
};
};

////////////////////////////////////////////////////////////////////////////
/**
* Initialize
*/
////////////////////////////////////////////////////////////////////////////
this._init = function (arg) {
arg = arg || {};
s_init.call(m_this, arg);

var defaultStyle = $.extend(
Expand All @@ -403,6 +363,9 @@ var pointFeature = function (arg) {
}

m_this.style(defaultStyle);
if (defaultStyle.position) {
m_this.position(defaultStyle.position);
}
m_this.dataTime().modified();

// bind to the zoom handler for point clustering
Expand All @@ -429,9 +392,10 @@ var pointFeature = function (arg) {
* @param {geo.pointFeature.spec} spec The object specification
* @returns {geo.pointFeature|null}
*/
pointFeature.create = function (layer, renderer, spec) {
pointFeature.create = function (layer, spec) {
'use strict';

spec = spec || {};
spec.type = 'point';
return feature.create(layer, spec);
};
Expand Down
Loading