-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: alterations after review and improved code
- Loading branch information
1 parent
18e45e7
commit 5e67a79
Showing
2 changed files
with
31 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Animation, Chart } from 'chart.js'; | ||
|
||
interface DataSet { | ||
data: number[]; | ||
borderWidth: number; | ||
borderColor: string; | ||
label: string; | ||
} | ||
|
||
export const annotateLineEnd = (animation: Animation & { chart?: Chart }) => { | ||
const { chart } = animation; | ||
if (!chart) { | ||
return; | ||
} | ||
const { ctx } = chart; | ||
|
||
chart.data.datasets.forEach((dataset: DataSet, index: number) => { | ||
const meta = chart.getDatasetMeta(index); | ||
const [lastElement] = meta.data.slice(-1); | ||
const { x, y } = lastElement.getProps(['x', 'y']); | ||
ctx.fillStyle = dataset.borderColor; | ||
ctx.font = '14px Arial'; | ||
ctx.fillText(dataset.label, x + 10, y); | ||
}); | ||
}; |