Skip to content

Commit

Permalink
add possibiltiy to use icons
Browse files Browse the repository at this point in the history
  • Loading branch information
chrishrb committed May 24, 2024
1 parent fc76bf1 commit 45f5ede
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 23 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ libraries is its unique feature that allows users to customize the number of rin
* integrate in your own code by only installing and using this library
* variable number of rings
* variable number of slices / quadrants
* use [nerdfonts icons](https://www.nerdfonts.com/cheat-sheet)

## 📦 Getting started

Expand Down Expand Up @@ -84,6 +85,24 @@ libraries is its unique feature that allows users to customize the number of rin

More examples are provided under the `src` folder in this repository.

##  Icons

You can also use icons instead of numbers for the blips. Go to [nerdfonts](https://www.nerdfonts.com/cheat-sheet) and choose
an icon. Afterwards copy the hexcode to your config and add the `\u` as a prefix. So in this example the hexcode of the react logo is
`e7ba`, add the prefix `\u` and paste it into the blips configuration. **Important: Only the 4 digit hexcodes are working**:

```typescript
...
slices: [
{
name: "Frameworks & Ecosystems",
blipsByRing: {
adopt: [{ name: "React", icon: "\ue7ba" }],
},
},
...
```
## ⚡️ Local Development
1. Install dependencies with pnpm
Expand Down
1 change: 0 additions & 1 deletion lib/Techradar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import "./radar.css";
import { useEffect, useRef } from "react";
import createTechradar from "./createTechradar";
import { TechradarData, TechradarOptions } from "./types";
Expand Down
39 changes: 22 additions & 17 deletions lib/createTechradar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,14 @@ const createTechradar = (
.append("text")
.style("pointer-events", "none")
.attr("dy", 4)
.attr("class", (blip) => blip.icon != null ? "nf" : "")
.attr("font-family", "Arial, Helvetica")
.attr("font-size", "10px")
.attr("font-size", `${vizData.global.blipRadius}px`)
.attr("pointer-events", "none")
.attr("user-select", "none")
.attr("text-anchor", "middle")
.attr("fill", blip => vizData.rings[blip.ringIndex].textColor)
.text(blip => blip.blipIndex);
.text(blip => blip.icon ? blip.icon : blip.blipIndex);

let tooltip: Tooltip;
if (blipTooltipEnabled) {
Expand Down Expand Up @@ -169,7 +170,7 @@ const createTechradar = (
.selectAll(`#slice-${sliceIndex}`)
.append("text")
.attr("font-family", "Arial, Helvetica")
.attr("font-size", "18px")
.style("font-size", `${vizData.global.blipRadius + 6}px`)
.attr("font-weight", "bold")
.attr("fill", vizData.global.mainColor)
.text(vizData.slices[sliceIndex].name);
Expand All @@ -186,7 +187,7 @@ const createTechradar = (
.selectAll(`#slice-${sliceIndex}`)
.append("text")
.attr("font-family", "Arial, Helvetica")
.attr("font-size", "12px")
.style("font-size", `${vizData.global.blipRadius + 1}px`)
.attr("font-weight", "bold")
.attr("fill", vizData.rings[ringIndex].color)
.attr("dx", counter % 2 === 0 ? leftCoords.x : rightCoords.x)
Expand All @@ -204,19 +205,10 @@ const createTechradar = (
.attr("href", blip => blip.url ? blip.url : "#")
.attr("target", blip => blip.url && options?.linksInNewTabs ? "_blank" : null)
.append("text")
.style("font-family", "Arial, Helvetica")
.style("font-size", "11px")
.attr("font-family", "Arial, Helvetica")
.style("font-size", `${vizData.global.blipRadius}px`)
.attr("id", blip => `legendItem-${blip.blipIndex}`)
.attr("fill", vizData.global.mainColor)
.attr("dx", counter % 2 === 0 ? leftCoords.x : rightCoords.x)
.attr("dy", () => {
const step = 15;
if (counter % 2 === 0) {
return leftCoords.y += step;
} else {
return rightCoords.y += step;
}
})
.on("mouseover", (_, blip) => {
highlightLegendItem(blip, vizData.rings[ringIndex].color)

Expand All @@ -230,7 +222,20 @@ const createTechradar = (
unhighlightLegendItem(blip, vizData.global.mainColor)
tooltip.hide();
})
.text(blip => `${blip.blipIndex}. ${blip.name}`);
.attr("dx", counter % 2 === 0 ? leftCoords.x : rightCoords.x)
.attr("dy", () => {
const step = 15;
if (counter % 2 === 0) {
return leftCoords.y += step;
} else {
return rightCoords.y += step;
}
})
.attr("class", (blip) => blip.icon != null ? "nf" : "")
.text(blip => `${blip.icon ? blip.icon : blip.blipIndex}. `)
.append("tspan")
.style("font-family", "Arial, Helvetica")
.text(blip => blip.name)

if (counter % 2 === 0) {
leftCoords.y += 30;
Expand Down Expand Up @@ -258,7 +263,7 @@ const createTechradar = (
.attr("xml:space", "preserve")
.style("font-family", "Arial, Helvetica")
.attr("fill", vizData.global.mainColor)
.style("font-size", "10px");
.attr("font-size", `${vizData.global.blipRadius}px`)

// Position techradar and labels
techradar
Expand Down
2 changes: 1 addition & 1 deletion lib/generateTechradarVizData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const generateTechradarVizData = (
data: TechradarData,
options?: TechradarVizOptions
): TechradarVizData => {
const { radarSize = 900, blipRadius = 10, colorScheme = 'white' } = options || {};
const { radarSize = 900, blipRadius = 12, colorScheme = 'white' } = options || {};
const mainColor = colorScheme === 'white' ? 'black' : 'white';

//setup base scales
Expand Down
1 change: 1 addition & 0 deletions lib/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Techradar } from "./Techradar";
import "./radar.css";

import type {
TechradarData,
Expand Down
1 change: 1 addition & 0 deletions lib/radar.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "https://www.nerdfonts.com/assets/css/webfont.css"
2 changes: 2 additions & 0 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export type TechradarBlipData = {
name: string,
url?: string,
state?: TechradarBlipState,
icon?: string,
};

export type TechradarSliceData = {
Expand Down Expand Up @@ -50,6 +51,7 @@ export type TechradarBlipVizData = TechradarBlipData & {
ringIndex: number,
x: number,
y: number,
icon?: string,
};

export type Anchor = {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@chrishrb/techradar",
"description": "Create your own technology radar, with flexibility to customize the radar, the quadrants and the rings.",
"version": "0.1.4",
"version": "0.1.5",
"private": false,
"prepublishOnly": "pnpm run build",
"type": "module",
Expand Down
1 change: 1 addition & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ function App() {
return (
<>
<div style={{ paddingLeft: "20px" }}>
<i className="fa-brands fa-facebook"></i>
<div style={{ paddingBottom: "10px" }}>
<h2 style={{ fontFamily: "Arial, Helvetica", fontSize: "20px", fontWeight: "bold", marginBottom: "0px" }}>Choose an example:</h2>
<button style={{ margin: "5px", marginLeft: "0px" }} onClick={() => setExample(example1)}>Example 1</button>
Expand Down
6 changes: 3 additions & 3 deletions src/examples/example1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ const data: TechradarData = {
{
name: "Frameworks & Ecosystems",
blipsByRing: {
adopt: [{ name: "React" }],
adopt: [{ name: "React", icon: "\ue7ba" }],
trial: [{ name: "Vue" }, { name: "Angular (2+)" }],
hold: [{ name: "AngularJS (1)" }, { name: "jQuery" }],
},
},
{
name: "Linting & Formatting",
blipsByRing: {
adopt: [{ name: "ESLint" }, { name: "Prettier" }],
adopt: [{ name: "ESLint", icon: "\ue655" }, { name: "Prettier" }],
assess: [{ name: "AirBNB Eslint Config" }],
},
},
Expand All @@ -34,7 +34,7 @@ const data: TechradarData = {
{
name: "Infrastucture",
blipsByRing: {
adopt: [{ name: "AWS CodePipeline" }],
adopt: [{ name: "AWS CodePipeline", icon: "\uf0ef" }],
trial: [{ name: "Jenkins" }],
hold: [{ name: "Bamboo", state: 'down' }, { name: "TeamCity" }],
},
Expand Down

0 comments on commit 45f5ede

Please sign in to comment.