| 18 | id: 'annotation', |
| 19 | |
| 20 | beforeDatasetsDraw(chart, args, options) { |
| 21 | const { ctx, chartArea, scales } = chart; |
| 22 | const annotations = options.annotations || {}; |
| 23 | |
| 24 | if (!chartArea) return; |
| 25 | |
| 26 | ctx.save(); |
| 27 | |
| 28 | Object.keys(annotations).forEach(id => { |
| 29 | const annotation = annotations[id]; |
| 30 | if (!annotation || annotation.display === false) return; |
| 31 | |
| 32 | if (annotation.type === 'line') { |
| 33 | this.drawLine(ctx, chartArea, scales, annotation); |
| 34 | } |
| 35 | }); |
| 36 | |
| 37 | ctx.restore(); |
| 38 | }, |
| 39 | |
| 40 | drawLine(ctx, chartArea, scales, annotation) { |
| 41 | const { left, right, top, bottom } = chartArea; |