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/README.en.md CHANGED
@@ -55,6 +55,12 @@ The specific config options are as follows. Click on the field name to jump to [
55
55
  </tr>
56
56
  </thead>
57
57
  <tbody>
58
+ <tr>
59
+ <td>debug</td>
60
+ <td>boolean</td>
61
+ <td>false</td>
62
+ <td>Enable debug mode to output target element, parent, position, size, style info</td>
63
+ </tr>
58
64
  <tr>
59
65
  <td><a href="#display-information">info</a></td>
60
66
  <td>Array&lt;string&gt;</td>
package/README.md CHANGED
@@ -55,6 +55,12 @@ new TooltipPlugin(app, {
55
55
  </tr>
56
56
  </thead>
57
57
  <tbody>
58
+ <tr>
59
+ <td>debug</td>
60
+ <td>boolean</td>
61
+ <td>false</td>
62
+ <td>开启调试模式,输出目标元素、父级、位置、尺寸、样式等信息</td>
63
+ </tr>
58
64
  <tr>
59
65
  <td><a href="#显示信息">info</a></td>
60
66
  <td>Array&lt;string&gt;</td>
package/dev/bundle.js CHANGED
@@ -136,11 +136,35 @@ let Tooltip = class Tooltip extends di$1 {
136
136
  this.config = data.config;
137
137
  this.show();
138
138
  }
139
+ log(...args) {
140
+ var _a;
141
+ if ((_a = this.config) === null || _a === void 0 ? void 0 : _a.debug) {
142
+ console.log('[Tooltip]', ...args);
143
+ }
144
+ }
139
145
  createShapes(pos = this.__.pointerPos) {
146
+ var _a, _b, _c, _d, _e, _f, _g;
140
147
  this.clear();
141
148
  const { width, height, text } = handleTextStyle(this.target, this.config);
142
149
  const { backgroundColor, stroke, color, padding, borderRadius, fontSize, fontWeight, fontFamily, } = this.config.style;
143
150
  let offset = this.config.offset;
151
+ this.log('createShapes', {
152
+ target: {
153
+ tag: (_a = this.target) === null || _a === void 0 ? void 0 : _a.tag,
154
+ id: (_b = this.target) === null || _b === void 0 ? void 0 : _b.id,
155
+ className: (_c = this.target) === null || _c === void 0 ? void 0 : _c.className,
156
+ parent: {
157
+ tag: (_e = (_d = this.target) === null || _d === void 0 ? void 0 : _d.parent) === null || _e === void 0 ? void 0 : _e.tag,
158
+ id: (_g = (_f = this.target) === null || _f === void 0 ? void 0 : _f.parent) === null || _g === void 0 ? void 0 : _g.id,
159
+ },
160
+ },
161
+ pointer: pos,
162
+ offset,
163
+ renderPos: { x: pos.x + offset[0], y: pos.y + offset[1] },
164
+ size: { width, height },
165
+ style: { backgroundColor, stroke, color, padding, borderRadius, fontSize },
166
+ text,
167
+ });
144
168
  this.setStyle({
145
169
  fill: backgroundColor,
146
170
  stroke,
@@ -171,6 +195,7 @@ let Tooltip = class Tooltip extends di$1 {
171
195
  }
172
196
  show(pos = this.__.pointerPos) {
173
197
  this.clearShowHideTimers();
198
+ this.log('show', { pos, delay: this.config.showDelay, isShow: this.isShow });
174
199
  this.showTimerId = setTimeout(() => {
175
200
  this.createShapes(pos);
176
201
  this.showTimerId = null;
@@ -178,6 +203,7 @@ let Tooltip = class Tooltip extends di$1 {
178
203
  }
179
204
  hide(immediate = false) {
180
205
  this.clearShowHideTimers();
206
+ this.log('hide', { immediate, delay: this.config.hideDelay, isShow: this.isShow });
181
207
  if (immediate) {
182
208
  this.destroy();
183
209
  }
@@ -190,6 +216,7 @@ let Tooltip = class Tooltip extends di$1 {
190
216
  }
191
217
  update(pos) {
192
218
  this.clearShowHideTimers();
219
+ this.log('update', { pos, isShow: this.isShow });
193
220
  if (this.isShow) {
194
221
  this.createShapes(pos);
195
222
  }
@@ -230,6 +257,7 @@ Tooltip = __decorate([
230
257
  ], Tooltip);
231
258
 
232
259
  const defaultConfig = {
260
+ debug: false,
233
261
  reference: 'pointer',
234
262
  info: ['tag'],
235
263
  showType: 'value',
@@ -258,6 +286,11 @@ const defaultConfig = {
258
286
  };
259
287
 
260
288
  class TooltipPlugin {
289
+ log(...args) {
290
+ if (this.config.debug) {
291
+ console.log('[TooltipPlugin]', ...args);
292
+ }
293
+ }
261
294
  constructor(instance, config) {
262
295
  this.tooltipCache = new Map();
263
296
  this.includesTypeSet = new Set();
@@ -317,7 +350,8 @@ class TooltipPlugin {
317
350
  this.hideTooltip();
318
351
  return;
319
352
  }
320
- if (!this.handleAllowed(target)) {
353
+ const allowed = this.handleAllowed(target);
354
+ if (!allowed) {
321
355
  this.hideTooltip();
322
356
  return;
323
357
  }
@@ -344,16 +378,24 @@ class TooltipPlugin {
344
378
  const hasIncludesRule = this.includesTypeSet.size > 0;
345
379
  const hasExcludesRule = this.excludesTypeSet.size > 0;
346
380
  if (!hasIncludesRule && !hasExcludesRule) {
381
+ this.log('allowed', { target: target.tag, result: true, reason: 'no rules' });
347
382
  return true;
348
383
  }
349
384
  const matchesInclude = targetIdentifiers.some((id) => this.includesTypeSet.has(id));
350
385
  const matchesExclude = targetIdentifiers.some((id) => this.excludesTypeSet.has(id));
351
- if (matchesInclude)
386
+ if (matchesInclude) {
387
+ this.log('allowed', { target: target.tag, result: true, reason: 'matches include' });
352
388
  return true;
353
- if (matchesExclude)
389
+ }
390
+ if (matchesExclude) {
391
+ this.log('allowed', { target: target.tag, result: false, reason: 'matches exclude' });
354
392
  return false;
355
- if (hasIncludesRule)
393
+ }
394
+ if (hasIncludesRule) {
395
+ this.log('allowed', { target: target.tag, result: false, reason: 'has include rule but not matched' });
356
396
  return false;
397
+ }
398
+ this.log('allowed', { target: target.tag, result: true, reason: 'only exclude rule, not matched' });
357
399
  return true;
358
400
  }
359
401
  hideTooltip() {
@@ -377,12 +419,14 @@ class TooltipPlugin {
377
419
  });
378
420
  const cachedTooltip = this.tooltipCache.get(id);
379
421
  if (cachedTooltip && cachedTooltip.parent) {
422
+ this.log('tooltip update', { id, x: event.x, y: event.y });
380
423
  cachedTooltip.update({ x: event.x, y: event.y });
381
424
  }
382
425
  else {
383
426
  if (cachedTooltip) {
384
427
  this.tooltipCache.delete(id);
385
428
  }
429
+ this.log('tooltip create', { id, x: event.x, y: event.y, target: target.tag });
386
430
  const tooltip = new Tooltip({
387
431
  id,
388
432
  pointerPos: { x: event.x, y: event.y },
@@ -462,5 +506,5 @@ const flow = new m({
462
506
  height: 100,
463
507
  });
464
508
  app.tree.add(flow);
465
- new TooltipPlugin(app, { excludesType: ['Ellipse'], throughExcludes: true });
509
+ new TooltipPlugin(app, { excludesType: ['Ellipse'], throughExcludes: true, debug: true });
466
510
  console.log(app);
package/dist/index.cjs CHANGED
@@ -136,11 +136,35 @@ let Tooltip = class Tooltip extends di$1 {
136
136
  this.config = data.config;
137
137
  this.show();
138
138
  }
139
+ log(...args) {
140
+ var _a;
141
+ if ((_a = this.config) === null || _a === void 0 ? void 0 : _a.debug) {
142
+ console.log('[Tooltip]', ...args);
143
+ }
144
+ }
139
145
  createShapes(pos = this.__.pointerPos) {
146
+ var _a, _b, _c, _d, _e, _f, _g;
140
147
  this.clear();
141
148
  const { width, height, text } = handleTextStyle(this.target, this.config);
142
149
  const { backgroundColor, stroke, color, padding, borderRadius, fontSize, fontWeight, fontFamily, } = this.config.style;
143
150
  let offset = this.config.offset;
151
+ this.log('createShapes', {
152
+ target: {
153
+ tag: (_a = this.target) === null || _a === void 0 ? void 0 : _a.tag,
154
+ id: (_b = this.target) === null || _b === void 0 ? void 0 : _b.id,
155
+ className: (_c = this.target) === null || _c === void 0 ? void 0 : _c.className,
156
+ parent: {
157
+ tag: (_e = (_d = this.target) === null || _d === void 0 ? void 0 : _d.parent) === null || _e === void 0 ? void 0 : _e.tag,
158
+ id: (_g = (_f = this.target) === null || _f === void 0 ? void 0 : _f.parent) === null || _g === void 0 ? void 0 : _g.id,
159
+ },
160
+ },
161
+ pointer: pos,
162
+ offset,
163
+ renderPos: { x: pos.x + offset[0], y: pos.y + offset[1] },
164
+ size: { width, height },
165
+ style: { backgroundColor, stroke, color, padding, borderRadius, fontSize },
166
+ text,
167
+ });
144
168
  this.setStyle({
145
169
  fill: backgroundColor,
146
170
  stroke,
@@ -171,6 +195,7 @@ let Tooltip = class Tooltip extends di$1 {
171
195
  }
172
196
  show(pos = this.__.pointerPos) {
173
197
  this.clearShowHideTimers();
198
+ this.log('show', { pos, delay: this.config.showDelay, isShow: this.isShow });
174
199
  this.showTimerId = setTimeout(() => {
175
200
  this.createShapes(pos);
176
201
  this.showTimerId = null;
@@ -178,6 +203,7 @@ let Tooltip = class Tooltip extends di$1 {
178
203
  }
179
204
  hide(immediate = false) {
180
205
  this.clearShowHideTimers();
206
+ this.log('hide', { immediate, delay: this.config.hideDelay, isShow: this.isShow });
181
207
  if (immediate) {
182
208
  this.destroy();
183
209
  }
@@ -190,6 +216,7 @@ let Tooltip = class Tooltip extends di$1 {
190
216
  }
191
217
  update(pos) {
192
218
  this.clearShowHideTimers();
219
+ this.log('update', { pos, isShow: this.isShow });
193
220
  if (this.isShow) {
194
221
  this.createShapes(pos);
195
222
  }
@@ -230,6 +257,7 @@ Tooltip = __decorate([
230
257
  ], Tooltip);
231
258
 
232
259
  const defaultConfig = {
260
+ debug: false,
233
261
  reference: 'pointer',
234
262
  info: ['tag'],
235
263
  showType: 'value',
@@ -258,6 +286,11 @@ const defaultConfig = {
258
286
  };
259
287
 
260
288
  class TooltipPlugin {
289
+ log(...args) {
290
+ if (this.config.debug) {
291
+ console.log('[TooltipPlugin]', ...args);
292
+ }
293
+ }
261
294
  constructor(instance, config) {
262
295
  this.tooltipCache = new Map();
263
296
  this.includesTypeSet = new Set();
@@ -317,7 +350,8 @@ class TooltipPlugin {
317
350
  this.hideTooltip();
318
351
  return;
319
352
  }
320
- if (!this.handleAllowed(target)) {
353
+ const allowed = this.handleAllowed(target);
354
+ if (!allowed) {
321
355
  this.hideTooltip();
322
356
  return;
323
357
  }
@@ -344,16 +378,24 @@ class TooltipPlugin {
344
378
  const hasIncludesRule = this.includesTypeSet.size > 0;
345
379
  const hasExcludesRule = this.excludesTypeSet.size > 0;
346
380
  if (!hasIncludesRule && !hasExcludesRule) {
381
+ this.log('allowed', { target: target.tag, result: true, reason: 'no rules' });
347
382
  return true;
348
383
  }
349
384
  const matchesInclude = targetIdentifiers.some((id) => this.includesTypeSet.has(id));
350
385
  const matchesExclude = targetIdentifiers.some((id) => this.excludesTypeSet.has(id));
351
- if (matchesInclude)
386
+ if (matchesInclude) {
387
+ this.log('allowed', { target: target.tag, result: true, reason: 'matches include' });
352
388
  return true;
353
- if (matchesExclude)
389
+ }
390
+ if (matchesExclude) {
391
+ this.log('allowed', { target: target.tag, result: false, reason: 'matches exclude' });
354
392
  return false;
355
- if (hasIncludesRule)
393
+ }
394
+ if (hasIncludesRule) {
395
+ this.log('allowed', { target: target.tag, result: false, reason: 'has include rule but not matched' });
356
396
  return false;
397
+ }
398
+ this.log('allowed', { target: target.tag, result: true, reason: 'only exclude rule, not matched' });
357
399
  return true;
358
400
  }
359
401
  hideTooltip() {
@@ -377,12 +419,14 @@ class TooltipPlugin {
377
419
  });
378
420
  const cachedTooltip = this.tooltipCache.get(id);
379
421
  if (cachedTooltip && cachedTooltip.parent) {
422
+ this.log('tooltip update', { id, x: event.x, y: event.y });
380
423
  cachedTooltip.update({ x: event.x, y: event.y });
381
424
  }
382
425
  else {
383
426
  if (cachedTooltip) {
384
427
  this.tooltipCache.delete(id);
385
428
  }
429
+ this.log('tooltip create', { id, x: event.x, y: event.y, target: target.tag });
386
430
  const tooltip = new Tooltip({
387
431
  id,
388
432
  pointerPos: { x: event.x, y: event.y },
package/dist/index.esm.js CHANGED
@@ -134,11 +134,35 @@ let Tooltip = class Tooltip extends di$1 {
134
134
  this.config = data.config;
135
135
  this.show();
136
136
  }
137
+ log(...args) {
138
+ var _a;
139
+ if ((_a = this.config) === null || _a === void 0 ? void 0 : _a.debug) {
140
+ console.log('[Tooltip]', ...args);
141
+ }
142
+ }
137
143
  createShapes(pos = this.__.pointerPos) {
144
+ var _a, _b, _c, _d, _e, _f, _g;
138
145
  this.clear();
139
146
  const { width, height, text } = handleTextStyle(this.target, this.config);
140
147
  const { backgroundColor, stroke, color, padding, borderRadius, fontSize, fontWeight, fontFamily, } = this.config.style;
141
148
  let offset = this.config.offset;
149
+ this.log('createShapes', {
150
+ target: {
151
+ tag: (_a = this.target) === null || _a === void 0 ? void 0 : _a.tag,
152
+ id: (_b = this.target) === null || _b === void 0 ? void 0 : _b.id,
153
+ className: (_c = this.target) === null || _c === void 0 ? void 0 : _c.className,
154
+ parent: {
155
+ tag: (_e = (_d = this.target) === null || _d === void 0 ? void 0 : _d.parent) === null || _e === void 0 ? void 0 : _e.tag,
156
+ id: (_g = (_f = this.target) === null || _f === void 0 ? void 0 : _f.parent) === null || _g === void 0 ? void 0 : _g.id,
157
+ },
158
+ },
159
+ pointer: pos,
160
+ offset,
161
+ renderPos: { x: pos.x + offset[0], y: pos.y + offset[1] },
162
+ size: { width, height },
163
+ style: { backgroundColor, stroke, color, padding, borderRadius, fontSize },
164
+ text,
165
+ });
142
166
  this.setStyle({
143
167
  fill: backgroundColor,
144
168
  stroke,
@@ -169,6 +193,7 @@ let Tooltip = class Tooltip extends di$1 {
169
193
  }
170
194
  show(pos = this.__.pointerPos) {
171
195
  this.clearShowHideTimers();
196
+ this.log('show', { pos, delay: this.config.showDelay, isShow: this.isShow });
172
197
  this.showTimerId = setTimeout(() => {
173
198
  this.createShapes(pos);
174
199
  this.showTimerId = null;
@@ -176,6 +201,7 @@ let Tooltip = class Tooltip extends di$1 {
176
201
  }
177
202
  hide(immediate = false) {
178
203
  this.clearShowHideTimers();
204
+ this.log('hide', { immediate, delay: this.config.hideDelay, isShow: this.isShow });
179
205
  if (immediate) {
180
206
  this.destroy();
181
207
  }
@@ -188,6 +214,7 @@ let Tooltip = class Tooltip extends di$1 {
188
214
  }
189
215
  update(pos) {
190
216
  this.clearShowHideTimers();
217
+ this.log('update', { pos, isShow: this.isShow });
191
218
  if (this.isShow) {
192
219
  this.createShapes(pos);
193
220
  }
@@ -228,6 +255,7 @@ Tooltip = __decorate([
228
255
  ], Tooltip);
229
256
 
230
257
  const defaultConfig = {
258
+ debug: false,
231
259
  reference: 'pointer',
232
260
  info: ['tag'],
233
261
  showType: 'value',
@@ -256,6 +284,11 @@ const defaultConfig = {
256
284
  };
257
285
 
258
286
  class TooltipPlugin {
287
+ log(...args) {
288
+ if (this.config.debug) {
289
+ console.log('[TooltipPlugin]', ...args);
290
+ }
291
+ }
259
292
  constructor(instance, config) {
260
293
  this.tooltipCache = new Map();
261
294
  this.includesTypeSet = new Set();
@@ -315,7 +348,8 @@ class TooltipPlugin {
315
348
  this.hideTooltip();
316
349
  return;
317
350
  }
318
- if (!this.handleAllowed(target)) {
351
+ const allowed = this.handleAllowed(target);
352
+ if (!allowed) {
319
353
  this.hideTooltip();
320
354
  return;
321
355
  }
@@ -342,16 +376,24 @@ class TooltipPlugin {
342
376
  const hasIncludesRule = this.includesTypeSet.size > 0;
343
377
  const hasExcludesRule = this.excludesTypeSet.size > 0;
344
378
  if (!hasIncludesRule && !hasExcludesRule) {
379
+ this.log('allowed', { target: target.tag, result: true, reason: 'no rules' });
345
380
  return true;
346
381
  }
347
382
  const matchesInclude = targetIdentifiers.some((id) => this.includesTypeSet.has(id));
348
383
  const matchesExclude = targetIdentifiers.some((id) => this.excludesTypeSet.has(id));
349
- if (matchesInclude)
384
+ if (matchesInclude) {
385
+ this.log('allowed', { target: target.tag, result: true, reason: 'matches include' });
350
386
  return true;
351
- if (matchesExclude)
387
+ }
388
+ if (matchesExclude) {
389
+ this.log('allowed', { target: target.tag, result: false, reason: 'matches exclude' });
352
390
  return false;
353
- if (hasIncludesRule)
391
+ }
392
+ if (hasIncludesRule) {
393
+ this.log('allowed', { target: target.tag, result: false, reason: 'has include rule but not matched' });
354
394
  return false;
395
+ }
396
+ this.log('allowed', { target: target.tag, result: true, reason: 'only exclude rule, not matched' });
355
397
  return true;
356
398
  }
357
399
  hideTooltip() {
@@ -375,12 +417,14 @@ class TooltipPlugin {
375
417
  });
376
418
  const cachedTooltip = this.tooltipCache.get(id);
377
419
  if (cachedTooltip && cachedTooltip.parent) {
420
+ this.log('tooltip update', { id, x: event.x, y: event.y });
378
421
  cachedTooltip.update({ x: event.x, y: event.y });
379
422
  }
380
423
  else {
381
424
  if (cachedTooltip) {
382
425
  this.tooltipCache.delete(id);
383
426
  }
427
+ this.log('tooltip create', { id, x: event.x, y: event.y, target: target.tag });
384
428
  const tooltip = new Tooltip({
385
429
  id,
386
430
  pointerPos: { x: event.x, y: event.y },