Fix jsdocs and refactor from mixin to subclass.
MODIFY
src/contourFeature.js
src/contourFeature.js
var inherit = require('./inherit');
-var feature = require('./feature');
+var meshFeature = require('./meshFeature');
/**
* Contour feature specification.
@@ -13,12 +13,12 @@ var feature = require('./feature');
* 1.
* @property {geo.geoPosition|function} [style.position=data] The position of
* each data element. This defaults to just using `x`, `y`, and `z`
- * properties of the data element itself. The position is in the
- * feature's gcs coordinates.
+ * properties of the data element itself. The position is in the feature's
+ * gcs coordinates.
* @property {number|function} [style.value=data.z] The value of each data
- * element. This defaults `z` properties of the data element. If the
- * value of a grid point is `null` or `undefined`, that point and elements
- * that use that point won't be included in the results.
+ * element. This defaults `z` properties of the data element. If the value
+ * of a grid point is `null` or `undefined`, that point and elements that
+ * use that point won't be included in the results.
* @property {geo.contourFeature.contourSpec} [contour] The contour
* specification for the feature.
*/
@@ -26,7 +26,7 @@ var feature = require('./feature');
/**
* Contour specification.
*
- * @typedef {geo.meshMixin.meshSpec} geo.contourFeature.contourSpec
+ * @typedef {geo.meshFeature.meshSpec} geo.contourFeature.contourSpec
* @property {number} [min] Minimum contour value. If unspecified, taken from
* the computed minimum of the `value` style.
* @property {number} [max] Maximum contour value. If unspecified, taken from
@@ -44,13 +44,13 @@ var feature = require('./feature');
* @property {geo.geoColor[]} [colorRange=<color table>] An array of colors
* used to show the range of values. The default is a 9-step color table.
* @property {number[]} [opacityRange] An array of opacities used to show the
- * range of values. If unspecified, the opacity is 1. If this is a
- * shorter list than the `colorRange`, an opacity of 1 is used for the
- * entries near the end of the color range.
+ * range of values. If unspecified, the opacity is 1. If this is a shorter
+ * list than the `colorRange`, an opacity of 1 is used for the entries near
+ * the end of the color range.
* @property {number[]} [rangeValues] An array used to map values to the
- * `colorRange`. By default, values are spaced linearly. If specified,
- * the entries must be increasing weakly monotonic, and there must be one
- * more entry then the length of `colorRange`.
+ * `colorRange`. By default, values are spaced linearly. If specified, the
+ * entries must be increasing weakly monotonic, and there must be one more
+ * entry then the length of `colorRange`.
*/
/**
@@ -87,7 +87,9 @@ var feature = require('./feature');
*
* @class
* @alias geo.contourFeature
- * @extends geo.feature
+ * @extends geo.meshFeature
+ *
+ * @borrows geo.contourFeature#mesh as geo.contourFeature#contour
*
* @param {geo.contourFeature.spec} arg
* @returns {geo.contourFeature}
@@ -102,7 +104,7 @@ var contourFeature = function (arg) {
var util = require('./util');
arg = arg || {};
- feature.call(this, arg);
+ meshFeature.call(this, arg);
/**
* @private
@@ -205,6 +207,8 @@ var contourFeature = function (arg) {
return result;
};
+ this.contour = m_this.mesh;
+
/**
* Initialize.
*
@@ -213,13 +217,6 @@ var contourFeature = function (arg) {
this._init = function (arg) {
s_init.call(m_this, arg);
- /* Mixin the mesh properties and functions. */
- var meshMixin = require('./meshMixin');
- meshMixin.call(m_this, arg);
- /* Define contour the same as mesh; this keeps compatibility with older
- * forms and makes the named function more intuitive. */
- this.contour = this.mesh;
-
var defaultStyle = $.extend(
{},
{
@@ -261,7 +258,7 @@ var contourFeature = function (arg) {
return this;
};
-inherit(contourFeature, feature);
+inherit(contourFeature, meshFeature);
module.exports = contourFeature;
/* Example:

MODIFY
src/index.js
src/index.js
@@ -58,7 +58,7 @@ module.exports = $.extend({
lineFeature: require('./lineFeature'),
map: require('./map'),
mapInteractor: require('./mapInteractor'),
- meshMixin: require('./meshMixin'),
+ meshFeature: require('./meshFeature'),
object: require('./object'),
osmLayer: require('./osmLayer'),
pathFeature: require('./pathFeature'),

RENAME
src/meshMixin.js
src/meshFeature.js
+var inherit = require('./inherit');
+var feature = require('./feature');
+
/**
* A mesh formed by a set of triangular or square elements or a
* squarely-connected grid that is of rectangular extent. The gird can be
* regularly spaced or have arbitrary position coordinates for each node.
*
- * @typedef {object} geo.meshMixin.meshSpec
+ * @typedef {object} geo.meshFeature.meshSpec
* @property {number[]|array.<number[]>} [elements] If specified, a list of
* indices into the data array that form elements. If this is an array of
* arrays, each subarray must have at least either 3 values for triangular
* ensure that the map is covered from -180 to 180 as appropriate. Set
* this to `false` if using a non-longitude x coordinate.
*/
+
/**
* A set of triangular elements and their associated positions for a mesh.
*
- * @typedef {object} geo.meshMixin.meshInfo
+ * @typedef {object} geo.meshFeature.meshInfo
* @property {string} shape One of `'triangle'` or `'square'`. If `square`,
* each pair of elements is one square. These elements have vertices v00,
* v01, v02, v10, v11, v12. The square is formed via v00-v01-v10-v11-v00.
* @property {number} verticesPerElement 3 for triangles, 6 for squares.
*/
-var meshMixin = function (arg) {
+/**
+ * Create a new instance of class meshFeature. This should be the parent of a
+ * more useable feature class.
+ *
+ * @class
+ * @alias geo.meshFeature
+ * @extends geo.feature
+ *
+ * @param {geo.meshFeature.spec} arg
+ * @returns {this}
+ */
+var meshFeature = function (arg) {
+ 'use strict';
+ if (!(this instanceof meshFeature)) {
+ return new meshFeature(arg);
+ }
+
var $ = require('jquery');
var util = require('./util');
+ arg = arg || {};
+ feature.call(this, arg);
+
var m_this = this,
+ s_init = this._init,
m_mesh = {};
/**
* Get/Set mesh accessor.
*
- * @param {string|geo.meshObject.meshSpecc} [specOrProperty] If `undefined`,
+ * @param {string|geo.meshFeature.meshSpec} [specOrProperty] If `undefined`,
* return the current mesh specification. If a string is specified,
* either get or set the named mesh property. If an object is given, set
* or update the specification with the specified parameters.
* @param {object} [value] If `specOrProperty` is a string, set that property
* to `value`. If `undefined`, return the current value of the named
* property.
- * @returns {geo.meshObject.meshSpec|object|this} The current mesh
+ * @returns {geo.meshFeature.meshSpec|object|this} The current mesh
* specification, the value of a named mesh property, or this mesh object.
*/
this.mesh = function (specOrProperty, value) {
@@ -182,7 +206,7 @@ var meshMixin = function (arg) {
* (data[idx], idx). If a key is named `used`, then if its function
* returns a falsy value for a data point, the vertex associated with that
* data point is removed from the resultant mesh.
- * @returns {geo.meshMixin.meshInfo} An object with the mesh information.
+ * @returns {geo.meshFeature.meshInfo} An object with the mesh information.
*/
this.createMesh = function (vertexValueFuncs) {
vertexValueFuncs = vertexValueFuncs || {};
@@ -388,6 +412,14 @@ var meshMixin = function (arg) {
return result;
};
+ /**
+ * Initialize.
+ *
+ * @param {geo.meshFeature.spec} arg The mesh feature specification.
+ */
+ this._init = function (arg) {
+ s_init.call(m_this, arg);
+
/* Initialize from arguments */
arg = arg || {};
var style = $.extend({}, {
@@ -403,4 +435,9 @@ var meshMixin = function (arg) {
this.style(style);
};
-module.exports = meshMixin;
+ return this;
+};
+
+inherit(meshFeature, feature);
+
+module.exports = meshFeature;

MODIFY
src/pointFeature.js
src/pointFeature.js
@@ -352,9 +352,7 @@ var pointFeature = function (arg) {
/**
* Object specification for a point feature.
*
- * @extends geo.feature.spec // need to make a jsdoc plugin for this to work
- * @typedef geo.pointFeature.spec
- * @type {object}
+ * @typedef {geo.feature.spec} geo.pointFeature.spec
*/
/**

MODIFY
tests/cases/contourFeature.js
tests/cases/contourFeature.js
@@ -26,6 +26,9 @@ describe('Contour Feature', function () {
it('direct create', function () {
var contour = geo.contourFeature({layer: layer});
expect(contour instanceof geo.contourFeature).toBe(true);
+ expect(contour instanceof geo.meshFeature).toBe(true);
+ var mesh = geo.meshFeature({layer: layer});
+ expect(mesh instanceof geo.meshFeature).toBe(true);
});
});

Fix jsdocs and refactor from mixin to subclass.