Skip to content

Commit 27b1f7d

Browse files
committed
Add tests for radial plot dataprocessing
1 parent 9e62092 commit 27b1f7d

File tree

2 files changed

+637
-10
lines changed

2 files changed

+637
-10
lines changed

node/src/js/dataviz/radial-plot-dataprocessing.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ const color = colorFn(category);
1212
export function getColor(categories, colourList = d3.schemeAccent) {
1313
return d3.scaleOrdinal().domain(categories).range(colourList).unknown('#ccc')
1414
}
15-
/* Get the point at the bottom left of the category. Used as the start point of
16-
the line from category segments to category label */
15+
16+
/* Get the point at the bottom left of the category.
17+
18+
Used as the start point of the line from category segments to category label */
1719
export const catAnnotationPointInner = (categoryStartAngleMap) => (categoryId) => {
1820
const angle = categoryStartAngleMap[categoryId]
1921
const x = Math.sin(angle)
@@ -67,15 +69,15 @@ export const catAnnotationPointOuter = (categoryStartAngleMap) => (categoryId) =
6769
// return { x, y }
6870
// }
6971

70-
/* Calculates label position based on offset from y top/bottom */
72+
/* Calculates label position based on position in quadrant*/
7173
export const catAnnotationPointOuterLabel =
7274
(categoryStartAngleMap, catLabelWidthHeightMap, xPadding, yPadding, plotHeight) =>
7375
(categoryId) => {
7476
const angle = categoryStartAngleMap[categoryId] % fullCircleAngle
7577
const xSide = Math.sin(angle) > 0 ? 1 : -1
7678
const ySide = -Math.cos(angle) > 0 ? 1 : -1
7779

78-
const catsOnThisSide = Object.keys(categoryStartAngleMap)
80+
const catsInThisQuadrant = Object.keys(categoryStartAngleMap)
7981
.filter((catId) => {
8082
const inXSide = Math.sin(categoryStartAngleMap[catId]) > 0 ? 1 : -1
8183
const inYSide = -Math.cos(categoryStartAngleMap[catId]) > 0 ? 1 : -1
@@ -91,8 +93,9 @@ export const catAnnotationPointOuterLabel =
9193
: 1
9294
)
9395

94-
const thisCatIndex = catsOnThisSide.length - catsOnThisSide.indexOf(categoryId) - 1
95-
const preCatHeights = catsOnThisSide
96+
const thisCatIndex =
97+
catsInThisQuadrant.length - catsInThisQuadrant.indexOf(categoryId) - 1
98+
const preCatHeights = catsInThisQuadrant
9699
.slice(0, thisCatIndex)
97100
.reduce((acc, catId) => acc + catLabelWidthHeightMap[catId].height, 0)
98101

@@ -117,6 +120,10 @@ export const catAnnotationPointOuterLabel =
117120
skillPadding: number;
118121
arcPercent: number;
119122
arcStartOffset: number;
123+
labelXOffset = 1.1,
124+
labelYSpacing = 10,
125+
maxLabelWidth = 150,
126+
fontSize = 14,
120127
121128
The function returns a function that takes in the following parameters:
122129
skillsData: IDataItem[];
@@ -130,9 +137,10 @@ export const catAnnotationPointOuterLabel =
130137
color: string;
131138
132139
Category is an object with the following properties:
133-
id: string;
134-
skills: IDataItem[];
135-
color: string;
140+
skillsData: IDataItem[];
141+
levels: Level[];
142+
categories: Category[];
143+
groupedByCategory: Map<Category, IDataItem[]>;
136144
*/
137145
export const getArcsFn =
138146
({
@@ -226,7 +234,6 @@ export const getArcsFn =
226234
/* Function to get the distance from the center of the circle to a y value
227235
at the bottom of the level */
228236
const lvlHeight = d3
229-
// .scaleRadial() // Disabled so each level is the same depth
230237
.scaleLinear()
231238
.domain([minLvl, maxLvl + 1]) // Use max lvl + 1 as we need the top and bottom of each lvl
232239
.range([innerRadius, outerRadius])
@@ -329,6 +336,7 @@ export const getArcsFn =
329336
330337
The function takes in the following parameters:
331338
data: IDataItem[];
339+
colourList?: string[];
332340
333341
Where IDataItem is an object with the following properties:
334342
skill: string;

0 commit comments

Comments
 (0)