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


TypeScript d3-scale.scaleLinear函数代码示例

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


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

示例1: drawChart

function drawChart(user: PuzzleUserData) {
  const history = Array.from(user.recent.map(x => x[2]))
  const rating = user.rating
  if (rating !== undefined) {
    history.push(rating)
  }
  const data = history.map((x, i) => [i + 1, x])
  const graph = select('#training-graph')
  const margin = {top: 5, right: 20, bottom: 5, left: 35}
  const width = +graph.attr('width') - margin.left - margin.right
  const height = +graph.attr('height') - margin.top - margin.bottom
  const g = graph.append('g').attr('transform', 'translate(' + margin.left + ',' + margin.top + ')')

  const xvalues = data.map(d => d[0])
  const scaleX = scaleLinear()
  .domain([Math.min.apply(null, xvalues), Math.max.apply(null, xvalues)])
  .rangeRound([0, width])

  const yvalues = data.map(d => d[1])
  const scaleY = scaleLinear()
  .domain([Math.min.apply(null, yvalues) - 10, Math.max.apply(null, yvalues) + 10])
  .rangeRound([height, 0])

  const area = d3Area()
  .x(d => scaleX(d[0]))
  .y0(height)
  .y1(d => scaleY(d[1]))

  const line = d3Area()
  .x(d => scaleX(d[0]))
  .y(d => scaleY(d[1]))

  const yAxis = axisLeft(scaleY)
  .tickFormat(d => String(d))

  g.datum(data)

  g.append('g')
  .call(yAxis)
  .append('text')
  .attr('class', 'legend')
  .attr('transform', 'rotate(-90)')
  .attr('y', 6)
  .attr('dy', '0.71em')
  .attr('text-anchor', 'end')
  .text(i18n('rating'))

  g.append('path')
  .attr('class', 'path')
  .attr('fill', 'steelblue')
  .attr('stroke', 'steelblue')
  .attr('stroke-linejoin', 'round')
  .attr('stroke-linecap', 'round')
  .attr('stroke-width', 0)
  .attr('d', area)

  g.append('path')
  .attr('class', 'line')
  .attr('d', line)
}
开发者ID:mbensley,项目名称:lichobile,代码行数:60,代码来源:menu.ts

示例2: niceInterval

export function niceInterval(interval: Interval): Interval {
  const nicedInterval = d3Scale.scaleLinear().domain([ interval.min, interval.max ]).nice().domain();
  return {
    min: nicedInterval[0],
    max: nicedInterval[1]
  }
}
开发者ID:abe732,项目名称:react-layered-chart,代码行数:7,代码来源:intervalUtils.ts

示例3: generateColorScheme

  generateColorScheme(scheme, type, domain) {
    if (typeof(scheme) === 'string') {
      scheme = colorSets.find(cs => {
        return cs.name === scheme;
      });
    }
    let colorScale;
    if (type === 'quantile') {
      colorScale = scaleQuantile()
        .range(scheme.domain)
        .domain(domain);

    } else if (type === 'ordinal') {
      colorScale = scaleOrdinal()
        .range(scheme.domain)
        .domain(domain);

    } else if (type === 'linear') {
      // linear schemes must have at least 2 colors
      const colorDomain = [...scheme.domain];
      if (colorDomain.length === 1) {
        colorDomain.push(colorDomain[0]);
        this.colorDomain = colorDomain;
      }

      const points = range(0, 1, 1.0 / colorDomain.length);
      colorScale = scaleLinear()
        .domain(points)
        .range(colorDomain);
    }

    return colorScale;
  }
开发者ID:emilkpetkov,项目名称:ngx-charts,代码行数:33,代码来源:color.helper.ts

示例4: function

var getMaxTickLabelSize = function (domainValues, formatter, fnCalcTickLabelSize, axisLabelLimit) {

    if (domainValues.length === 0) {
        return {width: 0, height: 0};
    }

    if (formatter === null) {
        var size = fnCalcTickLabelSize('TauChart Library');
        size.width = axisLabelLimit * 0.625; // golden ratio
        return size;
    }

    if (domainValues.every(d => (typeof d === 'number'))) {
        domainValues = d3.scaleLinear().domain(domainValues).ticks();
    }

    var maxXTickText = domainValues.reduce((prev, value) => {
        let computed = formatter(value).toString().length;

        if (!prev.computed || computed > prev.computed) {
            return {
                value: value,
                computed: computed
            };
        }
        return prev;
    }, {}).value;

    return fnCalcTickLabelSize(formatter(maxXTickText));
};
开发者ID:TargetProcess,项目名称:tauCharts,代码行数:30,代码来源:spec-transform-auto-layout.ts

示例5: getColor

  getColor(value) {
    if (this.scaleType === 'linear') {
      const valueScale = scaleLinear()
        .domain(this.domain)
        .range([0, 1]);

      return (this.scale(valueScale(value)));
    } else {

      if(typeof this.customColors === 'function') {
        return this.customColors(value);
      }

      const formattedValue = value.toString();
      let found: any; // todo type customColors
      if (this.customColors && this.customColors.length > 0) {
        found = this.customColors.find((mapping) => {
          return mapping.name.toLowerCase() === formattedValue.toLowerCase();
        });
      }

      if (found) {
        return found.value;
      } else {
        return this.scale(value);
      }
    }
  }
开发者ID:emilkpetkov,项目名称:ngx-charts,代码行数:28,代码来源:color.helper.ts

示例6: constructor

  constructor(column: DataGridColumn, state: IHihglighterState) {
    super(column, state);

    this.state.minColor = formatColor(state.minColor || getDefaultColor('blue'));
    this.state.maxColor = formatColor(state.maxColor || getDefaultColor('red'));

    this.colorScale = d3scale.scaleLinear()
      .domain([this.state.minVal, this.state.maxVal])
      .range([this.state.minColor, this.state.maxColor]);
  }
开发者ID:twosigma,项目名称:beaker-notebook,代码行数:10,代码来源:HeatmapHighlighter.ts

示例7: initBarGraph

  initBarGraph() {
    const svg = selection.select('.line-graph-container')
      .append('svg')
      .attr('width', 700)
      .attr('height', 300);
    const margin = {top: 20, right: 20, bottom: 30, left: 40};
    const width = +svg.attr('width') - margin.left - margin.right;
    const height = +svg.attr('height') - margin.top - margin.bottom;
    const x = scaleBand().rangeRound([0, width]).padding(0.1);
    const y = scaleLinear().rangeRound([height, 0]);

    const g = svg.append('g')
        .attr('transform', `translate(${margin.left}, ${margin.top})`);

    // uses sample data from https://bl.ocks.org/mbostock/3885304
    (d3 as any).tsv('/assets/data.tsv').then(function(d) {
      d.frequency = +d.frequency;
      return d;
    }, function(error, data: [{ letter: string, frequency: number}]) {
      if (error) {
        throw error;
      }

      x.domain(data.map((d) => d.letter));
      y.domain(d3.extent(data, (d) => d.frequency));

      g.append('g')
        .attr('class', 'axis axis--x')
        .attr('transform', `translate(0, ${height})`)
        .call(d3.axisBottom(x));

      g.append('g')
        .attr('class', 'axis axis--y')
        .call(d3.axisLeft(y).ticks(10, '%').tickPadding(23))
        .append('text')
          .attr('transform', 'rotate(-90)')
          .attr('y', 6)
          .attr('dy', '0.71em')
          .attr('text-anchor', 'end')
          .text('Frequency');

      g.selectAll('.bar')
        .data(data)
        .enter().append('rect')
          .attr('class', 'bar')
          .attr('x', (d) => x(d.letter))
          .attr('y', (d) => y(d.frequency))
          .attr('width', x.bandwidth())
          .attr('height', (d) => height - y(d.frequency));
    });
  }
开发者ID:hasadna,项目名称:open_pension,代码行数:51,代码来源:detail-pai.component.ts

示例8: constructor

  constructor(column: DataGridColumn, state: IHihglighterState) {
    super(column, state);

    if (typeof this.state.minVal !== 'number' || typeof this.state.maxVal !== 'number' ) {
      throw new Error('Min and Max values are not set');
    }

    this.state.midVal = column.getValueResolver()(this.state.midVal || (this.state.minVal + this.state.maxVal / 2));
    this.state.midColor = formatColor(state.midColor);

    this.colorScale = d3scale.scaleLinear()
      .domain([this.state.minVal, this.state.midVal, this.state.maxVal])
      .range([this.state.minColor, this.state.midColor, this.state.maxColor]);
  }
开发者ID:twosigma,项目名称:beaker-notebook,代码行数:14,代码来源:ThreeColorHeatmapHighlighter.ts

示例9: constructor

	constructor( svg: Selection<BaseType, {}, HTMLElement, any>, dataLength: number) {
		const node: SVGSVGElement = svg.node() as SVGSVGElement
		const div: HTMLElement = node.parentNode as HTMLElement

		const width = div.clientWidth
		const height = div.clientHeight

		const x = scaleTime().range([0, width])
		const y = scaleLinear().range([height, 0])

		const minModelX = Date.now()

		const idxToTime = (idx: number) => minModelX + idx * 86400 * 1000
		const xAxis = new MyAxis(Orientation.Bottom, x)
			.ticks(4)
			.setTickSize(height)
			.setTickPadding(8 - height)
			.setScale(x)

		const yAxis = new MyAxis(Orientation.Right, y)
			.ticks(4)
			.setTickSize(width)
			.setTickPadding(2 - width)
			.setScale(y)

		const gX = svg.append('g')
			.attr('class', 'axis')
			.call(xAxis.axis.bind(xAxis))

		const gY = svg.append('g')
			.attr('class', 'axis')
			.call(yAxis.axis.bind(yAxis))

		animateBench((elapsed: number) => {
			const minY = -5
			const maxY = 83
			const minX = animateCosDown(dataLength / 2, 0, elapsed)
			const maxX = minX + dataLength / 2

			x.domain([minX, maxX].map(idxToTime))
			y.domain([minY, maxY])

			xAxis.axisUp(gX)
			yAxis.axisUp(gY)
		})
	}
开发者ID:streamcode9,项目名称:svg-time-series,代码行数:46,代码来源:draw.ts

示例10:

 colors.forEach(function (color) {
     if (prevColor) {
         const scale = d3ScaleLinear()
             .domain([0, subPaletteSize])
             .range([prevColor, color])
             .interpolate(d3InterpolateLab as any)
             ;
         for (let i = 0; i < subPaletteSize; ++i) {
             range.push(scale(i));
         }
     }
     prevColor = color;
 });
开发者ID:GordonSmith,项目名称:Visualization,代码行数:13,代码来源:Palette.ts


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