More flexible default position accessors.
Before, most position accessors have assumed the data contains an object
with `x` and `y` and, optionally, `z`.  Now, for lines, points,
polygons, text, meshes, and paths, the default position accessor will
also handle a data entry that is an array that is either 2 or 3 numbers.
MODIFY
src/lineFeature.js
src/lineFeature.js
@@ -465,7 +465,7 @@ var lineFeature = function (arg) {
antialiasing: 2.0,
closed: false,
line: function (d) { return d; },
- position: function (d) { return d; },
+ position: (d) => Array.isArray(d) ? {x: d[0], y: d[1], z: d[2] || 0} : d,
origin: (p) => (p.length >= 3 ? p.slice(0, 3) : [0, 0, 0])
},
arg.style === undefined ? {} : arg.style

MODIFY
src/meshFeature.js
src/meshFeature.js
@@ -455,12 +455,7 @@ var meshFeature = function (arg) {
/* Initialize from arguments */
arg = arg || {};
var style = $.extend({}, {
- position: function (d) {
- /* We could construct a new object and return
- * {x: d.x, y: d.y, z: d.z};
- * but that isn't necessary. */
- return d;
- }
+ position: (d) => Array.isArray(d) ? {x: d[0], y: d[1], z: d[2] || 0} : d
}, arg.style || {});
m_this.mesh(arg.mesh || {});

MODIFY
src/pathFeature.js
src/pathFeature.js
@@ -84,7 +84,7 @@ var pathFeature = function (arg) {
{
strokeWidth: 1,
strokeColor: {r: 1.0, g: 1.0, b: 1.0},
- position: function (d) { return d; }
+ position: (d) => Array.isArray(d) ? {x: d[0], y: d[1], z: d[2] || 0} : d
},
arg.style === undefined ? {} : arg.style
);

MODIFY
src/pointFeature.js
src/pointFeature.js
@@ -503,7 +503,7 @@ var pointFeature = function (arg) {
fillColor: { r: 1.0, g: 0.839, b: 0.439 },
fill: true,
fillOpacity: 0.8,
- position: function (d) { return d; },
+ position: (d) => Array.isArray(d) ? {x: d[0], y: d[1], z: d[2] || 0} : d,
origin: (p) => (p.length >= 3 ? p.slice(0, 3) : [0, 0, 0])
},
arg.style === undefined ? {} : arg.style

MODIFY
src/polygonFeature.js
src/polygonFeature.js
@@ -128,11 +128,8 @@ var polygonFeature = function (arg) {
outer = new Array(coord.length);
for (j = 0; j < coord.length; j += 1) {
outer[j] = posFunc.call(m_this, coord[j], j, d, i);
- x = outer[j].x || outer[j][0] || 0;
- y = outer[j].y || outer[j][1] || 0;
- if (outer[j].x === undefined) {
- outer[j] = {x: x, y: y};
- }
+ x = outer[j].x;
+ y = outer[j].y;
if (!j) {
range = {min: {x: x, y: y}, max: {x: x, y: y}};
} else {
@@ -147,9 +144,6 @@ var polygonFeature = function (arg) {
var trans = new Array(coord.length);
for (j = 0; j < coord.length; j += 1) {
trans[j] = posFunc.call(m_this, coord[j], j, d, i);
- if (trans[j].x === undefined) {
- trans[j] = {x: trans[j].x || trans[j][0] || 0, y: trans[j].y || trans[j][1] || 0};
- }
}
return trans;
});
@@ -725,7 +719,7 @@ var polygonFeature = function (arg) {
strokeColor: {r: 0.0, g: 1.0, b: 1.0},
strokeOpacity: 1.0,
polygon: function (d) { return d; },
- position: function (d) { return d; },
+ position: (d) => Array.isArray(d) ? {x: d[0], y: d[1], z: d[2] || 0} : d,
origin: (items) => {
for (let i = 0; i < items.length; i += 1) {
if (items[i].vertices.length >= 3) {

MODIFY
src/textFeature.js
src/textFeature.js
@@ -158,7 +158,7 @@ var textFeature = function (arg) {
rotation: 0, /* in radians */
rotateWithMap: false,
textScaled: false,
- position: function (d) { return d; },
+ position: (d) => Array.isArray(d) ? {x: d[0], y: d[1], z: d[2] || 0} : d,
text: function (d) { return d.text; }
},
arg.style === undefined ? {} : arg.style

More flexible default position accessors.

Before, most position accessors have assumed the data contains an object
with `x` and `y` and, optionally, `z`.  Now, for lines, points,
polygons, text, meshes, and paths, the default position accessor will
also handle a data entry that is an array that is either 2 or 3 numbers.