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


TypeScript d3.range函数代码示例

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


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

示例1: 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:PaulMest,项目名称:grafana,代码行数:28,代码来源:color_legend.ts

示例2: 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:PaulMest,项目名称:grafana,代码行数:34,代码来源:color_legend.ts

示例3: 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 = 10;
  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:PaulMest,项目名称:grafana,代码行数:26,代码来源:color_legend.ts

示例4: drawSimpleColorLegend

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

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

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

    let legend = d3.select(legendElem.get(0));
    var 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:PaulMest,项目名称:grafana,代码行数:24,代码来源:color_legend.ts


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