当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript layout.partition方法代码示例

本文整理汇总了TypeScript中d3.layout.partition方法的典型用法代码示例。如果您正苦于以下问题:TypeScript layout.partition方法的具体用法?TypeScript layout.partition怎么用?TypeScript layout.partition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在d3.layout的用法示例。


在下文中一共展示了layout.partition方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: ngOnInit

    ngOnInit(){     
       
        var el = this.elementRef.nativeElement;
        var attrName = el.children && el.children[0] && el.children[0].attributes && el.children[0].attributes[0] && el.children[0].attributes[0].name;
       
        var componentContainer = d3.select(this.elementRef.nativeElement);
        var d3Container = componentContainer.select("#display");
        
        var margin = {top: 30, right: 120, bottom: 0, left: 120},
            width = 960 - margin.left - margin.right,
            height = 500 - margin.top - margin.bottom;

        var x = d3.scale.linear()
            .range([0, width]);

        var barHeight = 20;

        var color = d3.scale.ordinal()
            .range(["steelblue", "#ccc"]);

        var duration = 750,
            delay = 25;
            
        var partition = d3.layout.partition()
            .value(function(d) { return d.size; });

        var xAxis = d3.svg.axis()
            .scale(x)
            .orient("top");

        var svg = d3Container.append("svg")
            .attr(attrName, "")
            .attr("width", width + margin.left + margin.right)
            .attr("height", height + margin.top + margin.bottom)
            .append("g")
            .attr(attrName, "")
            .attr("transform", "translate(" + margin.left + "," + margin.top + ")");

        svg.append("rect")
            .attr(attrName, "")
            .attr("class", "background")
            .attr("width", width)
            .attr("height", height)
            .on("click", up);

        svg.append("g")
            .attr(attrName, "")
            .attr("class", "x axis");

        svg.append("g")
            .attr(attrName, "")
            .attr("class", "y axis")
        .append("line")
            .attr(attrName, "")
            .attr("y1", "100%");

        d3.json("app/components/bar-charts-hierarchical-bar-chart/readme.json", function(error, root) {
            if (error) throw error;

            partition.nodes(root);  
            x.domain([0, root.value]).nice();
            down(root, 0);
        });
        
        

        function down(d, i) {
            if (!d.children || window.__transition__) return;
            var end = duration + d.children.length * delay;

            // Mark any currently-displayed bars as exiting.
            var exit = svg.selectAll(".enter")
                .attr("class", "exit");

            // Entering nodes immediately obscure the clicked-on bar, so hide it.
            exit.selectAll("rect").filter(function(p) { return p === d; })
                .style("fill-opacity", 1e-6);

            // Enter the new bars for the clicked-on data.
            // Per above, entering bars are immediately visible.
            var enter = bar(d)
                .attr("transform", stack(i))
                .style("opacity", 1);

            // Have the text fade-in, even though the bars are visible.
            // Color the bars as parents; they will fade to children if appropriate.
            enter.select("text").style("fill-opacity", 1e-6);
            enter.select("rect").style("fill", color(true));

            // Update the x-scale domain.
            x.domain([0, d3.max(d.children, function(d) { return d.value; })]).nice();

            // Update the x-axis.
            svg.selectAll(".x.axis").transition()
                .duration(duration)
                .call(xAxis);

            // Transition entering bars to their new position.
            var enterTransition = enter.transition()
                .duration(duration)
//.........这里部分代码省略.........
开发者ID:Anhmike,项目名称:angular2-d3-sample,代码行数:101,代码来源:component.ts


注:本文中的d3.layout.partition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。