Skip to content

Commit

Permalink
Improved uuid generation, neater return of donut callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
graphieros committed Jan 23, 2024
1 parent e368090 commit 94a4398
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion savyg/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "savyg",
"private": false,
"version": "1.1.8",
"version": "1.1.9",
"description": "A savvy library to create svg elements and charts with ease",
"author": "Alec Lloyd Probert",
"repository": {
Expand Down
29 changes: 25 additions & 4 deletions savyg/src/utils_chart_donut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,17 +431,37 @@ export function chartDonut({
function clickArc(index: number) {
if (callbacks?.onClickArc) {
return callbacks?.onClickArc({
arc: arcs[index],
item: formattedDataset[index]
arc: {
"stroke-width": arcs[index]["stroke-width"],
arcMidpoint: findArcMidpoint(arcs[index].path),
color: arcs[index].color,
cx: arcs[index].cx,
cy: arcs[index].cy,
name: arcs[index].name,
path: arcs[index].path,
proportion: arcs[index].proportion,
uid: arcs[index].uid,
value: arcs[index].value,
}
})
}
}

function hoverArc(index: number) {
if (callbacks?.onHoverArc) {
return callbacks?.onHoverArc({
arc: arcs[index],
item: formattedDataset[index]
arc: {
"stroke-width": arcs[index]["stroke-width"],
arcMidpoint: findArcMidpoint(arcs[index].path),
color: arcs[index].color,
cx: arcs[index].cx,
cy: arcs[index].cy,
name: arcs[index].name,
path: arcs[index].path,
proportion: arcs[index].proportion,
uid: arcs[index].uid,
value: arcs[index].value,
},
})
}
}
Expand Down Expand Up @@ -624,6 +644,7 @@ export function chartDonut({
arcs: arcs.map((a: any, i: number) => {
return {
pathElement: a.path,
arcMidPoint: findArcMidpoint(a.path),
name: formattedDataset[i].name,
color: formattedDataset[i].color,
uid: formattedDataset[i].uid,
Expand Down
4 changes: 3 additions & 1 deletion savyg/src/utils_common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ export function ratioToMax(value: number, max: number) {
export function createUid() {
const cryptoArray = new Uint8Array(16);
window.crypto.getRandomValues(cryptoArray);

cryptoArray[6] = (cryptoArray[6] & 0x0F) | 0x40;
cryptoArray[8] = (cryptoArray[8] & 0x3F) | 0x80;
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
.replace(/[xy]/g, function (c, index) {
const r = cryptoArray[index >> 1];
Expand All @@ -114,6 +115,7 @@ export function createUid() {
});
}


export function rotateMatrix(x: number) {
return [
[Math.cos(x), -Math.sin(x)],
Expand Down

0 comments on commit 94a4398

Please sign in to comment.