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

TypeScript d3-interpolate.interpolate函数代码示例

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

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



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

示例1: interpolate

export default <T extends object>(
  { startValue, endValue, onFinish }: TransitionOptions<T>,
  onUpdate: Callback<T>,
) => {
  const interp = interpolate(startValue, endValue);
  onUpdate(interp(0));
  onUpdate(interp(0.5));
  onUpdate(interp(1));
  onFinish();
};
开发者ID:tessenate,项目名称:polyhedra-viewer,代码行数:10,代码来源:transition.ts


示例2: animateOnce

function animateOnce(fromValue: any, toValue: any, durationMs: number, onFrame: (t: number) => void) {
  const interpolator = d3Interpolate.interpolate(fromValue, toValue);
  const frameCount = Math.ceil(durationMs / 1000 * ANIMATION_FRAMERATE);

  let frame = 1;
  const setIntervalId = setInterval(() => {
    onFrame(interpolator(d3Ease.easeCubicInOut(frame / frameCount)));
    if (frame === frameCount) {
      clearInterval(setIntervalId);
    }
    frame++;
  }, durationMs / frameCount);

  return () => { clearInterval(setIntervalId); };
}
开发者ID:briann,项目名称:react-layered-chart,代码行数:15,代码来源:AnimateProps.ts


示例3: improviseGradientFromShorter

    improviseGradientFromShorter(shortColors: Color[], numColors: number): Color[] {
        const newColors = clone(shortColors)

        while (newColors.length < numColors) {
            for (let i = newColors.length - 1; i > 0; i -= 1) {
                const startColor = rgb(newColors[i - 1])
                const endColor = rgb(newColors[i])
                const newColor = interpolate(startColor, endColor)(0.5)
                newColors.splice(i, 0, newColor)

                if (newColors.length >= numColors) break
            }
        }

        return newColors
    }
开发者ID:OurWorldInData,项目名称:owid-grapher,代码行数:16,代码来源:ColorSchemes.ts


示例4: interpolateArray

function interpolateArray(scaleArr: string[]) {
    const N = scaleArr.length - 2 // -1 for spacings, -1 for number of interpolate fns
    const intervalWidth = 1 / N
    const intervals: Array<(t: number) => string> = []

    for (let i = 0; i <= N; i++) {
        intervals[i] = interpolate(rgb(scaleArr[i]), rgb(scaleArr[i + 1]))
    }

    return (t: number) => {
        if (t < 0 || t > 1) throw new Error('Outside the allowed range of [0, 1]')

        const i = Math.floor(t * N)
        const intervalOffset = i * intervalWidth

        return intervals[i](t / intervalWidth - intervalOffset / intervalWidth)
    }
}
开发者ID:OurWorldInData,项目名称:owid-grapher,代码行数:18,代码来源:ColorSchemes.ts


示例5: interpolate

/**
 * An animation function based on d3's interpolate.
 * @returns an cancel() function
 */
export default function transition<T extends object>(
  options: TransitionOptions<T>,
  updateCallback: Callback<T>,
) {
  const {
    startValue,
    endValue,
    // Duration, in milliseconds
    duration,
    ease = 'easePolyInOut',
    onFinish = _.noop,
  } = options;
  let start = 0;
  const id: { current?: number } = {};
  // Adapted from:
  // https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame
  const interp = interpolate(startValue, endValue);
  const step = (timestamp: number) => {
    if (!start) {
      start = timestamp;
    }
    const delta = timestamp - start;
    const progress = Math.min(delta / duration, 1);
    const currentValue = interp(d3[ease](progress));
    updateCallback(currentValue);
    if (delta < duration) {
      id.current = requestAnimationFrame(step);
    } else {
      onFinish();
    }
  };
  id.current = requestAnimationFrame(step);
  return {
    cancel() {
      cancelAnimationFrame(id.current!);
    },
  };
}
开发者ID:tessenate,项目名称:polyhedra-viewer,代码行数:42,代码来源:transition.ts


示例6: Date

    iKeyVal: Interpolator<{ [key: string]: any }>,
    iRGBColorObj: Interpolator<d3Color.RGBColor>,
    iZoom: d3Interpolate.ZoomInterpolator;

let num: number,
    str: string,
    arrNum: number[],
    arrStr: string[],
    objKeyVal: { [key: string]: any },
    objRGBColor: d3Color.RGBColor,
    objHSVColor: d3Hsv.HSVColor,
    zoom: [number, number, number];

// test interpolate(a, b) signature ----------------------------------------------------

iNum = d3Interpolate.interpolate('1', 5);


// color interpolator returning a color string
iString = d3Interpolate.interpolate('seagreen', d3Color.rgb(100, 100, 100));
iString = d3Interpolate.interpolate('seagreen', d3Hsv.hsv(60, 1, 0.2, 0.4));
iString = d3Interpolate.interpolate('seagreen', 'steelblue'); // as used with valid color name string

// date interpolator
iDate = d3Interpolate.interpolate(new Date(2016, 6, 1), new Date(2016, 6, 31));

// regular string interpolator interpolating number strings (as the strings are not valid color strings)
iString = d3Interpolate.interpolate(1, '5');
iString = d3Interpolate.interpolate('a: 1', 'a: 5');
iString = d3Interpolate.interpolate(new StringCoercible('a: 1'), 'a: 5');
开发者ID:ArtemZag,项目名称:DefinitelyTyped,代码行数:30,代码来源:d3-interpolate-tests.ts


示例7: return

 return (d: any) => {
   const interpolator = interpolate(start, target);
   return (t) => {
     return this.arcGenerator(interpolator(t));
   }
 };
开发者ID:iteratec,项目名称:OpenSpeedMonitor,代码行数:6,代码来源:csi-value-svg.renderer.ts


示例8: Date

let iRGBColorObj: Interpolator<d3Color.RGBColor>;
let iZoom: d3Interpolate.ZoomInterpolator;

let num: number;
let str: string;
let arrNum: number[];
let arrStr: string[];
let objKeyVal: { [key: string]: any };
let xyz: Xyz;
let objRGBColor: d3Color.RGBColor;
let zoom: [number, number, number];

// test interpolate(a, b) signature ----------------------------------------------------

// $ExpectError
iNum = d3Interpolate.interpolate('1', 5); // fails, https://github.com/Microsoft/TypeScript/issues/4002#issuecomment-124201510

// null and boolean interpolator
iNull = d3Interpolate.interpolate(null, null);
iNull = d3Interpolate.interpolate(10, null);
iBoolean = d3Interpolate.interpolate(false, true);
iBoolean = d3Interpolate.interpolate("10", true);

// color interpolator returning a color string
iString = d3Interpolate.interpolate('seagreen', d3Color.rgb(100, 100, 100));
iString = d3Interpolate.interpolate('seagreen', d3Hsv.hsv(60, 1, 0.2, 0.4));
iString = d3Interpolate.interpolate('seagreen', 'steelblue'); // as used with valid color name string

// date interpolator
iDate = d3Interpolate.interpolate(new Date(2016, 6, 1), new Date(2016, 6, 31));
开发者ID:AlexGalays,项目名称:DefinitelyTyped,代码行数:30,代码来源:d3-interpolate-tests.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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