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

TypeScript d3.range函数代码示例

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

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



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

示例1: render

    /**
     * Render given data as bubbles.
     */
    public render(data: T[]): d3.Selection<any> {
        const svg = this.element.append('svg')
                    .attr('height', this.chartHeight)
                    .attr('width', this.chartWidth);

        const plot = svg.append('g')
            .attr('transform', 'translate(400 300)');

        this.render_spiral_axis(plot);

        if (this.x_map) {
            const extent = d3.extent(data, (datum: T, _) => this.x_map(datum));
            const turn_range_sec = this.period_fraction * (extent[1] - extent[0]);

            // do the section from east to the end of the spiral
            const s1_range = BubbleSpiral.MODULO(1 / this.period_fraction, 1) - 1 / 4;
            const s1_fractions = d3.range(s1_range * 8 + 1).map(i => i / 8);
            const s1_start_sec = extent[1] - s1_range * turn_range_sec;
            const s1_labels = s1_fractions.map(i => (s1_start_sec + i * turn_range_sec)).map(this.label_map);

            // do the section from one past the start of the last winding to east
            const s2_range_start = s1_range + 1 / 8;
            const s2_range = 1 - s2_range_start;
            const s2_fractions = d3.range(s2_range * 8).map(i => i / 8);
            const s2_start_sec = extent[1] - 7 / 8 * turn_range_sec;
            const s2_labels = s2_fractions.map(i => (s2_start_sec + i * turn_range_sec)).map(this.label_map);

            const marks = s1_fractions.concat(s2_fractions.map(x => x + s2_range_start));
            const labels = s1_labels.concat(s2_labels);

            this.add_axis(plot, marks, labels);
        }

        const bubble_groups = plot.append('g').selectAll('g.bubble')
            .data(data)
            .enter().append('g')
            .attr('class', 'bubble');

        bubble_groups.append('circle')
            .attr('cx', (d) => this.get_polar(this.radial_map(d)).x)
            .attr('cy', (d) => this.get_polar(this.radial_map(d)).y)
            .attr('r', (d) => this.bubble_scale_map(d))
            .style('fill', this.color_map ? (d) => this.color_map(d) : () => 'red')
            .style('fill-opacity', 0.1)
            .style('stroke', 'black')
            .style('stroke-width', 0.05);

        return plot;
    }
开发者ID:nlesc-sherlock,项目名称:spiraljs,代码行数:52,代码来源:BubbleSpiral.ts


示例2: drawColorLegend

function drawColorLegend(elem, colorScheme, rangeFrom, rangeTo, maxValue, minValue) {
  const legendElem = $(elem).find('svg');
  const legend = d3.select(legendElem.get(0));
  clearLegend(elem);

  const legendWidth = Math.floor(legendElem.outerWidth()) - 30;
  const legendHeight = legendElem.attr('height');

  const rangeStep = ((rangeTo - rangeFrom) / legendWidth) * LEGEND_SEGMENT_WIDTH;
  const widthFactor = legendWidth / (rangeTo - rangeFrom);
  const valuesRange = d3.range(rangeFrom, rangeTo, rangeStep);

  const colorScale = getColorScale(colorScheme, contextSrv.user.lightTheme, maxValue, minValue);
  legend
    .append('g')
    .attr('class', 'legend-color-bar')
    .attr('transform', 'translate(' + LEGEND_PADDING_LEFT + ',0)')
    .selectAll('.heatmap-color-legend-rect')
    .data(valuesRange)
    .enter()
    .append('rect')
    .attr('x', d => Math.round((d - rangeFrom) * widthFactor))
    .attr('y', 0)
    .attr('width', Math.round(rangeStep * widthFactor + 1)) // Overlap rectangles to prevent gaps
    .attr('height', legendHeight)
    .attr('stroke-width', 0)
    .attr('fill', d => colorScale(d));

  drawLegendValues(elem, rangeFrom, rangeTo, maxValue, minValue, legendWidth, valuesRange);
}
开发者ID:grafana,项目名称:grafana,代码行数:30,代码来源:color_legend.ts


示例3: drawSimpleOpacityLegend

function drawSimpleOpacityLegend(elem, options) {
  let legendElem = $(elem).find('svg');
  clearLegend(elem);

  let legend = d3.select(legendElem.get(0));
  let legendWidth = Math.floor(legendElem.outerWidth());
  let legendHeight = legendElem.attr("height");

  if (legendWidth) {
    let legendOpacityScale;
    if (options.colorScale === 'linear') {
      legendOpacityScale = d3.scaleLinear()
      .domain([0, legendWidth])
      .range([0, 1]);
    } else if (options.colorScale === 'sqrt') {
      legendOpacityScale = d3.scalePow().exponent(options.exponent)
      .domain([0, legendWidth])
      .range([0, 1]);
    }

    let rangeStep = 10;
    let valuesRange = d3.range(0, legendWidth, rangeStep);
    var legendRects = legend.selectAll(".heatmap-opacity-legend-rect").data(valuesRange);

    legendRects.enter().append("rect")
      .attr("x", d => d)
      .attr("y", 0)
      .attr("width", rangeStep)
      .attr("height", legendHeight)
      .attr("stroke-width", 0)
      .attr("fill", options.cardColor)
      .style("opacity", d => legendOpacityScale(d));
  }
}
开发者ID:connection-reset,项目名称:grafana,代码行数:34,代码来源:color_legend.ts


示例4: drawColorLegend

function drawColorLegend(elem, colorScheme, rangeFrom, rangeTo, maxValue, minValue) {
  const legendElem = $(elem).find('svg');
  const legend = d3.select(legendElem.get(0));
  clearLegend(elem);

  const legendWidth = Math.floor(legendElem.outerWidth()) - 30;
  const legendHeight = legendElem.attr('height');

  let rangeStep = 1;
  if (rangeTo - rangeFrom > legendWidth) {
    rangeStep = Math.floor((rangeTo - rangeFrom) / legendWidth);
  }
  const widthFactor = legendWidth / (rangeTo - rangeFrom);
  const valuesRange = d3.range(rangeFrom, rangeTo, rangeStep);

  const colorScale = getColorScale(colorScheme, contextSrv.user.lightTheme, maxValue, minValue);
  legend
    .selectAll('.heatmap-color-legend-rect')
    .data(valuesRange)
    .enter()
    .append('rect')
    .attr('x', d => d * widthFactor)
    .attr('y', 0)
    .attr('width', rangeStep * widthFactor + 1) // Overlap rectangles to prevent gaps
    .attr('height', legendHeight)
    .attr('stroke-width', 0)
    .attr('fill', d => colorScale(d));

  drawLegendValues(elem, colorScale, rangeFrom, rangeTo, maxValue, minValue, legendWidth);
}
开发者ID:CorpGlory,项目名称:grafana,代码行数:30,代码来源:color_legend.ts


示例5: drawSimpleColorLegend

function drawSimpleColorLegend(elem, colorScale) {
  const legendElem = $(elem).find('svg');
  clearLegend(elem);

  const legendWidth = Math.floor(legendElem.outerWidth());
  const legendHeight = legendElem.attr('height');

  if (legendWidth) {
    const valuesNumber = Math.floor(legendWidth / 2);
    const rangeStep = Math.floor(legendWidth / valuesNumber);
    const valuesRange = d3.range(0, legendWidth, rangeStep);

    const legend = d3.select(legendElem.get(0));
    const legendRects = legend.selectAll('.heatmap-color-legend-rect').data(valuesRange);

    legendRects
      .enter()
      .append('rect')
      .attr('x', d => d)
      .attr('y', 0)
      .attr('width', rangeStep + 1) // Overlap rectangles to prevent gaps
      .attr('height', legendHeight)
      .attr('stroke-width', 0)
      .attr('fill', d => colorScale(d));
  }
}
开发者ID:CorpGlory,项目名称:grafana,代码行数:26,代码来源:color_legend.ts


示例6: drawOpacityLegend

  function drawOpacityLegend() {
    d3.select("#heatmap-opacity-legend").selectAll("rect").remove();

    let legend = d3.select("#heatmap-opacity-legend");
    let legendWidth = Math.floor($(d3.select("#heatmap-opacity-legend").node()).outerWidth());
    let legendHeight = d3.select("#heatmap-opacity-legend").attr("height");

    let legendOpacityScale;
    if (panel.color.colorScale === 'linear') {
      legendOpacityScale = d3.scaleLinear()
      .domain([0, legendWidth])
      .range([0, 1]);
    } else if (panel.color.colorScale === 'sqrt') {
      legendOpacityScale = d3.scalePow().exponent(panel.color.exponent)
      .domain([0, legendWidth])
      .range([0, 1]);
    }

    let rangeStep = 1;
    let valuesRange = d3.range(0, legendWidth, rangeStep);
    var legendRects = legend.selectAll(".heatmap-opacity-legend-rect").data(valuesRange);

    legendRects.enter().append("rect")
    .attr("x", d => d)
    .attr("y", 0)
    .attr("width", rangeStep)
    .attr("height", legendHeight)
    .attr("stroke-width", 0)
    .attr("fill", panel.color.cardColor)
    .style("opacity", d => {
      return legendOpacityScale(d);
    });
  }
开发者ID:postsql,项目名称:grafana,代码行数:33,代码来源:rendering.ts


示例7: drawOpacityLegend

function drawOpacityLegend(elem, options, rangeFrom, rangeTo, maxValue, minValue) {
  const legendElem = $(elem).find('svg');
  const legend = d3.select(legendElem.get(0));
  clearLegend(elem);

  const legendWidth = Math.floor(legendElem.outerWidth()) - 30;
  const legendHeight = legendElem.attr('height');

  let rangeStep = 1;
  if (rangeTo - rangeFrom > legendWidth) {
    rangeStep = Math.floor((rangeTo - rangeFrom) / legendWidth);
  }
  const widthFactor = legendWidth / (rangeTo - rangeFrom);
  const valuesRange = d3.range(rangeFrom, rangeTo, rangeStep);

  const opacityScale = getOpacityScale(options, maxValue, minValue);
  legend
    .selectAll('.heatmap-opacity-legend-rect')
    .data(valuesRange)
    .enter()
    .append('rect')
    .attr('x', d => d * widthFactor)
    .attr('y', 0)
    .attr('width', rangeStep * widthFactor)
    .attr('height', legendHeight)
    .attr('stroke-width', 0)
    .attr('fill', options.cardColor)
    .style('opacity', d => opacityScale(d));

  drawLegendValues(elem, opacityScale, rangeFrom, rangeTo, maxValue, minValue, legendWidth);
}
开发者ID:CorpGlory,项目名称:grafana,代码行数:31,代码来源:color_legend.ts


示例8: drawOpacityLegend

function drawOpacityLegend(elem, options, rangeFrom, rangeTo, maxValue, minValue) {
  let legendElem = $(elem).find('svg');
  let legend = d3.select(legendElem.get(0));
  clearLegend(elem);

  let legendWidth = Math.floor(legendElem.outerWidth()) - 30;
  let legendHeight = legendElem.attr("height");

  let rangeStep = 1;
  if (rangeTo - rangeFrom > legendWidth) {
    rangeStep = Math.floor((rangeTo - rangeFrom) / legendWidth);
  }
  let widthFactor = legendWidth / (rangeTo - rangeFrom);
  let valuesRange = d3.range(rangeFrom, rangeTo, rangeStep);

  let opacityScale = getOpacityScale(options, maxValue, minValue);
  legend.selectAll(".heatmap-opacity-legend-rect")
    .data(valuesRange)
    .enter().append("rect")
    .attr("x", d => d * widthFactor)
    .attr("y", 0)
    .attr("width", rangeStep * widthFactor)
    .attr("height", legendHeight)
    .attr("stroke-width", 0)
    .attr("fill", options.cardColor)
    .style("opacity", d => opacityScale(d));

  drawLegendValues(elem, opacityScale, rangeFrom, rangeTo, maxValue, minValue, legendWidth);
}
开发者ID:connection-reset,项目名称:grafana,代码行数:29,代码来源:color_legend.ts


示例9: drawOpacityLegend

function drawOpacityLegend(elem, options, rangeFrom, rangeTo, maxValue, minValue) {
  const legendElem = $(elem).find('svg');
  const legend = d3.select(legendElem.get(0));
  clearLegend(elem);

  const legendWidth = Math.floor(legendElem.outerWidth()) - 30;
  const legendHeight = legendElem.attr('height');

  const rangeStep = ((rangeTo - rangeFrom) / legendWidth) * LEGEND_SEGMENT_WIDTH;
  const widthFactor = legendWidth / (rangeTo - rangeFrom);
  const valuesRange = d3.range(rangeFrom, rangeTo, rangeStep);

  const opacityScale = getOpacityScale(options, maxValue, minValue);
  legend
    .append('g')
    .attr('class', 'legend-color-bar')
    .attr('transform', 'translate(' + LEGEND_PADDING_LEFT + ',0)')
    .selectAll('.heatmap-opacity-legend-rect')
    .data(valuesRange)
    .enter()
    .append('rect')
    .attr('x', d => Math.round((d - rangeFrom) * widthFactor))
    .attr('y', 0)
    .attr('width', Math.round(rangeStep * widthFactor))
    .attr('height', legendHeight)
    .attr('stroke-width', 0)
    .attr('fill', options.cardColor)
    .style('opacity', d => opacityScale(d));

  drawLegendValues(elem, rangeFrom, rangeTo, maxValue, minValue, legendWidth, valuesRange);
}
开发者ID:grafana,项目名称:grafana,代码行数:31,代码来源:color_legend.ts


示例10: drawColorLegend

function drawColorLegend(elem, colorScheme, rangeFrom, rangeTo, maxValue, minValue) {
  let legendElem = $(elem).find('svg');
  let legend = d3.select(legendElem.get(0));
  clearLegend(elem);

  let legendWidth = Math.floor(legendElem.outerWidth()) - 30;
  let legendHeight = legendElem.attr("height");

  let rangeStep = 1;
  if (rangeTo - rangeFrom > legendWidth) {
    rangeStep = Math.floor((rangeTo - rangeFrom) / legendWidth);
  }
  let widthFactor = legendWidth / (rangeTo - rangeFrom);
  let valuesRange = d3.range(rangeFrom, rangeTo, rangeStep);

  let colorScale = getColorScale(colorScheme, maxValue, minValue);
  legend.selectAll(".heatmap-color-legend-rect")
    .data(valuesRange)
    .enter().append("rect")
    .attr("x", d => d * widthFactor)
    .attr("y", 0)
    .attr("width", rangeStep * widthFactor + 1) // Overlap rectangles to prevent gaps
    .attr("height", legendHeight)
    .attr("stroke-width", 0)
    .attr("fill", d => colorScale(d));

  drawLegendValues(elem, colorScale, rangeFrom, rangeTo, maxValue, minValue, legendWidth);
}
开发者ID:shirish87,项目名称:grafana,代码行数:28,代码来源:color_legend.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript d3.scaleLinear函数代码示例发布时间:2022-05-25
下一篇:
TypeScript d3.quantile函数代码示例发布时间: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