new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

D3 · all subjects

d3-array/bin

12 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

d3.bin() constructor

Constructs a new bin generator with default settings. The returned bin generator supports method chaining and is also a function. Typically chained with bin.value() to assign a value accessor.

bin(data) - bins the input data

Bins the given iterable of data samples. Returns an array of bins, where each bin is an array containing associated elements from the input data. The length of a bin is the number of elements in that bin. Each bin has two additional attributes: x0 (the lower bound of the bin, inclusive) and x1 (the upper bound of the bin, exclusive, except for the last bin). Null or non-comparable values, or those outside the domain, are ignored.

bin.value() - set or get value accessor

If value is specified, sets the value accessor to the specified function or constant and returns the bin generator. If value is not specified, returns the current value accessor, which defaults to the identity function. When bins are generated, the value accessor is invoked for each element in the input data array, passed the element d, index i, and array data as three arguments. The default value accessor assumes input data are orderable, such as numbers or dates.

bin.domain() - set or get domain

If domain is specified, sets the domain to the specified function or array and returns the bin generator. If domain is not specified, returns the current domain, which defaults to extent. The bin domain is defined as an array [min, max], where both values are inclusive. Any value outside this domain is ignored when bins are generated. The domain accessor is invoked on the materialized array of values, not on the input data array.

bin.thresholds() with number argument

If thresholds is specified as a number, the domain is uniformly divided into approximately that many bins using the ticks algorithm.

bin.thresholds() with array argument

If thresholds is specified as an array [x0, x1, …], values less than x0 are placed in the first bin, values >= x0 and < x1 are placed in the second bin, and so on. The generated bins will have thresholds.length + 1 bins. Threshold values outside the domain are ignored. The first bin.x0 is always equal to the minimum domain value, and the last bin.x1 is always equal to the maximum domain value.

bin.thresholds() with function argument

If thresholds is specified as a function, the function receives three arguments: the array of input values derived from the data, and the domain represented as min and max. The function may return either an array of numeric thresholds or a count of bins. In the latter case, the domain is divided uniformly into approximately count bins. The default threshold generator implements Sturges' formula.

thresholdFreedmanDiaconis(values, min, max)

Returns the number of bins according to the Freedman–Diaconis rule. The input values must be numbers. Used as d3.bin().thresholds(d3.thresholdFreedmanDiaconis).

thresholdScott(values, min, max)

Returns the number of bins according to Scott's normal reference rule. The input values must be numbers. Used as d3.bin().thresholds(d3.thresholdScott).

thresholdSturges(values, min, max)

Returns the number of bins according to Sturges' formula. The input values must be numbers. Used as d3.bin().thresholds(d3.thresholdSturges). This is the default threshold generator.

bin domain with extent default

If the default extent domain is used and thresholds are specified as a count rather than explicit values, the computed domain will be niced such that all bins are uniform width.

bin with scale example

To use a bin generator with a linear scale x: const bin = d3.bin().domain(x.domain()).thresholds(x.ticks(20)); Then compute bins from an array of numbers like so: const bins = bin(numbers);

Give your agent this brain