HTML-D3

 view release on metacpan or  search on metacpan

lib/HTML/D3.pm  view on Meta::CPAN

        if (sortState.col === colIdx) {
            sortState.asc = !sortState.asc;
        } else {
            sortState.col = colIdx;
            sortState.asc = true;
        }
        var rows = tbody.selectAll('tr').data();
        rows.sort(function(a, b) {
            var va = a[colIdx], vb = b[colIdx];
            var na = parseFloat(va), nb = parseFloat(vb);
            if (!isNaN(na) && !isNaN(nb)) { va = na; vb = nb; }
            if (va < vb) return sortState.asc ? -1 : 1;
            if (va > vb) return sortState.asc ?  1 : -1;
            return 0;
        });
        tbody.selectAll('tr').data(rows).join('tr')
            .selectAll('td').data(function(d) { return d.slice(1); }).join('td')
            .text(function(d) { return d; });
        table.selectAll('th.dt-sortable')
            .attr('data-sort', function(d, i) {
                return i === sortState.col ? (sortState.asc ? 'asc' : 'desc') : null;

t/snippet_treemap.t  view on Meta::CPAN

	like($h, qr/var colorLabel = "Margin\\u003c\/script>\\u003cb>";/, 'label escaped for the script');
	like($h, qr/"id","tm2_cgrad"/, 'gradient id follows the chart id');

	throws_ok { $chart->render_treemap_snippet(\@coloured, { color_scheme => 'Viridis' }) }
		qr/Unknown color_scheme: Viridis/, 'unknown color_scheme dies when colouring by value';
	lives_ok { $chart->render_treemap_snippet(\@flat_data, { color_scheme => 'Viridis' }) }
		'color_scheme is not read without colour values';
};

subtest 'a bad color_value dies' => sub {
	for my $bad ('high', 'NaN', 'inf', '') {
		throws_ok {
			$chart->render_treemap_snippet([ { path => 'R/A', value => 1, color_value => $bad } ])
		} qr/Each flat row's 'color_value' must be numeric/, "flat: '$bad'";
	}
	throws_ok {
		$chart->render_treemap_snippet({ name => 'R', children => [ { name => 'A', value => 1, color_value => 'x' } ] })
	} qr/Each node's 'color_value' must be numeric/, 'tree: a bad leaf';
};

subtest 'a hash tree is coloured by its leaves' => sub {



( run in 2.857 seconds using v1.01-cache-2.11-cpan-60884a8df76 )