Skip to content

Commit ea302ab

Browse files
docs(fuzzy-viz): update/fix readme code examples
1 parent 6888d2d commit ea302ab

2 files changed

Lines changed: 31 additions & 27 deletions

File tree

packages/fuzzy-viz/README.md

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ For Node.js REPL:
6565
const fuzzyViz = await import("@thi.ng/fuzzy-viz");
6666
```
6767

68-
Package sizes (brotli'd, pre-treeshake): ESM: 1.01 KB
68+
Package sizes (brotli'd, pre-treeshake): ESM: 1.00 KB
6969

7070
## Dependencies
7171

@@ -88,19 +88,18 @@ variable](https://github.com/thi-ng/umbrella/tree/develop/packages/fuzzy#linguis
8888

8989
![fuzzy set visualization of the example l-var](https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/fuzzy/temperature-lvar-2.svg)
9090

91-
```ts
91+
```ts tangle:export/readme-svg.ts
92+
import { invSigmoid, sigmoid, trapezoid, variable } from "@thi.ng/fuzzy";
9293
import { varToSvg } from "@thi.ng/fuzzy-viz";
94+
import { writeFileSync } from "fs";
9395

9496
// temperature sets (in celsius)
95-
const temp = variable(
96-
[-20, 40],
97-
{
98-
freezing: invSigmoid(0, 2),
99-
cold: trapezoid(-1, 2, 16, 20),
100-
warm: trapezoid(15, 20, 30, 34),
101-
hot: sigmoid(32, 2)
102-
}
103-
);
97+
const temp = variable([-20, 40], {
98+
freezing: invSigmoid(0, 2),
99+
cold: trapezoid(-1, 2, 16, 20),
100+
warm: trapezoid(15, 20, 30, 34),
101+
hot: sigmoid(32, 2),
102+
});
104103

105104
// generate & write SVG file
106105
writeFileSync("temperature.svg", varToSvg(temp, { samples: 200 }));
@@ -130,10 +129,13 @@ accumulate. If re-using the instrumented strategy for multiple `defuzz()`
130129
invocations, it's highly recommended to clear any previous results using
131130
`.clear()`.
132131

133-
```ts
132+
```ts tangle:export/readme-ascii.ts
133+
import { centroidStrategy, gaussian } from "@thi.ng/fuzzy";
134+
import { fuzzySetToAscii, instrumentStrategy } from "@thi.ng/fuzzy-viz";
135+
134136
const strategy = instrumentStrategy(
135-
cogStrategy({ samples: 1000 }),
136-
fuzzySetToAscii({ width: 40, height: 8 })
137+
centroidStrategy({ samples: 1000 }),
138+
fuzzySetToAscii({ width: 40, height: 8 })
137139
);
138140

139141
// apply strategy as normal (well, usually done via defuzz())

packages/fuzzy-viz/tpl.readme.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,18 @@ variable](https://github.com/thi-ng/umbrella/tree/develop/packages/fuzzy#linguis
3737

3838
![fuzzy set visualization of the example l-var](https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/fuzzy/temperature-lvar-2.svg)
3939

40-
```ts
40+
```ts tangle:export/readme-svg.ts
41+
import { invSigmoid, sigmoid, trapezoid, variable } from "@thi.ng/fuzzy";
4142
import { varToSvg } from "@thi.ng/fuzzy-viz";
43+
import { writeFileSync } from "fs";
4244

4345
// temperature sets (in celsius)
44-
const temp = variable(
45-
[-20, 40],
46-
{
47-
freezing: invSigmoid(0, 2),
48-
cold: trapezoid(-1, 2, 16, 20),
49-
warm: trapezoid(15, 20, 30, 34),
50-
hot: sigmoid(32, 2)
51-
}
52-
);
46+
const temp = variable([-20, 40], {
47+
freezing: invSigmoid(0, 2),
48+
cold: trapezoid(-1, 2, 16, 20),
49+
warm: trapezoid(15, 20, 30, 34),
50+
hot: sigmoid(32, 2),
51+
});
5352

5453
// generate & write SVG file
5554
writeFileSync("temperature.svg", varToSvg(temp, { samples: 200 }));
@@ -79,10 +78,13 @@ accumulate. If re-using the instrumented strategy for multiple `defuzz()`
7978
invocations, it's highly recommended to clear any previous results using
8079
`.clear()`.
8180

82-
```ts
81+
```ts tangle:export/readme-ascii.ts
82+
import { centroidStrategy, gaussian } from "@thi.ng/fuzzy";
83+
import { fuzzySetToAscii, instrumentStrategy } from "@thi.ng/fuzzy-viz";
84+
8385
const strategy = instrumentStrategy(
84-
cogStrategy({ samples: 1000 }),
85-
fuzzySetToAscii({ width: 40, height: 8 })
86+
centroidStrategy({ samples: 1000 }),
87+
fuzzySetToAscii({ width: 40, height: 8 })
8688
);
8789

8890
// apply strategy as normal (well, usually done via defuzz())

0 commit comments

Comments
 (0)