diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/graph.js | 5 | ||||
| -rw-r--r-- | src/utils/index.js | 20 | ||||
| -rw-r--r-- | src/views/Clock.js | 3 | ||||
| -rw-r--r-- | src/views/Detail.js | 10 | ||||
| -rw-r--r-- | src/views/Gallery.js | 3 |
5 files changed, 25 insertions, 16 deletions
diff --git a/src/graph.js b/src/graph.js index 3a0e8a1..7381f49 100644 --- a/src/graph.js +++ b/src/graph.js @@ -2,6 +2,7 @@ import * as THREE from "three"; import ForceGraph3D from "3d-force-graph"; import SpriteText from "three-spritetext"; import { union } from "./utils/set_utils.js"; +import { randint, choice, pad } from "./utils/index.js"; const IMG_SCALE = 16; const MAIN_IMG_SCALE = 80; @@ -20,7 +21,7 @@ export default function buildGraph({ db, objects, handlers }) { db.page.forEach((item, index) => { const node = { - title: index + 1 + " " + item.title, + title: pad(index + 1) + " " + item.title, id: index, data: item, groups: [], @@ -210,6 +211,4 @@ export default function buildGraph({ db, objects, handlers }) { // stars(); } -const randint = (limit) => Math.floor(Math.random() * limit); -const choice = (list) => list[randint(list.length)]; const commonGroups = (a, b) => union(a.groups, b.groups); diff --git a/src/utils/index.js b/src/utils/index.js new file mode 100644 index 0000000..ee9dae9 --- /dev/null +++ b/src/utils/index.js @@ -0,0 +1,20 @@ +/** + * Utility functions + */ + +export const rand = (n) => Math.random() * n; +export const randint = (limit) => Math.floor(Math.random() * limit); +export const choice = (list) => list[randint(list.length)]; + +export const mod = (n, m) => n - m * Math.floor(n / m); + +export const pad = (value) => (value < 10 ? "0" + value : value); + +export const capitalizeWord = (text = "") => + text ? text.charAt(0).toUpperCase() + text.slice(1) : ""; + +export const capitalize = (text = "") => + String(text || "") + .split(" ") + .map(capitalizeWord) + .join(" "); diff --git a/src/views/Clock.js b/src/views/Clock.js index a394b62..fe5039a 100644 --- a/src/views/Clock.js +++ b/src/views/Clock.js @@ -3,6 +3,7 @@ */ import React, { useState, useEffect } from "react"; +import { rand } from "../utils/index.js"; const clock = { width: "20vw", @@ -104,5 +105,3 @@ export default function Clock({ utc }) { // hour transform origin: 40 x 515 // 88 / 533 // minute transform origin: 37 x 622 // 72 x 740 // second transform origin: 11 x 751 // 24 x 980 - -const rand = (n) => Math.random() * n; diff --git a/src/views/Detail.js b/src/views/Detail.js index b1c4dcf..70f4561 100644 --- a/src/views/Detail.js +++ b/src/views/Detail.js @@ -7,6 +7,7 @@ import React from "react"; import Gallery from "./Gallery.js"; import Clocks from "./Clocks.js"; import Vimeo from "@u-wave/react-vimeo"; +import { pad } from "../utils/index.js"; export default function Detail({ node, visible, onClose }) { if (!node) { @@ -59,12 +60,3 @@ export default function Detail({ node, visible, onClose }) { </div> ); } - -const pad = (value) => (value < 10 ? "0" + value : value); -const capitalizeWord = (text = "") => - text ? text.charAt(0).toUpperCase() + text.slice(1) : ""; -const capitalize = (text = "") => - String(text || "") - .split(" ") - .map(capitalizeWord) - .join(" "); diff --git a/src/views/Gallery.js b/src/views/Gallery.js index c2bd62d..ec1b234 100644 --- a/src/views/Gallery.js +++ b/src/views/Gallery.js @@ -3,6 +3,7 @@ */ import React, { useState, useEffect } from "react"; +import { mod } from "../utils/index.js"; export default function Gallery({ images, visible }) { const hasItems = !!images?.length; @@ -71,5 +72,3 @@ export default function Gallery({ images, visible }) { </div> ); } - -const mod = (n, m) => n - m * Math.floor(n / m); |
