Skip to content

Commit

Permalink
Fix jsdocs for the path feature.
Browse files Browse the repository at this point in the history
This also normalizes some of the arguments to make it more like other
features (for instance, actually using the position accessor).
  • Loading branch information
manthey committed Nov 6, 2018
1 parent ea6d0a6 commit e694122
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 39 deletions.
32 changes: 11 additions & 21 deletions src/d3/pathFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ var registerFeature = require('../registry').registerFeature;
var pathFeature = require('../pathFeature');

/**
* Create a new instance of class pathFeature
* Create a new instance of class geo.d3.pathFeature.
*
* @class
* @alias geo.d3.pathFeature
* @extends geo.pathFeature
* @extends geo.d3.object
* @param {geo.pathFeature.spec} arg
* @returns {geo.d3.pathFeature}
*/
var d3_pathFeature = function (arg) {
Expand All @@ -26,33 +27,22 @@ var d3_pathFeature = function (arg) {
pathFeature.call(this, arg);
object.call(this);

/**
* @private
*/
var m_this = this,
s_init = this._init,
m_buildTime = timestamp(),
s_update = this._update,
m_style = {};

m_style.style = {};

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

/**
* Build
* Build.
*
* @override
* @returns {this}
*/
this._build = function () {
var data = m_this.data() || [],
s_style = m_this.style(),
posFunc = m_this.style.get('position'),
tmp, diag;
s_update.call(m_this);

Expand All @@ -67,8 +57,8 @@ var d3_pathFeature = function (arg) {
data.forEach(function (d, i) {
var src, trg;
if (i < data.length - 1) {
src = d;
trg = data[i + 1];
src = posFunc(d, i);
trg = posFunc(data[i + 1], i + 1);
tmp.push({
source: m_this.featureGcsToDisplay(src),
target: m_this.featureGcsToDisplay(trg)
Expand All @@ -84,8 +74,8 @@ var d3_pathFeature = function (arg) {
m_style.append = 'path';
m_style.classes = ['d3PathFeature'];
m_style.style = $.extend({
'fill': function () { return false; },
'fillColor': function () { return { r: 0, g: 0, b: 0 }; }
fill: function () { return false; },
fillColor: {r: 0, g: 0, b: 0}
}, s_style);
m_style.visible = m_this.visible;

Expand All @@ -97,9 +87,9 @@ var d3_pathFeature = function (arg) {
};

/**
* Update
* Update.
*
* @override
* @returns {this}
*/
this._update = function () {
s_update.call(m_this);
Expand Down
64 changes: 46 additions & 18 deletions src/pathFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,32 @@ var inherit = require('./inherit');
var feature = require('./feature');

/**
* Create a new instance of class pathFeature
* Specification for pathFeature.
*
* @typedef {geo.feature.spec} geo.pathFeature.spec
* @extends {geo.feature.spec}
* @property {geo.geoPosition|function} [position] Position of the data.
* Default is (data).
*/

/**
* Style specification for a path feature.
*
* @typedef {geo.feature.styleSpec} geo.pathFeature.styleSpec
* @extends geo.feature.styleSpec
* @property {geo.geoColor|function} [strokeColor='white'] Color to stroke each
* path.
* @property {number|function} [strokeWidth=1] The weight of the path's
* stroke in pixels.
*/

/**
* Create a new instance of class pathFeature.
*
* @class
* @alias geo.pathFeature
* @extends geo.feature
* @param {geo.pathFeature.spec} arg
* @returns {geo.pathFeature}
*/
var pathFeature = function (arg) {
Expand All @@ -18,51 +39,58 @@ var pathFeature = function (arg) {
arg = arg || {};
feature.call(this, arg);

/**
* @private
*/
var m_this = this,
m_position = arg.position === undefined ? [] : arg.position,
s_init = this._init;

this.featureType = 'path';

/**
* Get/Set positions
* Get/Set position.
*
* @returns {geo.pathFeature}
* @param {function|geo.geoPosition} [val] If not specified, return the
* position accessor. Otherwise, change the position accessor.
* @returns {this|function}
*/
this.position = function (val) {
if (val === undefined) {
return m_position;
return m_this.style('position');
}
if (val !== m_this.style('position')) {
m_this.style('position', val);
m_this.dataTime().modified();
m_this.modified();
}
// Copy incoming array of positions
m_position = val;
m_this.dataTime().modified();
m_this.modified();
return m_this;
};

/**
* Initialize
* Initialize.
*
* @param {geo.pathFeature.spec} arg The feature specification.
* @returns {this}
*/
this._init = function (arg) {
s_init.call(m_this, arg);

var defaultStyle = $.extend(
{},
{
'strokeWidth': function () { return 1; },
'strokeColor': function () { return { r: 1.0, g: 1.0, b: 1.0 }; }
strokeWidth: 1,
strokeColor: {r: 1.0, g: 1.0, b: 1.0},
position: function (d) { return d; }
},
arg.style === undefined ? {} : arg.style
);

if (arg.position !== undefined) {
defaultStyle.position = arg.position;
}
m_this.style(defaultStyle);

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

this._init(arg);
Expand Down

0 comments on commit e694122

Please sign in to comment.