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

TypeScript d3.bisector函数代码示例

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

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



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

示例1: init

    init() {
        const {target, width, height, margin} = this;
        // const {xTicks, yTicks, yRange} = this;
        const {xTicks, yRange} = this;
        const [w, h] = this.dimensions();

        this.chart = d3.select(target)
            .attr('width', width)
            .attr('height', height)
            .append('g')
            .attr('transform', `translate(${margin.left}, ${margin.top})`);

        this.x = d3.time.scale()
            .range([0, w]);

        this.y = d3.scale.linear()
            .range(yRange);

        this.xAxis = d3.svg.axis()
            .orient('bottom')
            .scale(this.x)
            .ticks(xTicks)
            .tickPadding(8)
            .tickSize(-h);

        this.chart.append('g')
            .attr('class', 'x axis')
            .attr('transform', `translate(0, ${h})`)
            .call(this.xAxis);


        his.details = this.chart.append('g')
            .attr('class', 'details')
            .style('display', 'none')

        this.details.append('line')
            .attr('class', 'x')
            .attr('y1', 0)
            .attr('y1', h)

        this.details.append('text')
            .attr('class', 'time')

        this.details.append('g')
            .attr('class', 'data')

        this.overlay = this.chart.append('rect')
            .attr('class', 'overlay')
            .attr('width', w)
            .attr('height', h)
            .style('fill-opacity', 0)
            .on('mousemove', _ => this.onMouseOver())
            .on('mouseleave', _ => this.onMouseLeave());

        this.xBisect = d3.bisector(d => d.time).left;


    }
开发者ID:xsurge83,项目名称:d3-charts,代码行数:58,代码来源:main.ts


示例2: getClosestItemIndexes2

export function getClosestItemIndexes2(array: Array<number>, value: number, accessor: any): { left: number, right: number } {
  let left: number = d3.bisector(accessor).left(array, value);
  left = Math.max(left - 1, 0);
  let right: number = Math.min(left + 1, array.length - 1);

  let item: number = accessor(array[left]);
  if (item >= value && item <= value) {
    right = left;
  }

  return { left, right };
}
开发者ID:Svjard,项目名称:ng2-stockcharts,代码行数:12,代码来源:index.ts


示例3: financeEODScale

export default function financeEODScale(indexAccessor = d => d.idx, dateAccessor = d => d.date, data = [0, 1], backingLinearScale = d3.scale.linear()) {

  var timeScaleSteps = [
    { step: 864e5, f: function(d) { return isDefined(dateAccessor(d)) && true; } },  // 1-day
    { step: 1728e5, f: function(d, i) { return isDefined(dateAccessor(d)) && (i % 2 === 0); } }, // 2-day
    { step: 8380e5, f: function(d, i, arr) {
      if (d.startOfMonth) return true;
      var list = [];
      if ((i - 2) >= 0) list.push(arr[i - 2]);
      if ((i - 1) >= 0) list.push(arr[i - 1]);
      list.push(arr[i]);
      if ((i + 1) <= arr.length - 1) list.push(arr[i + 1]);
      if ((i + 2) <= arr.length - 1) list.push(arr[i + 2]);
      var sm = list
            .map(function(each) { return each.startOfMonth; })
            .reduce(function(prev, curr) {
              return prev || curr;
            });
      return sm ? false : d.startOfWeek;
    } },  // 1-week
    { step: 3525e6, f: function(d) {return d.startOfMonth; } },  // 1-month
    { step: 7776e6, f: function(d) {return d.startOfQuarter; } },  // 3-month
    { step: 31536e6, f: function(d) {return d.startOfYear; } },  // 1-year
    { step: 91536e15, f: function(d) {return isDefined(dateAccessor(d)) && (d.startOfYear && dateAccessor(d).getFullYear() % 2 === 0); } }  // 2-year
  ];
  var timeScaleStepsBisector = d3.bisector(function(d) { return d.step; }).left;
  var bisectByIndex = d3.bisector(function(d) { return indexAccessor(d); }).left;
  var tickFormat = [
    [d3.time.format("%Y"), function(d) { return d.startOfYear; }],
    [d3.time.format("%b %Y"), function(d) { return d.startOfQuarter; }],
    [d3.time.format("%b"), function(d) { return d.startOfMonth; }],
    [d3.time.format("%d %b"), function(d) { return d.startOfWeek; }],
    [d3.time.format("%a %d "), function(/* d */) { return true; }]
  ];
  function formater(d) {
    var i = 0, format = tickFormat[i];
    while (!format[1](d)) format = tickFormat[++i];
    var tickDisplay = format[0](dateAccessor(d));
    // console.log(t;ickDisplay);
    return tickDisplay;
  }

  function scale(x) {
    return backingLinearScale(x);
  }
  scale.isPolyLinear = function() {
    return true;
  };
  scale.invert = function(x) {
    return backingLinearScale.invert(x);
  };
  scale.data = function(x) {
    if (!arguments.length) {
      return data;
    } else {
      data = x;
      // this.domain([data.first().index, data.last().index]);
      this.domain([indexAccessor(data[0]), indexAccessor(data[data.length - 1])]);
      return scale;
    }
  };
  scale.indexAccessor = function(x) {
    if (!arguments.length) return indexAccessor;
    indexAccessor = x;
    return scale;
  };
  scale.dateAccessor = function(x) {
    if (!arguments.length) return dateAccessor;
    dateAccessor = x;
    return scale;
  };
  scale.domain = function(x) {
    if (!arguments.length) return backingLinearScale.domain();
    // console.log("before = %s, after = %s", JSON.stringify(backingLinearScale.domain()), JSON.stringify(x))

    var d = [x[0], x[1]];
    // console.log(d);
    backingLinearScale.domain(d);
    return scale;
  };
  scale.range = function(x) {
    if (!arguments.length) return backingLinearScale.range();
    backingLinearScale.range(x);
    return scale;
  };
  scale.rangeRound = function(x) {
    return backingLinearScale.range(x);
  };
  scale.clamp = function(x) {
    if (!arguments.length) return backingLinearScale.clamp();
    backingLinearScale.clamp(x);
    return scale;
  };
  scale.interpolate = function(x) {
    if (!arguments.length) return backingLinearScale.interpolate();
    backingLinearScale.interpolate(x);
    return scale;
  };
  scale.ticks = function(m) {
    var start, end, count = 0;
//.........这里部分代码省略.........
开发者ID:Svjard,项目名称:ng2-stockcharts,代码行数:101,代码来源:financeEODDiscontinuousScale.ts


示例4: Error

  { target: 55e4, level: 4 },
  { target: 11e5, level: 5 },
  { target: 21e5, level: 6 },
  { target: 43e5, level: 7 },
  { target: 49e5, level: 8 }, // not tested
  { target: 50e5, level: 9 }, // not tested
  { target: 58e6, level: 10 }, // not tested
  { target: 58e6, level: 11 },
  { target: 11e7, level: 12 },
  { target: 78e7, level: 13 },
  { target: 16e8, level: 14 },
  { target: 62e8, level: 15 },
  { target: 10e20, level: 16 },
];

var tickLevelBisector = d3.bisector(function(d) { return d.target; }).left;

export default function financeDiscontinuousScale(index,
    interval,
    backingLinearScale = d3.scale.linear()) {

  if (isNotDefined(index) || isNotDefined(interval))
    throw new Error("Use the discontinuousTimeScaleProvider to create financeDiscontinuousScale");

  function scale(x) {
    return backingLinearScale(x);
  }
  scale.invert = function(x) {
    var inverted = backingLinearScale.invert(x);
    return Math.round(inverted * 10000) / 10000;
  };
开发者ID:Svjard,项目名称:ng2-stockcharts,代码行数:31,代码来源:financeDiscontinuousScale.ts


示例5: financeIntradayScale

export default function financeIntradayScale(indexAccessor = d => d.idx, dateAccessor = d => d.date, data = [0, 1], backingLinearScale = d3.scale.linear()) {

  var timeScaleSteps = [
    { step: 40000, f: function(d) { return isDefined(dateAccessor(d)) && (d.startOfDay || d.startOfMinute); } }, // 1 min
    { step: 192000, f: function(d) { return isDefined(dateAccessor(d)) && (d.startOfDay || d.startOf5Minutes); } }, // 5 min
    { step: 400000, f: function(d) { return isDefined(dateAccessor(d)) && (d.startOfDay || d.startOfQuarterHour); } },
    { step: 6684000, f: function(d) { return isDefined(dateAccessor(d)) && (d.startOfDay || d.startOfHalfHour); } },
    { step: 108e5, f: function(d) { return isDefined(dateAccessor(d)) && (d.startOfDay || d.startOfHour); } },
    { step: 216e5, f: function(d) { return isDefined(dateAccessor(d)) && (d.startOfDay || d.startOfEighthDay); } },
    { step: 432e5, f: function(d) { return isDefined(dateAccessor(d)) && (d.startOfDay || d.startOfQuarterDay); } }, // 12 hours
    { step: 864e5, f: function(d) { return isDefined(dateAccessor(d)) && (d.startOfDay || d.startOfHalfDay); } },  // 1-day
    { step: 2592e5, f: function(d) { return isDefined(dateAccessor(d)) && d.startOfDay; } },  // 3-day, doesnt work with 2h scale
    { step: 6048e5, f: function(d) { return isDefined(dateAccessor(d)) && (d.startOfDay && dateAccessor(d).getDate() % 3 === 0); } },  // 7-day
    { step: 12096e5, f: function(d) { return isDefined(dateAccessor(d)) && (d.startOfDay && dateAccessor(d).getDate() % 3 === 0); } }  // 14-day
  ];
  var timeScaleStepsBisector = d3.bisector(function(d) { return d.step; }).left;
  var bisectByIndex = d3.bisector(function(d) { return indexAccessor(d); }).left;
  var tickFormat = [
    [d3.time.format.utc("%a %d"), function(d) { return d.startOfDay; }],
    [d3.time.format.utc("%_I %p"), function(d) { return d.startOfHour && !d.startOfDay; }],
    [d3.time.format.utc("%I:%M %p"), d3.functor(true)] // accumulator fallback for first entry
  ];
  function formater(d) {
    var i = 0, format = tickFormat[i];
    while (!format[1](d)) format = tickFormat[++i];
    var tickDisplay = format[0](dateAccessor(d));
    // console.log(t;ickDisplay);
    return tickDisplay;
  }

  function scale(x) {
    return backingLinearScale(x);
  }
  scale.isPolyLinear = function() {
    return true;
  };
  scale.invert = function(x) {
    return backingLinearScale.invert(x);
  };
  scale.data = function(x) {
    if (!arguments.length) {
      return data;
    } else {
      data = x;
      // this.domain([data.first().index, data.last().index]);
      this.domain([indexAccessor(data[0]), indexAccessor(data[data.length - 1])]);
      return scale;
    }
  };
  scale.indexAccessor = function(x) {
    if (!arguments.length) return indexAccessor;
    indexAccessor = x;
    return scale;
  };
  scale.dateAccessor = function(x) {
    if (!arguments.length) return dateAccessor;
    dateAccessor = x;
    return scale;
  };
  scale.domain = function(x) {
    if (!arguments.length) return backingLinearScale.domain();
    // console.log("before = %s, after = %s", JSON.stringify(backingLinearScale.domain()), JSON.stringify(x))

    var d = [x[0], x[1]];
    // console.log(d);
    backingLinearScale.domain(d);
    return scale;
  };
  scale.range = function(x) {
    if (!arguments.length) return backingLinearScale.range();
    backingLinearScale.range(x);
    return scale;
  };
  scale.rangeRound = function(x) {
    return backingLinearScale.range(x);
  };
  scale.clamp = function(x) {
    if (!arguments.length) return backingLinearScale.clamp();
    backingLinearScale.clamp(x);
    return scale;
  };
  scale.interpolate = function(x) {
    if (!arguments.length) return backingLinearScale.interpolate();
    backingLinearScale.interpolate(x);
    return scale;
  };
  scale.ticks = function(m) {
    /* var start, end, count = 0;
    data.forEach(function(d) {
      if (isDefined(dateAccessor(d))) {
        if (isNotDefined(start)) start = d;
        end = d;
        count++;
      }
    });
    console.log(count / data.length);
    m = (count / data.length) * m;
    */

    var start = head(data);
//.........这里部分代码省略.........
开发者ID:Svjard,项目名称:ng2-stockcharts,代码行数:101,代码来源:financeIntradayDiscontinuousScale.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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