geojs 1.8.7 → 1.8.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "geojs",
3
- "version": "1.8.7",
3
+ "version": "1.8.10",
4
4
  "description": "JavaScript Geo Visualization and Analysis Library",
5
5
  "homepage": "https://github.com/OpenGeoscience/geojs",
6
6
  "license": "Apache-2.0",
@@ -55,6 +55,7 @@ var geojsonReader = function (arg) {
55
55
  strokeOffset: 0,
56
56
  lineCap: 'butt',
57
57
  lineJoin: 'miter',
58
+ uniformLine: true,
58
59
  closed: false,
59
60
  ...arg.lineStyle
60
61
  },
@@ -66,6 +67,7 @@ var geojsonReader = function (arg) {
66
67
  strokeColor: '#999999',
67
68
  strokeWidth: 2,
68
69
  strokeOpacity: 1,
70
+ uniformPolygon: true,
69
71
  ...arg.polygonStyle
70
72
  }
71
73
  };
@@ -80,7 +80,7 @@ var graphFeature = function (arg) {
80
80
  arg.style === undefined ? {} : arg.style);
81
81
 
82
82
  m_this.style(defaultStyle);
83
- m_this.nodes(function (d) { return d; });
83
+ m_this.nodes(util.identityFunction);
84
84
  return m_this;
85
85
  };
86
86
 
@@ -2,6 +2,7 @@ var $ = require('jquery');
2
2
  var inherit = require('./inherit');
3
3
  var feature = require('./feature');
4
4
  var transform = require('./transform');
5
+ var util = require('./util');
5
6
 
6
7
  /**
7
8
  * Heatmap feature specification.
@@ -79,7 +80,7 @@ var heatmapFeature = function (arg) {
79
80
 
80
81
  this.featureType = 'heatmap';
81
82
 
82
- m_position = arg.position || function (d) { return d; };
83
+ m_position = arg.position || util.identityFunction;
83
84
  m_intensity = arg.intensity || function (d) { return 1; };
84
85
  m_maxIntensity = arg.maxIntensity !== undefined ? arg.maxIntensity : null;
85
86
  m_minIntensity = arg.minIntensity !== undefined ? arg.minIntensity : null;
@@ -46,6 +46,9 @@ var util = require('./util');
46
46
  * divided by the sine of half the angle between segments, then a bevel join
47
47
  * is used instead. This is a single value that applies to all lines. If a
48
48
  * function, it is called with `(data)`.
49
+ * @property {boolean|function} [uniformLine=false] Boolean indicating if each
50
+ * line has a uniform style (uniform stroke color, opacity, and width). Can
51
+ * vary by line.
49
52
  * @property {number|function} [antialiasing] Antialiasing distance in pixels.
50
53
  * Values must be non-negative. A value greater than 1 will produce a
51
54
  * visible gradient. This is a single value that applies to all lines.
@@ -157,18 +160,30 @@ var lineFeature = function (arg) {
157
160
  var data = m_this.data(),
158
161
  line = m_this.line(),
159
162
  widthFunc = m_this.style.get('strokeWidth'),
163
+ widthVal = util.isFunction(m_this.style('strokeWidth')) ? undefined : widthFunc(),
160
164
  posFunc = m_this.position(),
161
165
  closedFunc = m_this.style.get('closed'),
166
+ closedVal = util.isFunction(m_this.style('closed')) ? undefined : closedFunc(),
167
+ uniformFunc = m_this.style.get('uniformLine'),
168
+ uniformVal = util.isFunction(m_this.style('uniformLine')) ? undefined : uniformFunc(),
162
169
  gcs = m_this.gcs(),
163
- mapgcs = m_this.layer().map().gcs();
170
+ mapgcs = m_this.layer().map().gcs(),
171
+ onlyInvertedY = transform.onlyInvertedY(gcs, mapgcs);
164
172
 
165
- data.forEach(function (d, index) {
166
- var closed = closedFunc(d, index),
167
- last, lasti, lastr, lastr2, first, record = [], min, max;
173
+ for (let index = 0; index < data.length; index += 1) {
174
+ const d = data[index];
175
+ const closed = closedVal === undefined ? closedFunc(d, index) : closedVal;
176
+ let last, lasti, lastr, lastr2, first, min, max, width;
177
+ const record = [];
178
+ const uniform = uniformVal === undefined ? uniformFunc(d, index) : uniformVal;
168
179
 
169
- line(d, index).forEach(function (current, j) {
170
- var p = posFunc(current, j, d, index);
171
- if (gcs !== mapgcs) {
180
+ const lineRecord = line(d, index);
181
+ for (let j = 0; j < lineRecord.length; j += 1) {
182
+ const current = lineRecord[j];
183
+ let p = posFunc(current, j, d, index);
184
+ if (onlyInvertedY) {
185
+ p.y = -p.y;
186
+ } else if (gcs !== mapgcs) {
172
187
  p = transform.transformCoordinates(gcs, mapgcs, p);
173
188
  }
174
189
  if (min === undefined) { min = {x: p.x, y: p.y}; }
@@ -177,9 +192,12 @@ var lineFeature = function (arg) {
177
192
  if (p.x > max.x) { max.x = p.x; }
178
193
  if (p.y < min.y) { min.y = p.y; }
179
194
  if (p.y > max.y) { max.y = p.y; }
180
- var r = Math.ceil(widthFunc(current, j, d, index) / 2) + 2;
195
+ if (!uniform || !j) {
196
+ width = widthVal === undefined ? widthFunc(current, j, d, index) : widthVal;
197
+ }
198
+ const r = Math.ceil(width / 2) + 2;
181
199
  if (max.r === undefined || r > max.r) { max.r = r; }
182
- var r2 = r * r;
200
+ const r2 = r * r;
183
201
  if (last) {
184
202
  record.push({u: p, v: last, r: lastr > r ? lastr : r, r2: lastr2 > r2 ? lastr2 : r2, i: j, j: lasti});
185
203
  }
@@ -190,14 +208,14 @@ var lineFeature = function (arg) {
190
208
  if (!first && closed) {
191
209
  first = {p: p, r: r, r2: r2, i: j};
192
210
  }
193
- });
211
+ }
194
212
  if (closed && first && (last.x !== first.p.x || last.y !== first.p.y)) {
195
213
  record.push({u: last, v: first.p, r: lastr > first.r ? lastr : first.r, r2: lastr2 > first.r2 ? lastr2 : first.r2, i: lasti, j: first.i});
196
214
  }
197
215
  record.min = min;
198
216
  record.max = max;
199
217
  m_pointSearchInfo.push(record);
200
- });
218
+ }
201
219
  return m_pointSearchInfo;
202
220
  };
203
221
 
@@ -438,8 +456,8 @@ var lineFeature = function (arg) {
438
456
  });
439
457
 
440
458
  /* Set the reduced lines as the data and use simple accessors. */
441
- m_this.style('position', function (d) { return d; });
442
- m_this.style('line', function (d) { return d; });
459
+ m_this.style('position', util.identityFunction);
460
+ m_this.style('line', util.identityFunction);
443
461
  m_this.data(data);
444
462
  return m_this;
445
463
  };
@@ -465,7 +483,7 @@ var lineFeature = function (arg) {
465
483
  // Values of 2 and above appear smoothest.
466
484
  antialiasing: 2.0,
467
485
  closed: false,
468
- line: function (d) { return d; },
486
+ line: util.identityFunction,
469
487
  position: (d) => Array.isArray(d) ? {x: d[0], y: d[1], z: d[2] || 0} : d,
470
488
  origin: (p) => (p.length >= 3 ? p.slice(0, 3) : [0, 0, 0])
471
489
  },
@@ -285,7 +285,7 @@ var pixelmapFeature = function (arg) {
285
285
  a: 1
286
286
  };
287
287
  },
288
- position: function (d) { return d; }
288
+ position: util.identityFunction
289
289
  },
290
290
  arg.style === undefined ? {} : arg.style
291
291
  );
@@ -495,7 +495,8 @@ var polygonFeature = function (arg) {
495
495
  strokeStyle: linePolyStyle(polyStyle.strokeStyle),
496
496
  strokeColor: linePolyStyle(polyStyle.strokeColor),
497
497
  strokeOffset: linePolyStyle(polyStyle.strokeOffset),
498
- strokeOpacity: strokeOpacity
498
+ strokeOpacity: strokeOpacity,
499
+ uniformLine: linePolyStyle(polyStyle.uniformPolygon)
499
500
  });
500
501
  var data = m_this.data(),
501
502
  posVal = m_this.style('position');
@@ -634,8 +635,8 @@ var polygonFeature = function (arg) {
634
635
  });
635
636
 
636
637
  /* Set the reduced polgons as the data and use simple accessors. */
637
- m_this.style('position', function (d) { return d; });
638
- m_this.style('polygon', function (d) { return d; });
638
+ m_this.style('position', util.identityFunction);
639
+ m_this.style('polygon', util.identityFunction);
639
640
  m_this.data(data);
640
641
  return m_this;
641
642
  };
@@ -719,7 +720,7 @@ var polygonFeature = function (arg) {
719
720
  strokeStyle: 'solid',
720
721
  strokeColor: {r: 0.0, g: 1.0, b: 1.0},
721
722
  strokeOpacity: 1.0,
722
- polygon: function (d) { return d; },
723
+ polygon: util.identityFunction,
723
724
  position: (d) => Array.isArray(d) ? {x: d[0], y: d[1], z: d[2] || 0} : d,
724
725
  origin: (items) => {
725
726
  for (let i = 0; i < items.length; i += 1) {
@@ -699,7 +699,7 @@ var quadFeature = function (arg) {
699
699
  previewImage: null,
700
700
  image: function (d) { return d.image; },
701
701
  video: function (d) { return d.video; },
702
- position: function (d) { return d; }
702
+ position: util.identityFunction
703
703
  },
704
704
  arg.style === undefined ? {} : arg.style
705
705
  );
@@ -814,8 +814,8 @@ var trackFeature = function (arg) {
814
814
  true,
815
815
  {},
816
816
  {
817
- track: (d) => d,
818
- position: (d) => d,
817
+ track: util.identityFunction,
818
+ position: util.identityFunction,
819
819
  time: (d, i) => (d.t !== undefined ? d.t : i)
820
820
  },
821
821
  arg.style === undefined ? {} : arg.style
package/src/transform.js CHANGED
@@ -19,7 +19,7 @@ var maxTransformCacheSize = 10;
19
19
 
20
20
  /* A RegExp to detect if two transforms only different by the middle axis's
21
21
  * direction. */
22
- var axisPattern = /^(.* |)\\+axis=e(n|s)u(| .*)$/;
22
+ var axisPattern = /^(.* |)\+axis=e(n|s)u(| .*)$/;
23
23
  var affinePattern = /(^|\s)\+(s[1-3][1-3]|[xyz]off)=\S/;
24
24
 
25
25
  /**
@@ -1443,6 +1443,17 @@ var util = {
1443
1443
  return value !== null && value !== undefined && (type === 'object' || type === 'function');
1444
1444
  },
1445
1445
 
1446
+ /**
1447
+ * Return the first value passed to the function. Using this function for
1448
+ * identity calls can allow some code to bypass making such a call entirely.
1449
+ *
1450
+ * @param {*} d Any value.
1451
+ * @returns {*} The passed value.
1452
+ */
1453
+ identityFunction: function (d) {
1454
+ return d;
1455
+ },
1456
+
1446
1457
  ///////////////////////////////////////////////////////////////////////////
1447
1458
  /*
1448
1459
  * Utility member properties.
@@ -1,5 +1,6 @@
1
1
  var inherit = require('./inherit');
2
2
  var feature = require('./feature');
3
+ var util = require('./util');
3
4
 
4
5
  /**
5
6
  * Object specification for a graph feature.
@@ -120,7 +121,7 @@ var vectorFeature = function (arg) {
120
121
  originStyle: 'none',
121
122
  endStyle: 'arrow',
122
123
  origin: {x: 0, y: 0, z: 0},
123
- delta: function (d) { return d; },
124
+ delta: util.identityFunction,
124
125
  scale: null // size scaling factor (null -> renderer decides)
125
126
  },
126
127
  arg.style === undefined ? {} : arg.style
@@ -136,7 +136,6 @@ var webgl_lineFeature = function (arg) {
136
136
  v = vert[1],
137
137
  target_gcs = m_this.gcs(),
138
138
  map_gcs = m_this.layer().map().gcs(),
139
- simpleInverse = transform.onlyInvertedY(target_gcs, map_gcs),
140
139
  pos, posIdx3, firstpos, firstPosIdx3,
141
140
  lineFunc = m_this.line(),
142
141
  strokeWidthFunc = m_this.style.get('strokeWidth'), strokeWidthVal,
@@ -147,6 +146,7 @@ var webgl_lineFeature = function (arg) {
147
146
  strokeOffsetFunc = m_this.style.get('strokeOffset'), strokeOffsetVal,
148
147
  miterLimit = m_this.style.get('miterLimit')(data),
149
148
  antialiasing = m_this.style.get('antialiasing')(data) || 0,
149
+ uniformFunc = m_this.style.get('uniformLine'), uniformVal, uniform,
150
150
  order = m_this.featureVertices(), orderk0, prevkey, nextkey, offkey,
151
151
  orderLen = order.length,
152
152
  // webgl buffers; see _init for details
@@ -165,6 +165,7 @@ var webgl_lineFeature = function (arg) {
165
165
  strokeOffsetVal = util.isFunction(m_this.style('strokeOffset')) ? undefined : (strokeOffsetFunc() || 0);
166
166
  strokeOpacityVal = util.isFunction(m_this.style('strokeOpacity')) ? undefined : strokeOpacityFunc();
167
167
  strokeWidthVal = util.isFunction(m_this.style('strokeWidth')) ? undefined : strokeWidthFunc();
168
+ uniformVal = util.isFunction(m_this.style('uniformLine')) ? undefined : uniformFunc();
168
169
 
169
170
  if (miterLimit !== undefined) {
170
171
  /* We impose a limit no matter what, since otherwise the growth is
@@ -178,6 +179,7 @@ var webgl_lineFeature = function (arg) {
178
179
  if (!onlyStyle) {
179
180
  var position = [],
180
181
  posFunc = m_this.position();
182
+ posFunc = posFunc === util.identityFunction ? null : posFunc;
181
183
  lineItemList = new Array(data.length);
182
184
  closed = new Array(data.length);
183
185
  for (i = 0; i < data.length; i += 1) {
@@ -189,9 +191,9 @@ var webgl_lineFeature = function (arg) {
189
191
  }
190
192
  numSegments += lineItem.length - 1;
191
193
  for (j = 0; j < lineItem.length; j += 1) {
192
- pos = posFunc(lineItem[j], j, d, i);
194
+ pos = posFunc ? posFunc(lineItem[j], j, d, i) : lineItem[j];
193
195
  position.push(pos.x);
194
- position.push(simpleInverse ? -pos.y : pos.y);
196
+ position.push(pos.y);
195
197
  position.push(pos.z || 0.0);
196
198
  if (!j) {
197
199
  firstpos = pos;
@@ -211,9 +213,7 @@ var webgl_lineFeature = function (arg) {
211
213
  }
212
214
  }
213
215
 
214
- if (!simpleInverse) {
215
- position = transform.transformCoordinates(target_gcs, map_gcs, position, 3);
216
- }
216
+ position = transform.transformCoordinates(target_gcs, map_gcs, position, 3);
217
217
  m_origin = new Float32Array(m_this.style.get('origin')(position));
218
218
  if (m_origin[0] || m_origin[1] || m_origin[2]) {
219
219
  for (i = 0; i < position.length; i += 3) {
@@ -264,6 +264,7 @@ var webgl_lineFeature = function (arg) {
264
264
  if (lineItem.length < 2) {
265
265
  continue;
266
266
  }
267
+ uniform = uniformVal === undefined ? uniformFunc(lineItem, i) : uniformVal;
267
268
  d = data[i];
268
269
  closedVal = closed[i];
269
270
  firstPosIdx3 = posIdx3;
@@ -290,12 +291,26 @@ var webgl_lineFeature = function (arg) {
290
291
  (j !== lidx ? firstPosIdx3 + 3 : firstPosIdx3 + 6 - closedVal * 3) :
291
292
  posIdx3);
292
293
  }
293
- v.strokeWidth = strokeWidthVal === undefined ? strokeWidthFunc(lineItemData, lidx, d, i) : strokeWidthVal;
294
- v.strokeColor = strokeColorVal === undefined ? strokeColorFunc(lineItemData, lidx, d, i) : strokeColorVal;
295
- v.strokeOpacity = strokeOpacityVal === undefined ? strokeOpacityFunc(lineItemData, lidx, d, i) : strokeOpacityVal;
294
+ if (uniform && j > 0) {
295
+ if (j === 1) {
296
+ v.strokeWidth = vert[0].strokeWidth;
297
+ v.strokeColor = vert[0].strokeColor;
298
+ v.strokeOpacity = vert[0].strokeOpacity;
299
+ }
300
+ } else {
301
+ v.strokeWidth = strokeWidthVal === undefined ? strokeWidthFunc(lineItemData, lidx, d, i) : strokeWidthVal;
302
+ v.strokeColor = strokeColorVal === undefined ? strokeColorFunc(lineItemData, lidx, d, i) : strokeColorVal;
303
+ v.strokeOpacity = strokeOpacityVal === undefined ? strokeOpacityFunc(lineItemData, lidx, d, i) : strokeOpacityVal;
304
+ }
296
305
  if (updateFlags) {
297
306
  if (strokeOffsetVal !== 0) {
298
- v.strokeOffset = (strokeOffsetVal === undefined ? strokeOffsetFunc(lineItemData, lidx, d, i) : strokeOffsetVal) || 0;
307
+ if (uniform && j > 0) {
308
+ if (j === 1) {
309
+ v.strokeOffset = vert[0].strokeOffset;
310
+ }
311
+ } else {
312
+ v.strokeOffset = (strokeOffsetVal === undefined ? strokeOffsetFunc(lineItemData, lidx, d, i) : strokeOffsetVal) || 0;
313
+ }
299
314
  if (v.strokeOffset) {
300
315
  /* we use 11 bits to store the offset, and we want to store values
301
316
  * from -1 to 1, so multiply our values by 1023, and use some bit
@@ -77,12 +77,11 @@ var webgl_polygonFeature = function (arg) {
77
77
  fillColor, fillColorFunc, fillColorVal,
78
78
  fillOpacity, fillOpacityFunc, fillOpacityVal,
79
79
  fillFunc, fillVal,
80
- uniformPolyFunc, uniform,
80
+ uniformFunc, uniformVal, uniform,
81
81
  indices,
82
82
  items = [],
83
83
  target_gcs = m_this.gcs(),
84
84
  map_gcs = m_this.layer().map().gcs(),
85
- simpleInverse = transform.onlyInvertedY(target_gcs, map_gcs),
86
85
  numPts = 0,
87
86
  geom = m_mapper.geometryData(),
88
87
  color, opacity, fill, d, d3, vertices, i, j, k, n,
@@ -94,15 +93,18 @@ var webgl_polygonFeature = function (arg) {
94
93
  fillOpacityVal = util.isFunction(m_this.style('fillOpacity')) ? undefined : fillOpacityFunc();
95
94
  fillFunc = m_this.style.get('fill');
96
95
  fillVal = util.isFunction(m_this.style('fill')) ? undefined : fillFunc();
97
- uniformPolyFunc = m_this.style.get('uniformPolygon');
96
+ uniformFunc = m_this.style.get('uniformPolygon');
97
+ uniformVal = util.isFunction(m_this.style('uniformPolygon')) ? undefined : uniformFunc();
98
98
 
99
99
  if (!onlyStyle) {
100
100
  posFunc = m_this.style.get('position');
101
+ posFunc = posFunc === util.identityFunction ? null : posFunc;
101
102
  polyFunc = m_this.style.get('polygon');
103
+ polyFunc = polyFunc === util.identityFunction ? null : polyFunc;
102
104
  m_this.data().forEach(function (item, itemIndex) {
103
105
  var polygon, outer, geometry, c;
104
106
 
105
- polygon = polyFunc(item, itemIndex);
107
+ polygon = polyFunc ? polyFunc(item, itemIndex) : item;
106
108
  if (!polygon) {
107
109
  return;
108
110
  }
@@ -116,9 +118,9 @@ var webgl_polygonFeature = function (arg) {
116
118
  * test). */
117
119
  geometry = new Array(outer.length * 3);
118
120
  for (i = d3 = 0; i < outer.length; i += 1, d3 += 3) {
119
- c = posFunc(outer[i], i, item, itemIndex);
121
+ c = posFunc ? posFunc(outer[i], i, item, itemIndex) : outer[i];
120
122
  geometry[d3] = c.x;
121
- geometry[d3 + 1] = simpleInverse ? -c.y : c.y;
123
+ geometry[d3 + 1] = c.y;
122
124
  // ignore the z values until we support them
123
125
  geometry[d3 + 2] = 0; // c.z || 0;
124
126
  }
@@ -133,9 +135,9 @@ var webgl_polygonFeature = function (arg) {
133
135
  original = original.concat(hole);
134
136
  geometry.holes.push(d3 / 3);
135
137
  for (i = 0; i < hole.length; i += 1, d3 += 3) {
136
- c = posFunc(hole[i], i, item, itemIndex);
138
+ c = posFunc ? posFunc(hole[i], i, item, itemIndex) : hole[i];
137
139
  geometry.vertices[d3] = c.x;
138
- geometry.vertices[d3 + 1] = simpleInverse ? -c.y : c.y;
140
+ geometry.vertices[d3 + 1] = c.y;
139
141
  // ignore the z values until we support them
140
142
  geometry.vertices[d3 + 2] = 0; // c.z || 0;
141
143
  }
@@ -143,14 +145,12 @@ var webgl_polygonFeature = function (arg) {
143
145
  }
144
146
 
145
147
  // transform to map gcs
146
- if (!simpleInverse) {
147
- geometry.vertices = transform.transformCoordinates(
148
- target_gcs,
149
- map_gcs,
150
- geometry.vertices,
151
- geometry.dimensions
152
- );
153
- }
148
+ geometry.vertices = transform.transformCoordinates(
149
+ target_gcs,
150
+ map_gcs,
151
+ geometry.vertices,
152
+ geometry.dimensions
153
+ );
154
154
 
155
155
  record = {
156
156
  // triangulate
@@ -189,7 +189,7 @@ var webgl_polygonFeature = function (arg) {
189
189
  item = items[k].item;
190
190
  itemIndex = items[k].itemIndex;
191
191
  original = items[k].original;
192
- uniform = uniformPolyFunc(item, itemIndex);
192
+ uniform = uniformVal === undefined ? uniformFunc(item, itemIndex) : uniformVal;
193
193
  opacity = fillOpacityVal;
194
194
  if (uniform) {
195
195
  if (fillColorVal === undefined) {