• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript d3.format函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中d3.format函数的典型用法代码示例。如果您正苦于以下问题:TypeScript format函数的具体用法?TypeScript format怎么用?TypeScript format使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: return

 return (v: number) => {
   let absv = Math.abs(v);
   if (absv < 1E-15) {
     // Sometimes zero-like values get an annoying representation
     absv = 0;
   }
   let f: (x: number) => string;
   if (absv >= 1E4) {
     f = d3.format('.' + digits + 'e');
   } else if (absv > 0 && absv < 0.01) {
     f = d3.format('.' + digits + 'e');
   } else {
     f = d3.format('.' + digits + 'g');
   }
   return f(v);
 };
开发者ID:AlbertXiebnu,项目名称:tensorflow,代码行数:16,代码来源:vz-chart-helpers.ts


示例2: rotate

            .each((d: IDatum, i: number): void => {
                var rotation = 0;
                var x = this._x(d, i, this._serie);
                var y = this._y(d, i, this._serie);
                var dx = 0;
                var dy = 0;

                if (this._labels.rotate === true) {
                    rotation = -90;
                }

                var text = this._svgLabels.append("text")
                    .text(d3.format(this._labels.format)(this._chart.series.items[this._serie].data[i]))
                    .style("text-anchor", "middle")
                    .attr({
                        "alignment-baseline": "central",
                        "class": "label",
                        "fill": "#fff",
                        "transform": "translate(" + x + ", " + y + ") rotate(" + rotation + ")"
                    });

                text
                    .attr("dy", dy)
                    .attr("dx", dx);
            });
开发者ID:frnkclsst,项目名称:d3charts,代码行数:25,代码来源:Shape.Bubble.ts


示例3: rotate

            .each((d: IDatum, i: number): void  => {
                var rotation = 0;
                var x = this._x(d, i, this._serie);
                var y = this._y(d, i, this._serie);
                var dx = 0;
                var dy = 0;

                if (this._labels.rotate === true) {
                    rotation = -90;
                }

                if (rotation != 0) {
                    dx = -this._height(d, i, this._serie) / 2;
                    dy = this._width(d, i, this._serie) / 2;
                }
                else {
                    dx = this._width(d, i, this._serie) / 2;
                    dy = this._height(d, i, this._serie) / 2;
                }

                this._svgLabels.append("text")
                    .text(d3.format(this._labels.format)(d.y))
                    .style("text-anchor", "middle")
                    .attr({
                        "alignment-baseline": "central",
                        "class": "label",
                        "fill": "#fff",
                        "transform": "translate(" + x + ", " + y + ") rotate(" + rotation + ")",
                        "dx": dx,
                        "dy": dy
                    });
            });
开发者ID:frnkclsst,项目名称:d3charts,代码行数:32,代码来源:Shape.Column.ts


示例4: update

    public update(data: any) {
        let propertyKey: string = this.config.get('propertyKey');
        
        // Exclude those values that do not contain a 'key'.
        let legend = null,
            entries = null,
            legendTitle = this.config.get('legendTitle'),
            propertyZ = this.config.get('propertyZ'),
            colorScale = this.config.get('colorScale'),
            height = this.config.get('height'),
            width = this.config.get('width'),
            legendCells = this.config.get('legendCells'),
            valuesFormat = this.config.get('valuesFormat');

        this.svg.select('.legend').remove();
        legend = this.svg.append('g').attr('class', 'legend');

        let min = d3min(data, (d: any) => +d[propertyZ]),
            max = d3max(data, (d: any) => +d[propertyZ]);

        if (data.length <= 1 || min == max) {
            legendCells = 2;
        } else if (data.length <= legendCells) {
            legendCells = data.length;
        }

        colorScale.domain([min, max]);

        let colorLegend: any = legendColor()
            .title(legendTitle)
            .labelDelimiter('–')
            .labelFormat(format(valuesFormat));
        if (legendCells) {
            colorLegend.cells(legendCells);
        }   
        colorLegend.scale(colorScale);
        
        legend.call(colorLegend);

        legend.attr('transform', `translate(${width + 10}, 0)`);
    }
开发者ID:proteus-h2020,项目名称:proteus-charts,代码行数:41,代码来源:ColorLegend.ts


示例5: function

        svg.on("mouseover", function (d: IDatum, i: number): void {
            var title = _self.chart.options.getValue("tooltip.title"),
                subtitle = _self.chart.categories.getLabel(i),
                color = _self.chart.colorPalette.color(serie),
                serieTitle = _self.chart.series.getLabel(serie),
                dataPoint,
                percent;

            if (d.y === d.y1) {
                dataPoint = d3.format(_self.getPointFormat(serie))(d.y) + _self.getSuffix(serie);
            }
            else if (d.y === undefined) {
                dataPoint =
                    d3.format(_self.getPointFormat(serie))(d.y0) + _self.getSuffix(serie) + " - " +
                    d3.format(_self.getPointFormat(serie))(d.y1) + _self.getSuffix(serie);
            }
            else {
                dataPoint =
                    d3.format(_self.getPointFormat(serie))(d.y) + _self.getSuffix(serie) + " (" +
                    d3.format(_self.getPointFormat(serie))(d.y0) + _self.getSuffix(serie) + " - " +
                    d3.format(_self.getPointFormat(serie))(d.y1) + _self.getSuffix(serie) + ")";
            }

            percent = isNaN(d.perc) ? "" : Math.round(d.perc * 100) + "%";
/*
            if (inverse) {
                color = _self.chart.colorPalette.color(i);
                subtitle = _self.chart.series.getLabel(serie);
                serieTitle = _self.chart.categories.getLabel(i);
                dataPoint = d.value;
                percent = Math.round(_self.chart.series.getMatrixItem(serie)[i].perc * 100) + "%";
            }

            if (_self.chart instanceof ScatterChart) {
                color = _self.chart.colorPalette.color(serie - 1);
            }
*/
            var svgSymbol = d3.select(document.createElementNS(d3.ns.prefix.svg, "svg"));
            var symbol = new SVGSymbol(svgSymbol, _self.chart, serie);
            symbol.color = color;
            symbol.opacity = _self.chart.options.plotOptions.area.opacity;
            symbol.draw();

            divTooltip.html("<div class='title'>" + title + "</div>" +
                "<div class='subtitle'>" + subtitle + "</div><br/>" +
                "<div class='items'>" +
                    "<div class='item'>" +
                        "<div class='cell color'>" +
                            "<svg width='24' height='11'>" +
                                svgSymbol.html() +
                            "</svg>" +
                        "</div>" +
                        "<div class='cell serie'>" + serieTitle + "</div>" +
                        "<div class='cell value'>" + dataPoint + "</div>" +
                        "<div class='cell percent'>" + percent + "</div>" +
                    "</div>" +
                "</div>"
            );

            // add animation
            divTooltip.transition()
                .delay(300)
                .duration(100)
                .style("opacity", 1);
            })
开发者ID:frnkclsst,项目名称:d3charts,代码行数:65,代码来源:Tooltip.ts


示例6: generateBarChart

  private generateBarChart(data: any) {

    let that = this;
    let margin = {top: 20, right: 40, bottom: 60, left: 80};


    let viewerWidth = $(this.vizCanvas.nativeElement).width() - margin.left - margin.right;
    let viewerHeight = $(this.vizCanvas.nativeElement).height() - margin.top - margin.bottom;
    let formatNumber = d3.format('.2n'),
      formatBillion = function (x) {
        return formatNumber(x / 1e9) + 'B';
      },
      formatMillion = function (x) {
        return formatNumber(x / 1e6) + 'M';
      },
      formatThousand = function (x) {
        return formatNumber(x / 1e3) + 'k';
      },
      formatAsIs = function (x) {
        return x;
      };

    function formatAbbreviation(x) {
      let v = Math.abs(x);
      return (v >= .9995e9 ? formatBillion
        : v >= .9995e6 ? formatMillion
          : v >= .9995e3 ? formatThousand
            : formatAsIs)(x);
    }


    let x = d3.scaleLinear().range([0, viewerWidth]);
    let y = d3.scaleLinear().range([viewerHeight, 0]);


// append the svg obgect to the body of the page
// appends a 'group' element to 'svg'
// moves the 'group' element to the top left margin
    let svg = d3.select(this.vizCanvas.nativeElement).append('svg')
      .attr('width', viewerWidth + margin.left + margin.right)
      .attr('height', viewerHeight + margin.top + margin.bottom)
      .append('g')
      .attr('transform',
        'translate(' + margin.left + ',' + margin.top + ')');


    let xis: number[] = data.map(function (d: any) {
      return Number(d[that._x_accessor]);
    });


    let yis: number[] = data.map(function (d: any) {
      return Number(d[that._y_accessor]);
    });


    // Scale the range of the data
    x.domain(d3.extent(xis));
    y.domain(d3.extent(yis));


    // Add the scatterplot
    svg.selectAll('dot')
      .data(data)
      .enter().append('circle')
      .attr('r', 3)
      .attr('cx', function (d) {
        return x(d[that._x_accessor]);
      })
      .attr('cy', function (d) {
        return y(
          d[that._y_accessor]);

      });

    // Add the X Axis
    svg.append('g')
      .attr('transform', 'translate(0,' + viewerHeight + ')')
      .call(d3.axisBottom(x).tickFormat(formatAbbreviation))
      .selectAll('text')
      .attr('y', 0)
      .attr('x', 9)
      .attr('dy', '.35em')
      .attr('transform', 'rotate(45)')
      .style('text-anchor', 'start');

    // Add the Y Axis
    svg.append('g')
      .call(d3.axisLeft(y).tickFormat(formatAbbreviation));


    svg.append('rect')
      .attr('x', 0)
      .attr('y', 0)
      .attr('height', viewerHeight)
      .attr('width', viewerWidth)
      .style('stroke', 'black')
      .style('fill', 'none')
      .style('stroke-width', '1');

//.........这里部分代码省略.........
开发者ID:okgreece,项目名称:indigo,代码行数:101,代码来源:scatterPlot.ts


示例7: 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: 20, right: 20, bottom: 30, left: 40},
            width = 960 - margin.left - margin.right,
            height = 500 - margin.top - margin.bottom;

        var x = d3.scale.ordinal()
            .rangeRoundBands([0, width], .1);

        var y = d3.scale.linear()
            .rangeRound([height, 0]);

        var color = d3.scale.ordinal()
            .range(["#98abc5", "#8a89a6", "#7b6888", "#6b486b", "#a05d56", "#d0743c", "#ff8c00"]);

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

        var yAxis = d3.svg.axis()
            .scale(y)
            .orient("left")
            .tickFormat(d3.format(".2s"));

        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 + ")");

        d3.csv("app/components/bar-charts-stacked-bar-chart/data.tsv", function(error, data) {
            if (error) throw error;

            color.domain(d3.keys(data[0]).filter(function(key) { return key !== "State"; }));

            data.forEach(function(d) {
                var y0 = 0;
                d.ages = color.domain().map(function(name) { return {name: name, y0: y0, y1: y0 += +d[name]}; });
                d.total = d.ages[d.ages.length - 1].y1;
            });

            data.sort(function(a, b) { return b.total - a.total; });

            x.domain(data.map(function(d) { return d.State; }));
            y.domain([0, d3.max(data, function(d) { return d.total; })]);

            svg.append("g")
                .attr(attrName, "")
                .attr("class", "x axis")
                .attr("transform", "translate(0," + height + ")")
                .call(xAxis);

            svg.append("g")
                .attr(attrName, "")
                .attr("class", "y axis")
                .call(yAxis)
                .append("text")
                .attr(attrName, "")
                .attr("transform", "rotate(-90)")
                .attr("y", 6)
                .attr("dy", ".71em")
                .style("text-anchor", "end")
                .text("Population");

            var state = svg.selectAll(".state")
                .data(data)
                .enter().append("g")
                .attr(attrName, "")
                .attr("class", "g")
                .attr("transform", function(d) { return "translate(" + x(d.State) + ",0)"; });

            state.selectAll("rect")
                .attr(attrName, "")
                .data(function(d) { return d.ages; })
                .enter().append("rect")
                .attr(attrName, "")
                .attr("width", x.rangeBand())
                .attr("y", function(d) { return y(d.y1); })
                .attr("height", function(d) { return y(d.y0) - y(d.y1); })
                .style("fill", function(d) { return color(d.name); });

            var legend = svg.selectAll(".legend")
                .data(color.domain().slice().reverse())
                .enter().append("g")
                .attr(attrName, "")
                .attr("class", "legend")
                .attr("transform", function(d, i) { return "translate(0," + i * 20 + ")"; });

            legend.append("rect")
                .attr(attrName, "")
//.........这里部分代码省略.........
开发者ID:Anhmike,项目名称:angular2-d3-sample,代码行数:101,代码来源:component.ts


示例8:

    axis: true,

    // x axis tick count
    xTicks: 6,

    // y range (opacity)
    yRange: [0, 1],

    // x domain (time)
    xDomain: [],

    // time formatter
    timeFormat: d3.time.format("%B %d %I:%M %p"),

    // value formatter
    valueFormat: d3.format('0,000'),

    // custom point width
    pointWidth: null,

    // easing function for transitions
    ease: 'linear'
};

class Margin {
    left:number;
    right:number;
    top:number;
    bottom:number;
}
开发者ID:xsurge83,项目名称:d3-charts,代码行数:30,代码来源:main.ts


示例9: format

 .text((d: any) => format(valuesFormat)(d[propertyZ]));
开发者ID:proteus-h2020,项目名称:proteus-charts,代码行数:1,代码来源:Timeboxset.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript d3.interpolateRgbBasis函数代码示例发布时间:2022-05-25
下一篇:
TypeScript d3.extent函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap