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

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,26 @@ export var BubbleLayer = (function (ShapeLayer) {
125
125
  }
126
126
  };
127
127
 
128
+ BubbleLayer.prototype._tooltipContext = function _tooltipContext (shape) {
129
+ return {
130
+ type: 'bubble',
131
+ className: 'k-map-bubble-tooltip',
132
+ dataItem: shape.dataItem,
133
+ location: shape.location,
134
+ value: shape.value
135
+ };
136
+ };
137
+
138
+ BubbleLayer.prototype._tooltipAnchor = function _tooltipAnchor (e) {
139
+ var shape = e.element;
140
+ var center = shape.bbox().center();
141
+
142
+ return {
143
+ top: center.y,
144
+ left: center.x
145
+ };
146
+ };
147
+
128
148
  return BubbleLayer;
129
149
  }(ShapeLayer));
130
150
 
@@ -241,12 +241,9 @@ export var Marker = (function (Class) {
241
241
  Marker.prototype.showAt = function showAt (point) {
242
242
  this.render();
243
243
 
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
- }
244
+ this._anchor = { left: Math.round(point.x), top: Math.round(point.y) };
245
+ this.element.style.left = toPixels(this._anchor.left);
246
+ this.element.style.top = toPixels(this._anchor.top);
250
247
  };
251
248
 
252
249
  Marker.prototype.hide = function hide () {
@@ -254,10 +251,6 @@ export var Marker = (function (Class) {
254
251
  this.element.remove();
255
252
  this.element = null;
256
253
  }
257
- if (this.tooltip) {
258
- this.tooltip.destroy();
259
- this.tooltip = null;
260
- }
261
254
  };
262
255
 
263
256
  Marker.prototype.bindEvents = function bindEvents () {
@@ -292,7 +285,7 @@ export var Marker = (function (Class) {
292
285
 
293
286
  var attributes = options.attributes || {};
294
287
  Object.keys(attributes).forEach(function(key) {
295
- element.setAttributett(key, attributes[key]);
288
+ element.setAttribute(key, attributes[key]);
296
289
  });
297
290
 
298
291
  element._kendoNode = this;
@@ -305,14 +298,26 @@ export var Marker = (function (Class) {
305
298
  }
306
299
 
307
300
  this.bindEvents();
308
-
309
- this.renderTooltip();
310
301
  }
311
302
  };
312
303
 
313
304
  Marker.prototype._mouseEnter = function _mouseEnter (e) {
314
305
  var args = this._createEventArgs(e);
315
306
  this.layer._markerMouseEnter(args);
307
+
308
+ this.layer.map._tooltip.show({
309
+ top: this._anchor.top - this.element.offsetHeight,
310
+ left: this._anchor.left
311
+ }, this._tooltipContext());
312
+ };
313
+
314
+ Marker.prototype._tooltipContext = function _tooltipContext () {
315
+ return {
316
+ type: 'marker',
317
+ className: 'k-map-marker-tooltip',
318
+ title: this.options.title,
319
+ location: this.location()
320
+ };
316
321
  };
317
322
 
318
323
  Marker.prototype._mouseLeave = function _mouseLeave (e) {
@@ -329,9 +334,6 @@ export var Marker = (function (Class) {
329
334
  return args;
330
335
  };
331
336
 
332
- Marker.prototype.renderTooltip = function renderTooltip () {
333
- };
334
-
335
337
  Marker.create = function create (arg, defaults) {
336
338
  if (arg instanceof Marker) {
337
339
  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,55 @@ 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.map.layers || []).indexOf(this),
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
+ className: 'k-map-shape-tooltip',
240
+ dataItem: shape.dataItem,
241
+ location: shape.location
242
+ };
243
+ };
244
+
245
+ ShapeLayer.prototype._tooltipAnchor = function _tooltipAnchor (e) {
246
+ var cursor = this.map.eventOffset(e.originalEvent);
247
+ return {
248
+ top: cursor.y,
249
+ left: cursor.x
250
+ };
251
+ };
252
+
223
253
  ShapeLayer.prototype._activate = function _activate () {
224
254
  Layer.prototype._activate.call(this);
225
255
  this._panHandler = proxy(this._pan, this);
@@ -350,6 +380,7 @@ var GeoJsonLoader = (function (Class) {
350
380
  GeoJsonLoader.prototype._loadPolygon = function _loadPolygon (container, rings, dataItem) {
351
381
  var shape = this._buildPolygon(rings);
352
382
  shape.dataItem = dataItem;
383
+ shape.location = this.locator.viewToLocation(shape.bbox().center());
353
384
  return this._loadShape(container, shape);
354
385
  };
355
386
 
@@ -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();
@@ -637,6 +644,10 @@ var Map = (function (Observable) {
637
644
  return layer;
638
645
  };
639
646
 
647
+ Map.prototype._createTooltip = function _createTooltip () {
648
+ return new Tooltip(this.widgetService, this.options.tooltip);
649
+ };
650
+
640
651
  /* eslint-disable arrow-body-style */
641
652
  Map.prototype._initMarkers = function _initMarkers () {
642
653
  var markerLayers = (this.options.layers || []).filter(function (x) {
@@ -663,6 +674,9 @@ var Map = (function (Observable) {
663
674
  origin.y += offset.y;
664
675
  this._scrollOffset = offset;
665
676
 
677
+ this._tooltip.offset = offset;
678
+ this._tooltip.hide();
679
+
666
680
  this._setOrigin(this.layerToLocation(origin));
667
681
 
668
682
  this.trigger('pan', {
@@ -732,6 +746,7 @@ var Map = (function (Observable) {
732
746
  this._viewOrigin = this._getOrigin(true);
733
747
 
734
748
  this._resetScroller();
749
+ this._tooltip.hide();
735
750
 
736
751
  this.trigger('beforeReset');
737
752
  this.trigger('reset');
@@ -803,6 +818,7 @@ var Map = (function (Observable) {
803
818
  }
804
819
 
805
820
  var cursor = this.eventOffset(e);
821
+ this._tooltip.hide();
806
822
 
807
823
  this.trigger('click', {
808
824
  originalEvent: e,
@@ -853,6 +869,15 @@ var Map = (function (Observable) {
853
869
  }
854
870
  };
855
871
 
872
+ Map.prototype._toDocumentCoordinates = function _toDocumentCoordinates (point) {
873
+ var offset = elementOffset(this.element);
874
+
875
+ return {
876
+ left: round(point.x + offset.left),
877
+ top: round(point.y + offset.top)
878
+ };
879
+ };
880
+
856
881
  return Map;
857
882
  }(Observable));
858
883
 
@@ -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,26 @@ 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
+ className: 'k-map-bubble-tooltip',
122
+ dataItem: shape.dataItem,
123
+ location: shape.location,
124
+ value: shape.value
125
+ };
126
+ }
127
+
128
+ _tooltipAnchor(e) {
129
+ const shape = e.element;
130
+ const center = shape.bbox().center();
131
+
132
+ return {
133
+ top: center.y,
134
+ left: center.x
135
+ };
136
+ }
117
137
  }
118
138
 
119
139
  setDefaultOptions(BubbleLayer, {
@@ -223,12 +223,9 @@ export class Marker extends Class {
223
223
  showAt(point) {
224
224
  this.render();
225
225
 
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
- }
226
+ this._anchor = { left: Math.round(point.x), top: Math.round(point.y) };
227
+ this.element.style.left = toPixels(this._anchor.left);
228
+ this.element.style.top = toPixels(this._anchor.top);
232
229
  }
233
230
 
234
231
  hide() {
@@ -236,10 +233,6 @@ export class Marker extends Class {
236
233
  this.element.remove();
237
234
  this.element = null;
238
235
  }
239
- if (this.tooltip) {
240
- this.tooltip.destroy();
241
- this.tooltip = null;
242
- }
243
236
  }
244
237
 
245
238
  bindEvents() {
@@ -274,7 +267,7 @@ export class Marker extends Class {
274
267
 
275
268
  const attributes = options.attributes || {};
276
269
  Object.keys(attributes).forEach(function(key) {
277
- element.setAttributett(key, attributes[key]);
270
+ element.setAttribute(key, attributes[key]);
278
271
  });
279
272
 
280
273
  element._kendoNode = this;
@@ -287,14 +280,26 @@ export class Marker extends Class {
287
280
  }
288
281
 
289
282
  this.bindEvents();
290
-
291
- this.renderTooltip();
292
283
  }
293
284
  }
294
285
 
295
286
  _mouseEnter(e) {
296
287
  const args = this._createEventArgs(e);
297
288
  this.layer._markerMouseEnter(args);
289
+
290
+ this.layer.map._tooltip.show({
291
+ top: this._anchor.top - this.element.offsetHeight,
292
+ left: this._anchor.left
293
+ }, this._tooltipContext());
294
+ }
295
+
296
+ _tooltipContext() {
297
+ return {
298
+ type: 'marker',
299
+ className: 'k-map-marker-tooltip',
300
+ title: this.options.title,
301
+ location: this.location()
302
+ };
298
303
  }
299
304
 
300
305
  _mouseLeave(e) {
@@ -311,9 +316,6 @@ export class Marker extends Class {
311
316
  return args;
312
317
  }
313
318
 
314
- renderTooltip() {
315
- }
316
-
317
319
  static create(arg, defaults) {
318
320
  if (arg instanceof Marker) {
319
321
  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,53 @@ 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.map.layers || []).indexOf(this),
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
+ className: 'k-map-shape-tooltip',
230
+ dataItem: shape.dataItem,
231
+ location: shape.location
232
+ };
233
+ }
234
+
235
+ _tooltipAnchor(e) {
236
+ const cursor = this.map.eventOffset(e.originalEvent);
237
+ return {
238
+ top: cursor.y,
239
+ left: cursor.x
240
+ };
241
+ }
242
+
215
243
  _activate() {
216
244
  super._activate();
217
245
  this._panHandler = proxy(this._pan, this);
@@ -334,6 +362,7 @@ class GeoJsonLoader extends Class {
334
362
  _loadPolygon(container, rings, dataItem) {
335
363
  let shape = this._buildPolygon(rings);
336
364
  shape.dataItem = dataItem;
365
+ shape.location = this.locator.viewToLocation(shape.bbox().center());
337
366
  return this._loadShape(container, shape);
338
367
  }
339
368
 
@@ -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';
@@ -113,13 +116,16 @@ class Map extends Observable {
113
116
  constructor(element, options = {}, themeOptions = {}, context = {}) {
114
117
  super();
115
118
 
116
-
117
119
  this._init(element, options, themeOptions, context);
118
120
  }
119
121
 
120
122
  destroy() {
121
123
  this.scroller.destroy();
122
124
 
125
+ if (this._tooltip) {
126
+ this._tooltip.destroy();
127
+ }
128
+
123
129
  if (this.navigator) {
124
130
  this.navigator.destroy();
125
131
  }
@@ -162,6 +168,7 @@ class Map extends Observable {
162
168
 
163
169
  this._viewOrigin = this._getOrigin();
164
170
 
171
+ this._tooltip = this._createTooltip();
165
172
  this._initScroller();
166
173
  this._initMarkers();
167
174
  this._initControls();
@@ -609,6 +616,10 @@ class Map extends Observable {
609
616
  return layer;
610
617
  }
611
618
 
619
+ _createTooltip() {
620
+ return new Tooltip(this.widgetService, this.options.tooltip);
621
+ }
622
+
612
623
  /* eslint-disable arrow-body-style */
613
624
  _initMarkers() {
614
625
  const markerLayers = (this.options.layers || []).filter(x => {
@@ -635,6 +646,9 @@ class Map extends Observable {
635
646
  origin.y += offset.y;
636
647
  this._scrollOffset = offset;
637
648
 
649
+ this._tooltip.offset = offset;
650
+ this._tooltip.hide();
651
+
638
652
  this._setOrigin(this.layerToLocation(origin));
639
653
 
640
654
  this.trigger('pan', {
@@ -704,6 +718,7 @@ class Map extends Observable {
704
718
  this._viewOrigin = this._getOrigin(true);
705
719
 
706
720
  this._resetScroller();
721
+ this._tooltip.hide();
707
722
 
708
723
  this.trigger('beforeReset');
709
724
  this.trigger('reset');
@@ -775,6 +790,7 @@ class Map extends Observable {
775
790
  }
776
791
 
777
792
  let cursor = this.eventOffset(e);
793
+ this._tooltip.hide();
778
794
 
779
795
  this.trigger('click', {
780
796
  originalEvent: e,
@@ -824,6 +840,15 @@ class Map extends Observable {
824
840
  }
825
841
  }
826
842
  }
843
+
844
+ _toDocumentCoordinates(point) {
845
+ const offset = elementOffset(this.element);
846
+
847
+ return {
848
+ left: round(point.x + offset.left),
849
+ top: round(point.y + offset.top)
850
+ };
851
+ }
827
852
  }
828
853
 
829
854
  setDefaultOptions(Map, {