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

Update the jsdocs for the vector feature. #961

Merged
merged 3 commits into from
Nov 26, 2018
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
"build-website-examples": "node examples/build-website.js && webpack --config webpack-website-examples.config.js",
"build-tutorials": "node tutorials/build.js && webpack --config webpack-tutorials.config.js",
"build-website-tutorials": "node tutorials/build-website.js && webpack --config webpack-website-tutorials.config.js",
"lint": "eslint --cache .",
"lint": "eslint --cache . --max-warnings=0",
"puglint": "pug-lint src examples",
"test": "GEOJS_TEST_CASE=tests/test-unit.js karma start karma-cov.conf.js --single-run --browsers ChromeHeadlessTouch,FirefoxHeadlessTouch,PhantomJS",
"test-all": "GEOJS_TEST_CASE=tests/test-unit.js karma start karma-cov.conf.js --single-run --browsers ChromeHeadlessTouch,FirefoxHeadlessTouch,PhantomJS",
Expand Down
1 change: 0 additions & 1 deletion src/d3/graphFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ var graphFeature = require('../graphFeature');
* @class
* @alias geo.d3.graphFeature
* @extends geo.graphFeature
* @extends geo.d3.object
* @param {geo.graphFeature.spec} arg Feature options.
* @returns {geo.graphFeature}
*/
Expand Down
9 changes: 7 additions & 2 deletions src/d3/tileLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ var d3_tileLayer = function () {
m_this.draw();
};

/* Remove the tile feature. */
/**
* Remove the tile feature.
*
* @param {geo.tile} tile The tile to remove.
*/
this._remove = function (tile) {
if (tile.quadId !== undefined && m_quadFeature) {
for (var i = 0; i < m_tiles.length; i += 1) {
Expand All @@ -66,7 +70,8 @@ var d3_tileLayer = function () {
s_exit.apply(m_this, arguments);
};

/* Initialize the tile layer. This creates a series of sublayers so that
/**
* Initialize the tile layer. This creates a series of sublayers so that
* the different layers will stack in the proper order.
*/
this._init = function () {
Expand Down
132 changes: 80 additions & 52 deletions src/d3/vectorFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,67 @@ var inherit = require('../inherit');
var registerFeature = require('../registry').registerFeature;
var vectorFeature = require('../vectorFeature');

/* These markers are available to all instances of the vectorFeature. */
var markerConfigs = {
arrow: {
attrs: {
class: 'geo-vector-arrow geo-vector-marker',
viewBox: '0 0 10 10',
refX: 1,
refY: 5,
markerHeight: 5,
markerWidth: 5,
orient: 'auto'
},
path: 'M 0 0 L 10 5 L 0 10 z'
},
point: {
attrs: {
class: 'geo-vector-point geo-vector-marker',
viewBox: '0 0 12 12',
refX: 6,
refY: 6,
markerHeight: 8,
markerWidth: 8,
orient: 'auto'
},
path: 'M 6 3 A 3 3 0 1 1 5.99999 3 Z'
},
bar: {
attrs: {
class: 'geo-vector-bar geo-vector-marker',
viewBox: '0 0 10 10',
refX: 0,
refY: 5,
markerHeight: 6,
markerWidth: 6,
orient: 'auto'
},
path: 'M 0 0 L 2 0 L 2 10 L 0 10 z'
},
wedge: {
attrs: {
class: 'geo-vector-wedge geo-vector-marker',
viewBox: '0 0 10 10',
refX: 10,
refY: 5,
markerHeight: 5,
markerWidth: 5,
orient: 'auto'
},
path: 'M 0 0 L 1 0 L 10 5 L 1 10 L 0 10 L 9 5 L 0 0'
}
};

/**
* Create a new instance of vectorFeature
* Create a new instance of d3.vectorFeature.
*
* @class
* @alias geo.d3.vectorFeature
* @extends geo.vectorFeature
* @extends geo.d3.object
* @returns {geo.d3.vectorFeature}
* @param {geo.vectorFeature.spec} arg Feature options.
* @returns {geo.vectorFeature}
*/
var d3_vectorFeature = function (arg) {
'use strict';
Expand All @@ -29,54 +82,35 @@ var d3_vectorFeature = function (arg) {
* @private
*/
var m_this = this,
s_init = this._init,
s_exit = this._exit,
s_update = this._update,
m_buildTime = timestamp(),
m_style = {};

/**
* Generate a unique ID for a marker definition
* @private
* @param {object} d Unused datum (for d3 compat)
* @param {number} i The marker index
* @param {string} position The marker's vector position (head or tail)
* Generate a unique ID for a marker definition.
*
* @param {object} d The marker datum (unused).
* @param {number} i The marker index.
* @param {string} position The marker's vector position (`'head'` or
* `'tail'`).
* @returns {string} The constructed ID.
*/
function markerID(d, i, position) {
return m_this._d3id() + '_marker_' + i + '_' + position;
}

/**
* Add marker styles for vector arrows.
* @private
* @param {object[]} data The vector data array
* @param {function} stroke The stroke accessor
* @param {function} opacity The opacity accessor
* @param {function} originStyle The marker style for the vector head
* @param {function} endStyle The marker style for the vector tail
*
* @param {object[]} data The vector data array.
* @param {function} stroke The stroke accessor.
* @param {function} opacity The opacity accessor.
* @param {function} originStyle The marker style for the vector head.
* @param {function} endStyle The marker style for the vector tail.
*/
function updateMarkers(data, stroke, opacity, originStyle, endStyle) {

var markerConfigs = {
'arrow': {
attrs: {'class': 'geo-vector-arrow geo-vector-marker', 'viewBox': '0 0 10 10', 'refX': '1', 'refY': '5', 'markerHeight': '5', 'markerWidth': '5', 'orient': 'auto'},
path: 'M 0 0 L 10 5 L 0 10 z'
},
'point': {
attrs: {'class': 'geo-vector-point geo-vector-marker', 'viewBox': '0 0 12 12', 'refX': '6', 'refY': '6', 'markerHeight': '8', 'markerWidth': '8', 'orient': 'auto'},
path: 'M 6 3 A 3 3 0 1 1 5.99999 3 Z'
},
'bar': {
attrs: {'class': 'geo-vector-bar geo-vector-marker', 'viewBox': '0 0 10 10', 'refX': '0', 'refY': '5', 'markerHeight': '6', 'markerWidth': '6', 'orient': 'auto'},
path: 'M 0 0 L 2 0 L 2 10 L 0 10 z'
},
'wedge': {
attrs: {'class': 'geo-vector-wedge geo-vector-marker', 'viewBox': '0 0 10 10', 'refX': '10', 'refY': '5', 'markerHeight': '5', 'markerWidth': '5', 'orient': 'auto'},
path: 'M 0 0 L 1 0 L 10 5 L 1 10 L 0 10 L 9 5 L 0 0'
}
};

//this allows for multiple VectorFeatures in a layer
//this allows for multiple vectorFeature in a layer
var markerGroup = m_this.renderer()._definitions()
.selectAll('g.marker-group#' + m_this._d3id())
.data(data.length ? [1] : []);
Expand Down Expand Up @@ -148,17 +182,9 @@ var d3_vectorFeature = function (arg) {
}

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

/**
* Build
* @protected
* Build.
*
* @returns {this}.
*/
this._build = function () {
var data = m_this.data(),
Expand All @@ -168,7 +194,7 @@ var d3_vectorFeature = function (arg) {
size_func = m_this.delta(),
cache = [],
scale = m_this.style('scale'),
max = Number.NEGATIVE_INFINITY;
max = 0;

// call super-method
s_update.call(m_this);
Expand All @@ -191,7 +217,7 @@ var d3_vectorFeature = function (arg) {

max = Math.sqrt(max);
if (!scale) {
scale = 75 / max;
scale = 75 / (max ? max : 1);
}

function getScale() {
Expand Down Expand Up @@ -246,8 +272,9 @@ var d3_vectorFeature = function (arg) {
};

/**
* Update
* @protected
* Update.
*
* @returns {this}
*/
this._update = function () {
s_update.call(m_this);
Expand All @@ -268,8 +295,7 @@ var d3_vectorFeature = function (arg) {
};

/**
* Exit
* @protected
* Exit. Remove markers.
*/
this._exit = function () {
s_exit.call(m_this);
Expand All @@ -281,6 +307,8 @@ var d3_vectorFeature = function (arg) {
return this;
};

d3_vectorFeature.markerConfigs = markerConfigs;

inherit(d3_vectorFeature, vectorFeature);

// Now register it
Expand Down
2 changes: 1 addition & 1 deletion src/graphFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var feature = require('./feature');
* Object specification for a graph feature.
*
* @typedef {geo.feature.spec} geo.graphFeature.spec
* @property {geo.pointFeature.styleSpec} [style] Style object with default
* @property {geo.graphFeature.styleSpec} [style] Style object with default
* style options.
*/

Expand Down
5 changes: 3 additions & 2 deletions src/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ var rendererForAnnotations = require('./registry').rendererForAnnotations;
* @property {geo.map} [map=null] Parent map of the layer.
* @property {string|geo.renderer} [renderer] Renderer to associate with the
* layer. If not specified, either `annotations` or `features` can be used
* to determine the renderer. If a `geo.renderer` instance, the renderer is
* not recreated; not all renderers can be shared by multiple layers.
* to determine the renderer. If a {@link geo.renderer} instance, the
* renderer is not recreated; not all renderers can be shared by multiple
* layers.
* @property {HTMLElement} [canvas] If specified, use this canvas rather than
* a canvas associaied with the renderer directly. Renderers may not support
* sharing a canvas.
Expand Down
72 changes: 58 additions & 14 deletions src/vectorFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,46 @@ var inherit = require('./inherit');
var feature = require('./feature');

/**
* Create a new instance of class vectorFeature
* Object specification for a graph feature.
*
* @typedef {geo.feature.spec} geo.vectorFeature.spec
* @property {geo.vectorFeature.styleSpec} [style] Style object with default
* style options.
* @property {function|object} [origin={x: 0, y: 0, z: 0}] Origin accessor.
*/

/**
* Style specification for a vector feature.
*
* @typedef {geo.feature.styleSpec} geo.vectorFeature.styleSpec
* @extends geo.feature.styleSpec
* @property {geo.geoColor|function} [strokeColor] Color to stroke each vector.
* @property {number|function} [strokeOpacity] Opacity for each vector.
* Opacity is on a [0-1] scale.
* @property {number|function} [strokeWidth] The weight of the vector stroke in
* pixels.
* @property {string|function} [originStyle='none'] The style at the origin of
* the vector. One of the marker styles or `'none'`. Marker styles are
* usually `'arrow'`, `'point'`, `'bar'`, and `'wedge'`.
* @property {string|function} [endStyle='arrow'] The style at the far end of
* the vector. One of the marker styles or `'none'`. Marker styles are
* usually `'arrow'`, `'point'`, `'bar'`, and `'wedge'`.
* @property {geo.geoPosition|function} [origin={x: 0, y: 0, z: 0}] The origin
* of the vector. One end of the vector will be at this point.
* @property {geo.geoPosition|function} [delta] The direction that the vector
* points in. The length of the vector is dependant on this and the `scale`.
* @property {number|function} [scale] The size of the vector relative to the
* delta. If `null`, `undefined`, or `0`, this is `75 / <maximum length of
* any delta in x-y space>`.
*/

/**
* Create a new instance of class vectorFeature.
*
* @class
* @alias geo.vectorFeature
* @extends geo.feature
* @param {geo.vectorFeature.spec} arg Feature options.
* @returns {geo.vectorFeature}
*/
var vectorFeature = function (arg) {
Expand All @@ -24,45 +59,53 @@ var vectorFeature = function (arg) {
* @private
*/
var m_this = this,
s_init = this._init,
s_style = this.style;
s_init = this._init;

this.featureType = 'vector';

/**
* Get or set the accessor for the origin of the vector. This is the point
* that the vector base resides at. Defaults to (0, 0, 0).
* @param {geo.accessor|geo.geoPosition} [accessor] The origin accessor
* that the vector starts.
*
* @param {geo.geoPosition|function} [val] The new origin if specified. If
* not specified, return the current origin.
* @returns {geo.geoPosition|function|this} Either the current origin or
* this feature.
*/
this.origin = function (val) {
if (val === undefined) {
return s_style('origin');
return m_this.style('origin');
} else {
s_style('origin', val);
m_this.style('origin', val);
m_this.dataTime().modified();
m_this.modified();
}
return m_this;
};

/**
* Get or set the accessor for the displacement (coordinates) of the vector.
* @param {geo.accessor|geo.geoPosition} [accessor] The accessor
* This is the direction of the vector.
*
* @param {geo.geoPosition|function} [val] The new delta if specified. If
* not specified, return the current delta.
* @returns {geo.geoPosition|function|this} Either the current delta or this
* feature.
*/
this.delta = function (val) {
if (val === undefined) {
return s_style('delta');
return m_this.style('delta');
} else {
s_style('delta', val);
m_this.style('delta', val);
m_this.dataTime().modified();
m_this.modified();
}
return m_this;
};

/**
* Initialize
* @protected
* Initialize.
*
* @param {geo.vectorFeature.spec} arg The feature specification.
* @returns {this}
*/
this._init = function (arg) {
s_init.call(m_this, arg);
Expand All @@ -88,6 +131,7 @@ var vectorFeature = function (arg) {

m_this.style(defaultStyle);
m_this.dataTime().modified();
return m_this;
};
};

Expand Down