@progress/kendo-charts 1.23.6 → 1.24.0-dev.202206130925

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.
@@ -0,0 +1,2 @@
1
+ export var SHOW_TOOLTIP = 'showTooltip';
2
+ export var HIDE_TOOLTIP = 'hideTooltip';
@@ -125,6 +125,27 @@ export var BubbleLayer = (function (ShapeLayer) {
125
125
  }
126
126
  };
127
127
 
128
+ BubbleLayer.prototype._tooltipContext = function _tooltipContext (shape) {
129
+ return {
130
+ type: 'bubble',
131
+ layerIndex: this._layerIndex(),
132
+ className: 'k-map-bubble-tooltip',
133
+ dataItem: shape.dataItem,
134
+ location: shape.location,
135
+ value: shape.value
136
+ };
137
+ };
138
+
139
+ BubbleLayer.prototype._tooltipAnchor = function _tooltipAnchor (e) {
140
+ var shape = e.element;
141
+ var center = shape.bbox().center();
142
+
143
+ return {
144
+ top: center.y,
145
+ left: center.x
146
+ };
147
+ };
148
+
128
149
  return BubbleLayer;
129
150
  }(ShapeLayer));
130
151
 
@@ -136,5 +136,10 @@ export var Layer = (function (Class) {
136
136
  return this._data && this._data.length > 0;
137
137
  };
138
138
 
139
+ Layer.prototype._layerIndex = function _layerIndex () {
140
+ var layers = this.map.layers || [];
141
+ return layers.indexOf(this);
142
+ };
143
+
139
144
  return Layer;
140
145
  }(Class));
@@ -153,14 +153,13 @@ export var MarkerLayer = (function (Layer) {
153
153
  };
154
154
 
155
155
  MarkerLayer.prototype._markerClick = function _markerClick (e) {
156
- var layers = this.map.layers || [];
157
156
  var marker = e.target._kendoNode;
158
157
 
159
158
  var args = {
160
159
  // marker: $(e.target).data('kendoMarker'),
161
160
  // marker: e.target.getAttribute("data-kendoMarker"),
162
161
  layer: this,
163
- layerIndex: layers.indexOf(this),
162
+ layerIndex: this._layerIndex(),
164
163
  marker: marker,
165
164
  markerIndex: (this.items || []).indexOf(marker),
166
165
  originalEvent: e
@@ -184,7 +183,7 @@ export var MarkerLayer = (function (Layer) {
184
183
 
185
184
  var args = extend({}, {
186
185
  layer: this,
187
- layerIndex: this.map.layers.indexOf(this),
186
+ layerIndex: this._layerIndex(),
188
187
  marker: marker,
189
188
  markerIndex: (this.items || []).indexOf(marker)
190
189
  }, e);
@@ -241,12 +240,9 @@ export var Marker = (function (Class) {
241
240
  Marker.prototype.showAt = function showAt (point) {
242
241
  this.render();
243
242
 
244
- this.element.style.left = toPixels(Math.round(point.x));
245
- this.element.style.top = toPixels(Math.round(point.y));
246
-
247
- if (this.tooltip && this.tooltip.popup) {
248
- this.tooltip.popup._position();
249
- }
243
+ this._anchor = { left: Math.round(point.x), top: Math.round(point.y) };
244
+ this.element.style.left = toPixels(this._anchor.left);
245
+ this.element.style.top = toPixels(this._anchor.top);
250
246
  };
251
247
 
252
248
  Marker.prototype.hide = function hide () {
@@ -254,10 +250,6 @@ export var Marker = (function (Class) {
254
250
  this.element.remove();
255
251
  this.element = null;
256
252
  }
257
- if (this.tooltip) {
258
- this.tooltip.destroy();
259
- this.tooltip = null;
260
- }
261
253
  };
262
254
 
263
255
  Marker.prototype.bindEvents = function bindEvents () {
@@ -288,11 +280,13 @@ export var Marker = (function (Class) {
288
280
  var element = document.createElement('span');
289
281
  addClass(element, 'k-marker k-icon k-i-marker-' + toHyphens(options.shape || 'pin'));
290
282
 
291
- element.setAttribute("title", options.title);
283
+ if (options.title) {
284
+ element.setAttribute("title", options.title);
285
+ }
292
286
 
293
287
  var attributes = options.attributes || {};
294
288
  Object.keys(attributes).forEach(function(key) {
295
- element.setAttributett(key, attributes[key]);
289
+ element.setAttribute(key, attributes[key]);
296
290
  });
297
291
 
298
292
  element._kendoNode = this;
@@ -305,14 +299,28 @@ export var Marker = (function (Class) {
305
299
  }
306
300
 
307
301
  this.bindEvents();
308
-
309
- this.renderTooltip();
310
302
  }
311
303
  };
312
304
 
313
305
  Marker.prototype._mouseEnter = function _mouseEnter (e) {
314
306
  var args = this._createEventArgs(e);
315
307
  this.layer._markerMouseEnter(args);
308
+
309
+ this.layer.map._tooltip.show({
310
+ top: this._anchor.top - this.element.offsetHeight,
311
+ left: this._anchor.left
312
+ }, this._tooltipContext());
313
+ };
314
+
315
+ Marker.prototype._tooltipContext = function _tooltipContext () {
316
+ return {
317
+ type: 'marker',
318
+ layerIndex: this.layer._layerIndex(),
319
+ className: 'k-map-marker-tooltip',
320
+ dataItem: this.dataItem,
321
+ title: this.options.title,
322
+ location: this.location()
323
+ };
316
324
  };
317
325
 
318
326
  Marker.prototype._mouseLeave = function _mouseLeave (e) {
@@ -329,9 +337,6 @@ export var Marker = (function (Class) {
329
337
  return args;
330
338
  };
331
339
 
332
- Marker.prototype.renderTooltip = function renderTooltip () {
333
- };
334
-
335
340
  Marker.create = function create (arg, defaults) {
336
341
  if (arg instanceof Marker) {
337
342
  return arg;
@@ -45,10 +45,9 @@ export var ShapeLayer = (function (Layer) {
45
45
 
46
46
  this._click = this._handler('shapeClick');
47
47
  this.surface.bind('click', this._click);
48
- this._mouseenter = this._handler('shapeMouseEnter');
49
- this.surface.bind('mouseenter', this._mouseenter);
50
48
  this._mouseleave = this._handler('shapeMouseLeave');
51
49
  this.surface.bind('mouseleave', this._mouseleave);
50
+ this.surface.bind('mouseenter', this._mouseenter.bind(this));
52
51
  }
53
52
 
54
53
  if ( Layer ) ShapeLayer.__proto__ = Layer;
@@ -202,24 +201,56 @@ export var ShapeLayer = (function (Layer) {
202
201
  }
203
202
  };
204
203
 
205
- ShapeLayer.prototype._handler = function _handler (event) {
206
- var layer = this;
204
+ ShapeLayer.prototype._eventArgs = function _eventArgs (e) {
205
+ return {
206
+ layer: this,
207
+ layerIndex: this._layerIndex(),
208
+ shape: e.element,
209
+ shapeIndex: (this._data || []).indexOf(e.element.dataItem),
210
+ originalEvent: e.originalEvent
211
+ };
212
+ };
213
+
214
+ ShapeLayer.prototype._handler = function _handler (eventName) {
215
+ var this$1 = this;
207
216
 
208
- return function(e) {
217
+ return function (e) {
209
218
  if (e.element) {
210
- var args = {
211
- layer: layer,
212
- layerIndex: (layer.map.layers || []).indexOf(layer),
213
- shape: e.element,
214
- shapeIndex: (layer._data || []).indexOf(e.element.dataItem),
215
- originalEvent: e.originalEvent
216
- };
217
-
218
- layer.map.trigger(event, args);
219
+ this$1.map.trigger(eventName, this$1._eventArgs(e));
219
220
  }
220
221
  };
221
222
  };
222
223
 
224
+ ShapeLayer.prototype._mouseenter = function _mouseenter (e) {
225
+ if (!e.element) {
226
+ return;
227
+ }
228
+
229
+ this.map.trigger('shapeMouseEnter', this._eventArgs(e));
230
+
231
+ var shape = e.element;
232
+ var anchor = this._tooltipAnchor(e);
233
+ this.map._tooltip.show(anchor, this._tooltipContext(shape));
234
+ };
235
+
236
+ ShapeLayer.prototype._tooltipContext = function _tooltipContext (shape) {
237
+ return {
238
+ type: 'shape',
239
+ layerIndex: this._layerIndex,
240
+ className: 'k-map-shape-tooltip',
241
+ dataItem: shape.dataItem,
242
+ location: shape.location
243
+ };
244
+ };
245
+
246
+ ShapeLayer.prototype._tooltipAnchor = function _tooltipAnchor (e) {
247
+ var cursor = this.map.eventOffset(e.originalEvent);
248
+ return {
249
+ top: cursor.y,
250
+ left: cursor.x
251
+ };
252
+ };
253
+
223
254
  ShapeLayer.prototype._activate = function _activate () {
224
255
  Layer.prototype._activate.call(this);
225
256
  this._panHandler = proxy(this._pan, this);
@@ -350,6 +381,7 @@ var GeoJsonLoader = (function (Class) {
350
381
  GeoJsonLoader.prototype._loadPolygon = function _loadPolygon (container, rings, dataItem) {
351
382
  var shape = this._buildPolygon(rings);
352
383
  shape.dataItem = dataItem;
384
+ shape.location = this.locator.viewToLocation(shape.bbox().center());
353
385
  return this._loadShape(container, shape);
354
386
  };
355
387
 
@@ -11,7 +11,8 @@ import {
11
11
  limitValue,
12
12
  deepExtend,
13
13
  elementOffset,
14
- isArray
14
+ isArray,
15
+ round
15
16
  } from '../common';
16
17
 
17
18
  import {
@@ -38,6 +39,8 @@ import {
38
39
  Extent
39
40
  } from './extent';
40
41
 
42
+ import { Tooltip } from './tooltip/tooltip';
43
+
41
44
  import {
42
45
  TileLayer
43
46
  } from './layers/tile';
@@ -117,7 +120,6 @@ var Map = (function (Observable) {
117
120
 
118
121
  Observable.call(this);
119
122
 
120
-
121
123
  this._init(element, options, themeOptions, context);
122
124
  }
123
125
 
@@ -130,6 +132,10 @@ var Map = (function (Observable) {
130
132
 
131
133
  this.scroller.destroy();
132
134
 
135
+ if (this._tooltip) {
136
+ this._tooltip.destroy();
137
+ }
138
+
133
139
  if (this.navigator) {
134
140
  this.navigator.destroy();
135
141
  }
@@ -176,6 +182,7 @@ var Map = (function (Observable) {
176
182
 
177
183
  this._viewOrigin = this._getOrigin();
178
184
 
185
+ this._tooltip = this._createTooltip();
179
186
  this._initScroller();
180
187
  this._initMarkers();
181
188
  this._initControls();
@@ -418,6 +425,12 @@ var Map = (function (Observable) {
418
425
  return false;
419
426
  };
420
427
 
428
+ Map.prototype.hideTooltip = function hideTooltip () {
429
+ if (this._tooltip) {
430
+ this._tooltip.hide();
431
+ }
432
+ };
433
+
421
434
  Map.prototype._setOrigin = function _setOrigin (origin, zoom) {
422
435
  var size = this.viewSize(),
423
436
  topLeft;
@@ -637,6 +650,10 @@ var Map = (function (Observable) {
637
650
  return layer;
638
651
  };
639
652
 
653
+ Map.prototype._createTooltip = function _createTooltip () {
654
+ return new Tooltip(this.widgetService, this.options.tooltip);
655
+ };
656
+
640
657
  /* eslint-disable arrow-body-style */
641
658
  Map.prototype._initMarkers = function _initMarkers () {
642
659
  var markerLayers = (this.options.layers || []).filter(function (x) {
@@ -663,6 +680,9 @@ var Map = (function (Observable) {
663
680
  origin.y += offset.y;
664
681
  this._scrollOffset = offset;
665
682
 
683
+ this._tooltip.offset = offset;
684
+ this.hideTooltip();
685
+
666
686
  this._setOrigin(this.layerToLocation(origin));
667
687
 
668
688
  this.trigger('pan', {
@@ -732,6 +752,7 @@ var Map = (function (Observable) {
732
752
  this._viewOrigin = this._getOrigin(true);
733
753
 
734
754
  this._resetScroller();
755
+ this.hideTooltip();
735
756
 
736
757
  this.trigger('beforeReset');
737
758
  this.trigger('reset');
@@ -803,6 +824,7 @@ var Map = (function (Observable) {
803
824
  }
804
825
 
805
826
  var cursor = this.eventOffset(e);
827
+ this.hideTooltip();
806
828
 
807
829
  this.trigger('click', {
808
830
  originalEvent: e,
@@ -853,6 +875,15 @@ var Map = (function (Observable) {
853
875
  }
854
876
  };
855
877
 
878
+ Map.prototype._toDocumentCoordinates = function _toDocumentCoordinates (point) {
879
+ var offset = elementOffset(this.element);
880
+
881
+ return {
882
+ left: round(point.x + offset.left),
883
+ top: round(point.y + offset.top)
884
+ };
885
+ };
886
+
856
887
  return Map;
857
888
  }(Observable));
858
889
 
@@ -0,0 +1,73 @@
1
+ import { Class, deepExtend, setDefaultOptions } from '../../common';
2
+ import { SHOW_TOOLTIP, HIDE_TOOLTIP } from '../constants';
3
+
4
+ export var Tooltip = (function (Class) {
5
+ function Tooltip(widgetService, options) {
6
+ Class.call(this);
7
+
8
+ this.widgetService = widgetService;
9
+ this.options = deepExtend({}, this.options, options);
10
+ this.offset = { x: 0, y: 0 };
11
+ }
12
+
13
+ if ( Class ) Tooltip.__proto__ = Class;
14
+ Tooltip.prototype = Object.create( Class && Class.prototype );
15
+ Tooltip.prototype.constructor = Tooltip;
16
+
17
+ var prototypeAccessors = { anchor: { configurable: true } };
18
+
19
+ Tooltip.prototype.show = function show (anchor, args) {
20
+ if (this.location === args.location) {
21
+ return;
22
+ }
23
+
24
+ this.anchor = anchor;
25
+ this.location = args.location;
26
+
27
+ this.widgetService.notify(SHOW_TOOLTIP,
28
+ Object.assign({ anchor: this.anchor }, args)
29
+ );
30
+
31
+ this.visible = true;
32
+ };
33
+
34
+ Tooltip.prototype.hide = function hide () {
35
+ if (this.widgetService) {
36
+ this.widgetService.notify(HIDE_TOOLTIP);
37
+ }
38
+
39
+ this.visible = false;
40
+ this.location = null;
41
+ };
42
+
43
+ prototypeAccessors.anchor.get = function () {
44
+ return this._anchor;
45
+ };
46
+
47
+ prototypeAccessors.anchor.set = function (anchor) {
48
+ var documentPoint = this.widgetService.widget._toDocumentCoordinates({
49
+ x: anchor.left - this.offset.x,
50
+ y: anchor.top - this.offset.y
51
+ });
52
+
53
+ this._anchor = {
54
+ left: documentPoint.left,
55
+ top: documentPoint.top
56
+ };
57
+ };
58
+
59
+ Tooltip.prototype.destroy = function destroy () {
60
+ this.widgetService = null;
61
+ };
62
+
63
+ Object.defineProperties( Tooltip.prototype, prototypeAccessors );
64
+
65
+ return Tooltip;
66
+ }(Class));
67
+
68
+ setDefaultOptions(Tooltip, {
69
+ border: {
70
+ width: 1
71
+ },
72
+ opacity: 1
73
+ });
@@ -0,0 +1,2 @@
1
+ export const SHOW_TOOLTIP = 'showTooltip';
2
+ export const HIDE_TOOLTIP = 'hideTooltip';
@@ -114,6 +114,27 @@ export class BubbleLayer extends ShapeLayer {
114
114
  this.surface.draw(shape);
115
115
  }
116
116
  }
117
+
118
+ _tooltipContext(shape) {
119
+ return {
120
+ type: 'bubble',
121
+ layerIndex: this._layerIndex(),
122
+ className: 'k-map-bubble-tooltip',
123
+ dataItem: shape.dataItem,
124
+ location: shape.location,
125
+ value: shape.value
126
+ };
127
+ }
128
+
129
+ _tooltipAnchor(e) {
130
+ const shape = e.element;
131
+ const center = shape.bbox().center();
132
+
133
+ return {
134
+ top: center.y,
135
+ left: center.x
136
+ };
137
+ }
117
138
  }
118
139
 
119
140
  setDefaultOptions(BubbleLayer, {
@@ -131,4 +131,9 @@ export class Layer extends Class {
131
131
  _hasData() {
132
132
  return this._data && this._data.length > 0;
133
133
  }
134
+
135
+ _layerIndex() {
136
+ const layers = this.map.layers || [];
137
+ return layers.indexOf(this);
138
+ }
134
139
  }
@@ -141,14 +141,13 @@ export class MarkerLayer extends Layer {
141
141
  }
142
142
 
143
143
  _markerClick(e) {
144
- const layers = this.map.layers || [];
145
144
  const marker = e.target._kendoNode;
146
145
 
147
146
  let args = {
148
147
  // marker: $(e.target).data('kendoMarker'),
149
148
  // marker: e.target.getAttribute("data-kendoMarker"),
150
149
  layer: this,
151
- layerIndex: layers.indexOf(this),
150
+ layerIndex: this._layerIndex(),
152
151
  marker: marker,
153
152
  markerIndex: (this.items || []).indexOf(marker),
154
153
  originalEvent: e
@@ -172,7 +171,7 @@ export class MarkerLayer extends Layer {
172
171
 
173
172
  let args = extend({}, {
174
173
  layer: this,
175
- layerIndex: this.map.layers.indexOf(this),
174
+ layerIndex: this._layerIndex(),
176
175
  marker: marker,
177
176
  markerIndex: (this.items || []).indexOf(marker)
178
177
  }, e);
@@ -223,12 +222,9 @@ export class Marker extends Class {
223
222
  showAt(point) {
224
223
  this.render();
225
224
 
226
- this.element.style.left = toPixels(Math.round(point.x));
227
- this.element.style.top = toPixels(Math.round(point.y));
228
-
229
- if (this.tooltip && this.tooltip.popup) {
230
- this.tooltip.popup._position();
231
- }
225
+ this._anchor = { left: Math.round(point.x), top: Math.round(point.y) };
226
+ this.element.style.left = toPixels(this._anchor.left);
227
+ this.element.style.top = toPixels(this._anchor.top);
232
228
  }
233
229
 
234
230
  hide() {
@@ -236,10 +232,6 @@ export class Marker extends Class {
236
232
  this.element.remove();
237
233
  this.element = null;
238
234
  }
239
- if (this.tooltip) {
240
- this.tooltip.destroy();
241
- this.tooltip = null;
242
- }
243
235
  }
244
236
 
245
237
  bindEvents() {
@@ -270,11 +262,13 @@ export class Marker extends Class {
270
262
  const element = document.createElement('span');
271
263
  addClass(element, 'k-marker k-icon k-i-marker-' + toHyphens(options.shape || 'pin'));
272
264
 
273
- element.setAttribute("title", options.title);
265
+ if (options.title) {
266
+ element.setAttribute("title", options.title);
267
+ }
274
268
 
275
269
  const attributes = options.attributes || {};
276
270
  Object.keys(attributes).forEach(function(key) {
277
- element.setAttributett(key, attributes[key]);
271
+ element.setAttribute(key, attributes[key]);
278
272
  });
279
273
 
280
274
  element._kendoNode = this;
@@ -287,14 +281,28 @@ export class Marker extends Class {
287
281
  }
288
282
 
289
283
  this.bindEvents();
290
-
291
- this.renderTooltip();
292
284
  }
293
285
  }
294
286
 
295
287
  _mouseEnter(e) {
296
288
  const args = this._createEventArgs(e);
297
289
  this.layer._markerMouseEnter(args);
290
+
291
+ this.layer.map._tooltip.show({
292
+ top: this._anchor.top - this.element.offsetHeight,
293
+ left: this._anchor.left
294
+ }, this._tooltipContext());
295
+ }
296
+
297
+ _tooltipContext() {
298
+ return {
299
+ type: 'marker',
300
+ layerIndex: this.layer._layerIndex(),
301
+ className: 'k-map-marker-tooltip',
302
+ dataItem: this.dataItem,
303
+ title: this.options.title,
304
+ location: this.location()
305
+ };
298
306
  }
299
307
 
300
308
  _mouseLeave(e) {
@@ -311,9 +319,6 @@ export class Marker extends Class {
311
319
  return args;
312
320
  }
313
321
 
314
- renderTooltip() {
315
- }
316
-
317
322
  static create(arg, defaults) {
318
323
  if (arg instanceof Marker) {
319
324
  return arg;
@@ -45,10 +45,9 @@ export class ShapeLayer extends Layer {
45
45
 
46
46
  this._click = this._handler('shapeClick');
47
47
  this.surface.bind('click', this._click);
48
- this._mouseenter = this._handler('shapeMouseEnter');
49
- this.surface.bind('mouseenter', this._mouseenter);
50
48
  this._mouseleave = this._handler('shapeMouseLeave');
51
49
  this.surface.bind('mouseleave', this._mouseleave);
50
+ this.surface.bind('mouseenter', this._mouseenter.bind(this));
52
51
  }
53
52
 
54
53
  destroy() {
@@ -194,24 +193,54 @@ export class ShapeLayer extends Layer {
194
193
  }
195
194
  }
196
195
 
197
- _handler(event) {
198
- let layer = this;
196
+ _eventArgs(e) {
197
+ return {
198
+ layer: this,
199
+ layerIndex: this._layerIndex(),
200
+ shape: e.element,
201
+ shapeIndex: (this._data || []).indexOf(e.element.dataItem),
202
+ originalEvent: e.originalEvent
203
+ };
204
+ }
199
205
 
200
- return function(e) {
206
+ _handler(eventName) {
207
+ return (e) => {
201
208
  if (e.element) {
202
- let args = {
203
- layer: layer,
204
- layerIndex: (layer.map.layers || []).indexOf(layer),
205
- shape: e.element,
206
- shapeIndex: (layer._data || []).indexOf(e.element.dataItem),
207
- originalEvent: e.originalEvent
208
- };
209
-
210
- layer.map.trigger(event, args);
209
+ this.map.trigger(eventName, this._eventArgs(e));
211
210
  }
212
211
  };
213
212
  }
214
213
 
214
+ _mouseenter(e) {
215
+ if (!e.element) {
216
+ return;
217
+ }
218
+
219
+ this.map.trigger('shapeMouseEnter', this._eventArgs(e));
220
+
221
+ const shape = e.element;
222
+ const anchor = this._tooltipAnchor(e);
223
+ this.map._tooltip.show(anchor, this._tooltipContext(shape));
224
+ }
225
+
226
+ _tooltipContext(shape) {
227
+ return {
228
+ type: 'shape',
229
+ layerIndex: this._layerIndex,
230
+ className: 'k-map-shape-tooltip',
231
+ dataItem: shape.dataItem,
232
+ location: shape.location
233
+ };
234
+ }
235
+
236
+ _tooltipAnchor(e) {
237
+ const cursor = this.map.eventOffset(e.originalEvent);
238
+ return {
239
+ top: cursor.y,
240
+ left: cursor.x
241
+ };
242
+ }
243
+
215
244
  _activate() {
216
245
  super._activate();
217
246
  this._panHandler = proxy(this._pan, this);
@@ -334,6 +363,7 @@ class GeoJsonLoader extends Class {
334
363
  _loadPolygon(container, rings, dataItem) {
335
364
  let shape = this._buildPolygon(rings);
336
365
  shape.dataItem = dataItem;
366
+ shape.location = this.locator.viewToLocation(shape.bbox().center());
337
367
  return this._loadShape(container, shape);
338
368
  }
339
369