Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function trianglify (_opts) {
const opts = {...defaultOptions, ..._opts}
// standard randomizer, used for point gen and layout
const rand = seedrandom(opts.seed)
const randomFromPalette = () => {
if (opts.palette instanceof Array) {
return opts.palette[Math.floor(rand()*opts.palette.length)]
}
const keys = Object.keys(opts.palette);
return opts.palette[keys[Math.floor(rand()*keys.length)]]
}
// The first step here is to set up our color scales for the X and Y axis.
// First, munge the shortcut options like 'random' or 'match' into real color
// arrays. Then, set up a Chroma scale in the appropriate color space.
const processColorOpts = (colorOpt) => {
switch (true) {
case Array.isArray(colorOpt):
return colorOpt
function getCurrentTime(): AbstractValue | NumberValue {
if (realm.useAbstractInterpretation) {
return AbstractValue.createTemporalFromTemplate(realm, buildDateNowSrc, NumberValue, [], {
isPure: true,
skipInvariant: true,
});
} else {
let newNow = Date.now();
if (realm.strictlyMonotonicDateNow && lastNow >= newNow) {
if (!offsetGenerator) offsetGenerator = seedrandom(0);
// certain behaviors in the test262 test suite can only be (reliably) triggered if Date.now() is strictly monotonically increasing
// TODO #1004: Set the strictlyMonotonicDateNow option on the realm in the test262 test runner, fix the issues that will come up in the tests, and remove this comment.
newNow = lastNow + 1 + Math.floor(offsetGenerator() * 500);
}
lastNow = newNow;
return new NumberValue(realm, newNow);
}
}
fontStyle,
fontSizes,
fontWeight,
padding,
rotations,
rotationAngles,
spiral,
scale,
} = mergedOptions;
const sortedWords = words
.concat()
.sort((x, y) => descending(x.value, y.value))
.slice(0, maxWords);
const random = deterministic ? seedrandom('deterministic') : seedrandom();
const layout = cloud()
.size(size)
.padding(padding)
.words(sortedWords)
.rotate(() => {
if (rotations === undefined) {
// default rotation algorithm
return (~~(random() * 6) - 3) * 30;
} else {
return rotate(rotations, rotationAngles, random);
}
})
.spiral(spiral)
.random(random)
.text(getText)
test('Should not cause stack overflow for large input', () => {
const randomNumberGenerator = randomLogNormal.source(seedRandom('abc'))();
const size = 10000;
const data = [];
for (let i = 0; i < size; i += 1) {
const datum = {
value: Math.ceil(randomNumberGenerator() * 10000),
};
data.push(datum);
}
expect(() => entry(data, {x0: 0, y0: 0, x1: 1000, y1: 1000})).not.toThrow();
});
const rng = () => {
return seedrandom('shawarma');
};
function e7(seed?: string) {
const random = seed ? seedrandom(`${seed}0`) : Math.random;
const d0 = (random() * 0xffffffff) | 0;
const d1 = (random() * 0xffffffff) | 0;
const d2 = (random() * 0xffffffff) | 0;
const d3 = (random() * 0xffffffff) | 0;
return `${lut[d0 & 0xff] +
lut[(d0 >> 8) & 0xff] +
lut[(d0 >> 16) & 0xff] +
lut[(d0 >> 24) & 0xff]}-${lut[d1 & 0xff]}${lut[(d1 >> 8) & 0xff]}-${
lut[((d1 >> 16) & 0x0f) | 0x40]
}${lut[(d1 >> 24) & 0xff]}-${lut[(d2 & 0x3f) | 0x80]}${lut[(d2 >> 8) & 0xff]}-${
lut[(d2 >> 16) & 0xff]
}${lut[(d2 >> 24) & 0xff]}${lut[d3 & 0xff]}${lut[(d3 >> 8) & 0xff]}${lut[(d3 >> 16) & 0xff]}${
lut[(d3 >> 24) & 0xff]
}`;
}
export function* randomWithinBounds(
lowerBound: number,
upperBound: number,
seed: string = Date.now().toLocaleString(),
): Generator {
const random = seedrandom(seed);
while (true) yield Math.floor(random() * (upperBound - lowerBound) + lowerBound);
}
function _rng(state = {}, handler = gen => gen()) {
const seed = state.seed;
const options = {
state: state.arc || {},
};
const result = seedrandom(seed, options);
return {
number: handler(result),
state: {
seed,
arc: result.state(),
count: (state.count || 0) + 1,
},
};
}
export const generateRandomDashboard = (title: string, seed?: string): DashboardModel => {
if (seed) {
seedrandom(seed, { global: true });
}
return {
title: title,
charts: [
generateRandomMetricChart('Single metric', ['chocolate'], 4),
generateRandomMetricChartWithLabels('Single metric with labels', [
genLabels('apples', undefined, [['color', 'green'], ['size', 'big']])
], 4),
generateRandomHistogramChart('Histogram', 4),
generateRandomMetricChart('Several metrics', ['dogs', 'cats', 'birds'], 6),
generateRandomMetricChartWithLabels('Several metrics with labels', [
genLabels('apples', undefined, [['color', 'green'], ['size', 'big']]),
genLabels('oranges', undefined, [['color', 'orange'], ['size', 'small']]),
genLabels('bananas', undefined, [['color', 'yellow'], ['size', 'medium']])
], 6),
{ name: 'empty 1', unit: 'bytes', spans: 6, metrics: [] },