Data that the histogram will be based on
InputRange that holds x and y coordinates for the kernel
import std.stdio : writeln; import std.algorithm : map; import std.array : array; import std.random : uniform; import std.range : chain, iota, repeat, walkLength; import ggplotd.aes : Aes; auto xs = iota(0,100,1) .map!((i)=>uniform(0,0.75)+uniform(0.25,1)) .array; auto dens = statDensity( Aes!( typeof(xs), "x")( xs ) ); auto dim = dens.walkLength; assertGreaterThan( dim, 1 ); // Test that grouping leads to longer (twice as long) result auto cols = chain("a".repeat(50),"b".repeat(50) ); auto dens2 = statDensity( Aes!(typeof(cols), "colour", typeof(xs), "x")( cols, xs ) ); assertGreaterThan( dens2.walkLength, 1.9*dim ); assertLessThan( dens2.walkLength, 2.1*dim ); // Test that colour is passed through (merged) assertEqual( dens2.front.colour.length, 1 ); // Test single point xs = [1]; dens = statDensity( Aes!( typeof(xs), "x")( xs ) ); assertEqual(dens.walkLength, 3);
Calculate kernel density for given data