leafer-x-tooltip-canvas 1.0.2 → 1.0.3

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/dist/index.js CHANGED
@@ -138,11 +138,35 @@ this.LeaferX.tooltipCanvas = (function (exports) {
138
138
  this.config = data.config;
139
139
  this.show();
140
140
  }
141
+ log(...args) {
142
+ var _a;
143
+ if ((_a = this.config) === null || _a === void 0 ? void 0 : _a.debug) {
144
+ console.log('[Tooltip]', ...args);
145
+ }
146
+ }
141
147
  createShapes(pos = this.__.pointerPos) {
148
+ var _a, _b, _c, _d, _e, _f, _g;
142
149
  this.clear();
143
150
  const { width, height, text } = handleTextStyle(this.target, this.config);
144
151
  const { backgroundColor, stroke, color, padding, borderRadius, fontSize, fontWeight, fontFamily, } = this.config.style;
145
152
  let offset = this.config.offset;
153
+ this.log('createShapes', {
154
+ target: {
155
+ tag: (_a = this.target) === null || _a === void 0 ? void 0 : _a.tag,
156
+ id: (_b = this.target) === null || _b === void 0 ? void 0 : _b.id,
157
+ className: (_c = this.target) === null || _c === void 0 ? void 0 : _c.className,
158
+ parent: {
159
+ tag: (_e = (_d = this.target) === null || _d === void 0 ? void 0 : _d.parent) === null || _e === void 0 ? void 0 : _e.tag,
160
+ id: (_g = (_f = this.target) === null || _f === void 0 ? void 0 : _f.parent) === null || _g === void 0 ? void 0 : _g.id,
161
+ },
162
+ },
163
+ pointer: pos,
164
+ offset,
165
+ renderPos: { x: pos.x + offset[0], y: pos.y + offset[1] },
166
+ size: { width, height },
167
+ style: { backgroundColor, stroke, color, padding, borderRadius, fontSize },
168
+ text,
169
+ });
146
170
  this.setStyle({
147
171
  fill: backgroundColor,
148
172
  stroke,
@@ -173,6 +197,7 @@ this.LeaferX.tooltipCanvas = (function (exports) {
173
197
  }
174
198
  show(pos = this.__.pointerPos) {
175
199
  this.clearShowHideTimers();
200
+ this.log('show', { pos, delay: this.config.showDelay, isShow: this.isShow });
176
201
  this.showTimerId = setTimeout(() => {
177
202
  this.createShapes(pos);
178
203
  this.showTimerId = null;
@@ -180,6 +205,7 @@ this.LeaferX.tooltipCanvas = (function (exports) {
180
205
  }
181
206
  hide(immediate = false) {
182
207
  this.clearShowHideTimers();
208
+ this.log('hide', { immediate, delay: this.config.hideDelay, isShow: this.isShow });
183
209
  if (immediate) {
184
210
  this.destroy();
185
211
  }
@@ -192,6 +218,7 @@ this.LeaferX.tooltipCanvas = (function (exports) {
192
218
  }
193
219
  update(pos) {
194
220
  this.clearShowHideTimers();
221
+ this.log('update', { pos, isShow: this.isShow });
195
222
  if (this.isShow) {
196
223
  this.createShapes(pos);
197
224
  }
@@ -232,6 +259,7 @@ this.LeaferX.tooltipCanvas = (function (exports) {
232
259
  ], Tooltip);
233
260
 
234
261
  const defaultConfig = {
262
+ debug: false,
235
263
  reference: 'pointer',
236
264
  info: ['tag'],
237
265
  showType: 'value',
@@ -260,6 +288,11 @@ this.LeaferX.tooltipCanvas = (function (exports) {
260
288
  };
261
289
 
262
290
  class TooltipPlugin {
291
+ log(...args) {
292
+ if (this.config.debug) {
293
+ console.log('[TooltipPlugin]', ...args);
294
+ }
295
+ }
263
296
  constructor(instance, config) {
264
297
  this.tooltipCache = new Map();
265
298
  this.includesTypeSet = new Set();
@@ -319,7 +352,8 @@ this.LeaferX.tooltipCanvas = (function (exports) {
319
352
  this.hideTooltip();
320
353
  return;
321
354
  }
322
- if (!this.handleAllowed(target)) {
355
+ const allowed = this.handleAllowed(target);
356
+ if (!allowed) {
323
357
  this.hideTooltip();
324
358
  return;
325
359
  }
@@ -346,16 +380,24 @@ this.LeaferX.tooltipCanvas = (function (exports) {
346
380
  const hasIncludesRule = this.includesTypeSet.size > 0;
347
381
  const hasExcludesRule = this.excludesTypeSet.size > 0;
348
382
  if (!hasIncludesRule && !hasExcludesRule) {
383
+ this.log('allowed', { target: target.tag, result: true, reason: 'no rules' });
349
384
  return true;
350
385
  }
351
386
  const matchesInclude = targetIdentifiers.some((id) => this.includesTypeSet.has(id));
352
387
  const matchesExclude = targetIdentifiers.some((id) => this.excludesTypeSet.has(id));
353
- if (matchesInclude)
388
+ if (matchesInclude) {
389
+ this.log('allowed', { target: target.tag, result: true, reason: 'matches include' });
354
390
  return true;
355
- if (matchesExclude)
391
+ }
392
+ if (matchesExclude) {
393
+ this.log('allowed', { target: target.tag, result: false, reason: 'matches exclude' });
356
394
  return false;
357
- if (hasIncludesRule)
395
+ }
396
+ if (hasIncludesRule) {
397
+ this.log('allowed', { target: target.tag, result: false, reason: 'has include rule but not matched' });
358
398
  return false;
399
+ }
400
+ this.log('allowed', { target: target.tag, result: true, reason: 'only exclude rule, not matched' });
359
401
  return true;
360
402
  }
361
403
  hideTooltip() {
@@ -379,12 +421,14 @@ this.LeaferX.tooltipCanvas = (function (exports) {
379
421
  });
380
422
  const cachedTooltip = this.tooltipCache.get(id);
381
423
  if (cachedTooltip && cachedTooltip.parent) {
424
+ this.log('tooltip update', { id, x: event.x, y: event.y });
382
425
  cachedTooltip.update({ x: event.x, y: event.y });
383
426
  }
384
427
  else {
385
428
  if (cachedTooltip) {
386
429
  this.tooltipCache.delete(id);
387
430
  }
431
+ this.log('tooltip create', { id, x: event.x, y: event.y, target: target.tag });
388
432
  const tooltip = new Tooltip({
389
433
  id,
390
434
  pointerPos: { x: event.x, y: event.y },