Published
Edited
Jul 29, 2021
Importers
Also listed in…
Electronics
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
digits = (x) => { // returns a string of digit()s, one for each digit in its input array.
return (x.length < 4 ? "<span>&nbsp;</span>" : "") + x.map(k => digit(k)).join("") // leading blanks
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
precision
Insert cell
precisions
Insert cell
Insert cell
Insert cell
Insert cell
precision = precisions
Insert cell
precisions = [
{ value: 2, tolerance: .4000, background: "none" },
{ value: 2, tolerance: .2000, background: "silver" },
{ value: 2, tolerance: .1000, background: "gold" },
{ value: 2, tolerance: .0500, background: "red" },
{ value: 3, tolerance: .0200, background: "brown" },
{ value: 3, tolerance: .0100, background: "green" },
{ value: 3, tolerance: .0050, background: "blue" },
{ value: 3, tolerance: .0025, background: "violet" },
{ value: 3, tolerance: .0010, background: "grey" },
].map((k, index) => ({index, ...k, i: colorcodes.findIndex(c => c.tolerance === k.tolerance)}))
Insert cell
basecodes = [
{ color: null , multiplier: null, tolerance: .2000, precision: 2 , code: null, letter: "M" , },
{ color: "pink" , multiplier: -3 , tolerance: null , precision: null, code: "PK", letter: null, },
{ color: "silver", multiplier: -2 , tolerance: .1000, precision: 2 , code: "SR", letter: "K" , },
{ color: "gold" , multiplier: -1 , tolerance: .0500, precision: 2 , code: "GD", letter: "J" , },
{ color: "black" , multiplier: 0 , tolerance: null , precision: null, code: "BK", letter: null, },
{ color: "brown" , multiplier: +1 , tolerance: .0100, precision: 2 , code: "BN", letter: "F" , },
{ color: "red" , multiplier: +2 , tolerance: .0200, precision: 3 , code: "RD", letter: "G" , },
{ color: "orange", multiplier: +3 , tolerance: .0005, precision: 3 , code: "OG", letter: "W" , },
{ color: "yellow", multiplier: +4 , tolerance: .0002, precision: 3 , code: "YE", letter: "P" , },
{ color: "green" , multiplier: +5 , tolerance: .0050, precision: 3 , code: "GN", letter: "D" , },
{ color: "blue" , multiplier: +6 , tolerance: .0025, precision: 3 , code: "BU", letter: "C" , },
{ color: "violet", multiplier: +7 , tolerance: .0010, precision: 3 , code: "VT", letter: "B" , },
{ color: "grey" , multiplier: +8 , tolerance: .0001, precision: 3 , code: "GY", letter: "L" , },
{ color: "white" , multiplier: +9 , tolerance: null , precision: null, code: null, letter: null, },
]
Insert cell
Insert cell
colorcodes = basecodes.map((k, e) => ({e, value: k.multiplier >= 0 ? k.multiplier : null, ...k}))
Insert cell
aap = colorcodes.reduce(
(accu, code) => ({
...accu,
[code.multiplier]: code,
}),
{}
)
Insert cell
tolerances = [
{color: "none" , precision: 2, tolerance: .4000, letter: "M",},
{color: "silver" , precision: 2, tolerance: .2000, letter: "K",},
{color: "gold" , precision: 2, tolerance: .1000, letter: "J",},
{color: "red" , precision: 2, tolerance: .0500, letter: "G",},
{color: "brown" , precision: 3, tolerance: .0200, letter: "F",},
{color: "green" , precision: 3, tolerance: .0100, letter: "D",},
{color: "blue" , precision: 3, tolerance: .0050, letter: "C",},
{color: "violet" , precision: 3, tolerance: .0025, letter: "B",},
{color: "orange" , precision: 3, tolerance: .0010, letter: "W",},
{color: "yellow" , precision: 3, tolerance: .0005, letter: "P",},
{color: "grey" , precision: 3, tolerance: .0002, letter: "L (A)",},
].map((k, i) => ({...k, E: E(i)}))
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// function z(seriesIndex, scaleIndex, precisionTable = precision) {
// // Assistants and shortcuts.

// // const precision = precisionTable[seriesIndex]

// // const resolution = factor(precisionTable.length - 1) // Total number of distinct values in the scale
// // const scaleFraction = scaleIndex / resolution // Where are we on the scale, exactly?
// // const blockCount = factor(seriesIndex)
// // const blockSize = resolution / blockCount
// // const blockIndex = scaleIndex / blockSize | 0 // The block we’re in.
// // const blockFraction = blockIndex / blockCount

// return {
// // e: `E${blockCount}`,
// // tolerance: 1 / blockCount,
// // seriesIndex,
// // precision,

// // resolution,
// // blockCount,
// // blockSize,
// // blockIndex,
// // blockFraction,

// // scaleIndex,
// // scaleFraction,

// official: valuator({
// e: seriesIndex,
// index: scaleIndex,
// colorcodes,
// tolerances,
// precision: precisionTable[seriesIndex],
// official: true
// })
// }
// }
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
v
Insert cell
function valuator({e, index, multiplier, tolerances, resolution = E(max), official = true} = {}) {
const series = E(e)
const {tolerance, precision} = tolerances[e]
const sector = (index / two(6 - e))|0
const raw = ten(sector / series)
const initial = +raw.toPrecision(precision)
const base = officialize({series: e, initial, official})
const integer = Math.round(ten(precision - 1) * base)
const factor = multiplier + precision - 1
const string = (base * Math.pow(10, factor)).toPrecision(precision)
const value = +string
const d = +((tolerance * value).toPrecision(precision))
const delta = si(d, 0)
const percentage = 100 * tolerance + "%"
const bands = [...`${integer}`, multiplier, e].map(k => +k)
const multiple = si(ten(multiplier), 0)
return ({
e,
max,
resolution,
index,
series,
tolerance,
delta,
percentage,
sector,
raw,
initial,
official,
base,
precision,
integer,
multiplier,
multiple,
factor,
value,
si: si(value, precision),
string,
bands,
range: ({min: value + d, max: value - d}),
E,
ten,
two,
Value: base,
})
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more