|
1 | | -window.setup = (id, dotnetConfig, jsonConfig) => { |
| 1 | +function crosshairLine(chart,evt,plugin) |
| 2 | +{ |
| 3 | + // https://www.youtube.com/watch?v=M3SOJJOf6L8 |
| 4 | + const { canvas, ctx, chartArea: {left, right, top, bottom}}=chart; |
| 5 | + |
| 6 | + chart.update("none"); |
| 7 | + |
| 8 | + if (plugin.cursor) { |
| 9 | + if (evt.offsetX >= left && evt.offsetX <= right && evt.offsetY <= bottom && evt.offsetY >= top) { |
| 10 | + canvas.style.cursor = plugin.cursor; |
| 11 | + } else |
| 12 | + canvas.style.cursor = "default"; |
| 13 | + } |
| 14 | + |
| 15 | + if (plugin.vertical && evt.offsetX>=left && evt.offsetX<=right) { |
| 16 | + let line = plugin.vertical; |
| 17 | + |
| 18 | + ctx.save(); |
| 19 | + ctx.beginPath(); |
| 20 | + ctx.moveTo(evt.offsetX, top); |
| 21 | + ctx.lineTo(evt.offsetX, bottom); |
| 22 | + ctx.lineWidth = line.width; |
| 23 | + if (line.color) |
| 24 | + ctx.strokeStyle = line.color; |
| 25 | + if (line.dash) |
| 26 | + ctx.setLineDash(line.dash); |
| 27 | + ctx.stroke(); |
| 28 | + ctx.restore(); |
| 29 | + } |
| 30 | + |
| 31 | + if (plugin.horizontal && evt.offsetY<=bottom && evt.offsetY>=top) { |
| 32 | + let line = plugin.horizontal; |
| 33 | + |
| 34 | + ctx.save(); |
| 35 | + ctx.beginPath(); |
| 36 | + ctx.moveTo(left, evt.offsetY); |
| 37 | + ctx.lineTo(right, evt.offsetY); |
| 38 | + ctx.lineWidth = line.width; |
| 39 | + if (line.color) |
| 40 | + ctx.strokeStyle = line.color; |
| 41 | + if (line.dash) |
| 42 | + ctx.setLineDash(line.dash); |
| 43 | + ctx.stroke(); |
| 44 | + ctx.restore(); |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +window.setup = (id, dotnetConfig, jsonConfig) => { |
2 | 49 | document.getElementById("chartcontainer" + id).style.display = 'none'; |
3 | 50 | document.getElementById("chartcontainer" + id).innerHTML = ' '; |
4 | 51 | document.getElementById("chartcontainer" + id).innerHTML = '<canvas id="' + id + '"></canvas>'; |
|
14 | 61 | }; |
15 | 62 | } |
16 | 63 |
|
| 64 | + let crosshair_plugin = config?.options?.plugins?.crosshair; |
| 65 | + if (config?.options?.plugins?.crosshair) |
| 66 | + { |
| 67 | + config.options.plugins.crosshair = undefined; |
| 68 | + } |
| 69 | + |
17 | 70 | if (config?.options?.hasOnHoverAsync) { |
18 | 71 | config.options.hasOnHoverAsync = undefined; |
19 | 72 | config.options.onHover = function (evt, activeElements, ch) { |
|
29 | 82 | } |
30 | 83 |
|
31 | 84 | var chart = new Chart(context2d, config); |
| 85 | + if (crosshair_plugin) { |
| 86 | + chart.canvas.addEventListener("mousemove", (evt) => { |
| 87 | + crosshairLine(chart, evt,crosshair_plugin); |
| 88 | + }); |
| 89 | + } |
32 | 90 |
|
33 | 91 | chart.options.onClick = function (event, array) { |
34 | 92 | var rtn = -1; |
|
0 commit comments