Skip to content

Commit

Permalink
Merge branch 'master' into distance-functions
Browse files Browse the repository at this point in the history
  • Loading branch information
manthey authored Mar 21, 2018
2 parents c30916a + 63f796b commit c5f6ce3
Show file tree
Hide file tree
Showing 14 changed files with 461 additions and 187 deletions.
1 change: 0 additions & 1 deletion src/d3/d3Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ var d3Renderer = function (arg) {

/**
* Set the translation, scale, and zoom for the current view.
* @note rotation not yet supported
* @private
*/
this._setTransform = function () {
Expand Down
10 changes: 6 additions & 4 deletions src/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ var sceneObject = require('./sceneObject');
* @param {number} [arg.maxBounds.right=20037508] The right bound.
* @param {number} [arg.maxBounds.bottom=-20037508] The bottom bound.
* @param {number} [arg.maxBounds.top=20037508] The top bound.
* @param {number} [arg.maxBounds.gcs=arg.ingcs] The coordinate system for the
* bounds.
*
* @param {number} [arg.zoom=4] Initial zoom.
* @param {object?} [arg.center] Initial map center.
Expand Down Expand Up @@ -128,17 +130,17 @@ var map = function (arg) {
* [0, width] and [0, height] instead. */
var mcx = ((m_maxBounds.left || 0) + (m_maxBounds.right || 0)) / 2,
mcy = ((m_maxBounds.bottom || 0) + (m_maxBounds.top || 0)) / 2;
m_maxBounds.left = transform.transformCoordinates(m_ingcs, m_gcs, {
m_maxBounds.left = transform.transformCoordinates(m_maxBounds.gcs || m_ingcs, m_gcs, {
x: m_maxBounds.left !== undefined ? m_maxBounds.left : -180, y: mcy
}).x;
m_maxBounds.right = transform.transformCoordinates(m_ingcs, m_gcs, {
m_maxBounds.right = transform.transformCoordinates(m_maxBounds.gcs || m_ingcs, m_gcs, {
x: m_maxBounds.right !== undefined ? m_maxBounds.right : 180, y: mcy
}).x;
m_maxBounds.top = (m_maxBounds.top !== undefined ?
transform.transformCoordinates(m_ingcs, m_gcs, {
transform.transformCoordinates(m_maxBounds.gcs || m_ingcs, m_gcs, {
x: mcx, y: m_maxBounds.top}).y : m_maxBounds.right);
m_maxBounds.bottom = (m_maxBounds.bottom !== undefined ?
transform.transformCoordinates(m_ingcs, m_gcs, {
transform.transformCoordinates(m_maxBounds.gcs || m_ingcs, m_gcs, {
x: mcx, y: m_maxBounds.bottom}).y : m_maxBounds.left);
m_unitsPerPixel = (arg.unitsPerPixel || (
m_maxBounds.right - m_maxBounds.left) / 256);
Expand Down
19 changes: 16 additions & 3 deletions src/ui/domWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@ var widget = require('./widget');
var inherit = require('../inherit');
var registerWidget = require('../registry').registerWidget;

/**
* Create a new instance of class domWidget.
*
* @class
* @alias geo.gui.domWidget
* @extends geo.gui.widget
* @param {object} arg
* @param {geo.widget} [parent] A parent widget for this widget.
* @param {string} [el='div'] The type of DOM element to create.
* @returns {geo.domWidget}
*/
var domWidget = function (arg) {
'use strict';
if (!(this instanceof domWidget)) {
Expand All @@ -17,25 +28,27 @@ var domWidget = function (arg) {
* Initializes DOM Widget.
* Sets the canvas for the widget, does parent/child relationship management,
* appends it to it's parent and handles any positioning logic.
*
* @returns {this}
*/
this._init = function () {
if (arg.hasOwnProperty('parent')) {
arg.parent.addChild(m_this);
}

m_this._createCanvas();
m_this._appendChild();
m_this._appendCanvasToParent();

m_this.canvas().addEventListener('mousedown', function (e) {
e.stopPropagation();
});

m_this.reposition();
return m_this;
};

/**
* Creates the widget canvas.
* This is just a simple DOM element (based on args.el, or defaults to a div)
* Creates the widget canvas. This is a DOM element (`arg.el` or a div).
*/
this._createCanvas = function () {
m_this.canvas(document.createElement(arg.el || m_default_canvas));
Expand Down
8 changes: 3 additions & 5 deletions src/ui/legendWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ var legendWidget = function (arg) {
m_group = null,
m_border = null,
m_spacing = 20, // distance in pixels between lines
m_padding = 12, // padding in pixels inside the border
s_createCanvas = this._createCanvas,
s_appendChild = this._appendChild;
m_padding = 12; // padding in pixels inside the border

/**
* Get or set the category array associated with
Expand Down Expand Up @@ -212,8 +210,8 @@ var legendWidget = function (arg) {
// adding categories redraws the entire thing by calling _init, see
// the m_top.remove() line below
if (!m_top) {
s_createCanvas();
s_appendChild();
m_this._createCanvas();
m_this._appendCanvasToParent();
}

// total size = interior size + 2 * padding + 2 * width of the border
Expand Down
6 changes: 2 additions & 4 deletions src/ui/sliderWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ var sliderWidget = function (arg) {

var m_this = this,
s_exit = this._exit,
s_createCanvas = this._createCanvas,
s_appendChild = this._appendChild,
m_xscale,
m_yscale,
m_plus,
Expand Down Expand Up @@ -91,8 +89,8 @@ var sliderWidget = function (arg) {
* @private
*/
this._init = function () {
s_createCanvas();
s_appendChild();
m_this._createCanvas();
m_this._appendCanvasToParent();

m_this.reposition();

Expand Down
49 changes: 35 additions & 14 deletions src/ui/svgWidget.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,45 @@
var domWidget = require('./domWidget');
var widget = require('./widget');
var inherit = require('../inherit');
var registerWidget = require('../registry').registerWidget;

/**
* Create a new instance of class geo.gui.svgWidget
* Create a new instance of class geo.gui.svgWidget.
*
* Due to the nature of d3 creating DOM elements as it inserts them, calls to appendChild
* don't appear in this widget.
* Due to the nature of d3 creating DOM elements as it inserts them, calls to
* appendChild don't appear in this widget.
*
* The canvas of an svgWidget always refers to the actual svg element.
* The parentCanvas can refer to another widgets svg element, dom element, or the
* UI layers dom element.
* The parentCanvas can refer to another widget's svg element, dom element, or
* the UI layer's dom element.
* See {@link geo.gui.widget#parentCanvas}.
*
* @class geo.gui.svgWidget
* @extends geo.gui.domWidget
* @class
* @alias geo.gui.svgWidget
* @extends geo.gui.widget
* @param {object} arg
* @param {geo.widget} [parent] A parent widget for this widget.
* @returns {geo.gui.svgWidget}
*
*/
var svgWidget = function (arg) {
'use strict';
if (!(this instanceof svgWidget)) {
return new svgWidget(arg);
}

domWidget.call(this, arg);
widget.call(this, arg);

var d3Renderer = require('../d3/d3Renderer');

var m_this = this,
s_exit = this._exit,
m_renderer = null;

this._init = function (arg) {
/**
* Initializes SVG Widget.
*
* @returns {this}
*/
this._init = function () {
var d3Parent;
if (arg.hasOwnProperty('parent')) {
arg.parent.addChild(m_this);
Expand All @@ -47,12 +55,25 @@ var svgWidget = function (arg) {
});

m_this.reposition();
return m_this;
};

/**
* Clean up the widget.
*/
this._exit = function () {
if (m_renderer) {
m_renderer._exit();
}
s_exit();
};

/**
* Creates the canvas for the svg widget.
* This directly uses the {@link geo.d3.d3Renderer} as a helper to do all of the heavy
* lifting.
* This directly uses the {@link geo.d3.d3Renderer} as a helper to do all of
* the heavy lifting.
*
* @param {d3Selector} d3Parent The canvas's parent element.
*/
this._createCanvas = function (d3Parent) {
var rendererOpts = {
Expand All @@ -75,7 +96,7 @@ var svgWidget = function (arg) {
return this;
};

inherit(svgWidget, domWidget);
inherit(svgWidget, widget);

registerWidget('dom', 'svg', svgWidget);
module.exports = svgWidget;
Loading

0 comments on commit c5f6ce3

Please sign in to comment.