mirror of
https://github.com/System-End/github-readme-stats.git
synced 2026-04-19 19:55:16 +00:00
Top languages card render test: move repeated code into helper function (#2718)
This commit is contained in:
parent
d59a80599f
commit
6d45f89c9e
1 changed files with 21 additions and 18 deletions
|
|
@ -39,6 +39,19 @@ const langs = {
|
|||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieve number array from SVG path definition string.
|
||||
*
|
||||
* @param {string} d SVG path definition string.
|
||||
* @return {number[]} Resulting numbers array.
|
||||
*/
|
||||
const getNumbersFromSvgPathDefinitionAttribute = (d) => {
|
||||
return d
|
||||
.split(" ")
|
||||
.filter((x) => !isNaN(x))
|
||||
.map((x) => parseFloat(x));
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieve the language percentage from the donut chart SVG.
|
||||
*
|
||||
|
|
@ -48,10 +61,7 @@ const langs = {
|
|||
* @returns {number} The percentage of the language.
|
||||
*/
|
||||
const langPercentFromDonutLayoutSvg = (d, centerX, centerY) => {
|
||||
const dTmp = d
|
||||
.split(" ")
|
||||
.filter((x) => !isNaN(x))
|
||||
.map((x) => parseFloat(x));
|
||||
const dTmp = getNumbersFromSvgPathDefinitionAttribute(d);
|
||||
const endAngle =
|
||||
cartesianToPolar(centerX, centerY, dTmp[0], dTmp[1]).angleInDegrees + 90;
|
||||
let startAngle =
|
||||
|
|
@ -69,10 +79,7 @@ const langPercentFromDonutLayoutSvg = (d, centerX, centerY) => {
|
|||
* @returns {number} The percentage of the language.
|
||||
*/
|
||||
const langPercentFromPieLayoutSvg = (d, centerX, centerY) => {
|
||||
const dTmp = d
|
||||
.split(" ")
|
||||
.filter((x) => !isNaN(x))
|
||||
.map((x) => parseFloat(x));
|
||||
const dTmp = getNumbersFromSvgPathDefinitionAttribute(d);
|
||||
const startAngle = cartesianToPolar(
|
||||
centerX,
|
||||
centerY,
|
||||
|
|
@ -504,11 +511,9 @@ describe("Test renderTopLanguages", () => {
|
|||
"size",
|
||||
"40",
|
||||
);
|
||||
const d = queryAllByTestId(document.body, "lang-donut")[0]
|
||||
.getAttribute("d")
|
||||
.split(" ")
|
||||
.filter((x) => !isNaN(x))
|
||||
.map((x) => parseFloat(x));
|
||||
const d = getNumbersFromSvgPathDefinitionAttribute(
|
||||
queryAllByTestId(document.body, "lang-donut")[0].getAttribute("d"),
|
||||
);
|
||||
const center = { x: d[7], y: d[7] };
|
||||
const HTMLLangPercent = langPercentFromDonutLayoutSvg(
|
||||
queryAllByTestId(document.body, "lang-donut")[0].getAttribute("d"),
|
||||
|
|
@ -579,11 +584,9 @@ describe("Test renderTopLanguages", () => {
|
|||
"40",
|
||||
);
|
||||
|
||||
const d = queryAllByTestId(document.body, "lang-pie")[0]
|
||||
.getAttribute("d")
|
||||
.split(" ")
|
||||
.filter((x) => !isNaN(x))
|
||||
.map((x) => parseFloat(x));
|
||||
const d = getNumbersFromSvgPathDefinitionAttribute(
|
||||
queryAllByTestId(document.body, "lang-pie")[0].getAttribute("d"),
|
||||
);
|
||||
const center = { x: d[0], y: d[1] };
|
||||
const HTMLLangPercent = langPercentFromPieLayoutSvg(
|
||||
queryAllByTestId(document.body, "lang-pie")[0].getAttribute("d"),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue