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

TypeScript array.sortBy函数代码示例

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

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



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

示例1: _paint_levels

  _paint_levels(ctx: Context2d, levels, clip_region = null) {
    ctx.save();

    if ((clip_region != null) && (this.model.plot.output_backend === "canvas")) {
      ctx.beginPath();
      ctx.rect.apply(ctx, clip_region);
      ctx.clip();
    }

    const indices = {};
    for (let i = 0; i < this.model.plot.renderers.length; i++) {
      const renderer = this.model.plot.renderers[i];
      indices[renderer.id] = i;
    }

    const sortKey = renderer_view => indices[renderer_view.model.id];

    for (const level of levels) {
      const renderer_views = sortBy(values(this.levels[level]), sortKey);

      for (const renderer_view of renderer_views) {
        renderer_view.render();
      }
    }

    return ctx.restore();
  }
开发者ID:FourtekIT-incubator,项目名称:bokeh,代码行数:27,代码来源:plot_canvas.ts


示例2: _paint_levels

  protected _paint_levels(ctx: Context2d, levels: string[], clip_region?: FrameBox): void {
    ctx.save()

    if (clip_region != null) {
      ctx.beginPath()
      ctx.rect.apply(ctx, clip_region)
      ctx.clip()
    }

    const indices: {[key: string]: number} = {}
    for (let i = 0; i < this.model.plot.renderers.length; i++) {
      const renderer = this.model.plot.renderers[i]
      indices[renderer.id] = i
    }

    const sortKey = (renderer_view: RendererView) => indices[renderer_view.model.id]

    for (const level of levels) {
      const renderer_views = sortBy(values(this.levels[level]), sortKey)

      for (const renderer_view of renderer_views) {
        renderer_view.render()
      }
    }

    ctx.restore()
  }
开发者ID:gully,项目名称:bokeh,代码行数:27,代码来源:plot_canvas.ts


示例3: _merge_tools

  protected _merge_tools(): void {
    // Go through all the tools on the toolbar and replace them with
    // a proxy e.g. PanTool, BoxSelectTool, etc.
    this._proxied_tools = []

    const inspectors: {[key: string]: InspectTool[]} = {}
    const actions: {[key: string]: ActionTool[]} = {}
    const gestures: {[key: string]: {[key: string]: GestureTool[]}} = {}

    const new_help_tools = []
    const new_help_urls = []
    for (const helptool of this.help) {
      if (!includes(new_help_urls, helptool.redirect)) {
        new_help_tools.push(helptool)
        new_help_urls.push(helptool.redirect)
      }
    }
    this._proxied_tools.push(...new_help_tools)
    this.help = new_help_tools

    for (const event_type in this.gestures) {
      const gesture = this.gestures[event_type as GestureType]
      if (!(event_type in gestures)) {
        gestures[event_type] = {}
      }
      for (const tool of gesture.tools) {
        if (!(tool.type in gestures[event_type])) {
          gestures[event_type][tool.type] = []
        }
        gestures[event_type][tool.type].push(tool)
      }
    }

    for (const tool of this.inspectors) {
      if (!(tool.type in inspectors)) {
        inspectors[tool.type] = []
      }
      inspectors[tool.type].push(tool)
    }

    for (const tool of this.actions) {
      if (!(tool.type in actions)) {
        actions[tool.type] = []
      }
      actions[tool.type].push(tool)
    }

    // Add a proxy for each of the groups of tools.
    const make_proxy = (tools: ButtonTool[], active: boolean = false) => {
      const proxy = new ToolProxy({tools, active})
      this._proxied_tools.push(proxy)
      return proxy
    }

    for (const event_type in gestures) {
      const gesture = this.gestures[event_type as GestureType]
      gesture.tools = []

      for (const tool_type in gestures[event_type]) {
        const tools = gestures[event_type][tool_type]

        if (tools.length > 0) {
          const proxy = make_proxy(tools)
          gesture.tools.push(proxy as any)
          this.connect(proxy.properties.active.change, this._active_change.bind(this, proxy))
        }
      }
    }

    this.actions = []
    for (const tool_type in actions) {
      const tools = actions[tool_type]

      if (tools.length > 0)
        this.actions.push(make_proxy(tools) as any) // XXX
    }

    this.inspectors = []
    for (const tool_type in inspectors) {
      const tools = inspectors[tool_type]

      if (tools.length > 0)
        this.inspectors.push(make_proxy(tools, true) as any) // XXX
    }

    for (const et in this.gestures) {
      const gesture = this.gestures[et as GestureType]
      if (gesture.tools.length == 0)
        continue

      gesture.tools = sortBy(gesture.tools, (tool) => tool.default_order)

      if (!(et == 'pinch' || et == 'scroll' || et == 'multi'))
        gesture.tools[0].active = true
    }
  }
开发者ID:Zyell,项目名称:bokeh,代码行数:96,代码来源:toolbar_box.ts


示例4: _merge_tools

  _merge_tools() {
    // Go through all the tools on the toolbar and replace them with
    // a proxy e.g. PanTool, BoxSelectTool, etc.

    let active, tools;
    this._proxied_tools = [];

    const inspectors = {};
    const actions = {};
    const gestures = {};

    const new_help_tools = [];
    const new_help_urls = [];
    for (const helptool of this.help) {
      if (!includes(new_help_urls, helptool.redirect)) {
        new_help_tools.push(helptool);
        new_help_urls.push(helptool.redirect);
      }
    }
    this._proxied_tools.push(...new_help_tools || []);
    this.help = new_help_tools;

    for (const event_type in this.gestures) {
      const info = this.gestures[event_type];
      if (!(event_type in gestures)) {
        gestures[event_type] = {};
      }
      for (const tool of info.tools) {
        if (!(tool.type in gestures[event_type])) {
          gestures[event_type][tool.type] = [];
        }
        gestures[event_type][tool.type].push(tool);
      }
    }

    for (const tool of this.inspectors) {
      if (!(tool.type in inspectors)) {
        inspectors[tool.type] = [];
      }
      inspectors[tool.type].push(tool);
    }

    for (const tool of this.actions) {
      if (!(tool.type in actions)) {
        actions[tool.type] = [];
      }
      actions[tool.type].push(tool);
    }

    // Add a proxy for each of the groups of tools.
    const make_proxy = (tools, active = false) => {
      const proxy = new ToolProxy({tools, active});
      this._proxied_tools.push(proxy);
      return proxy;
    };

    for (const event_type in gestures) {
      this.gestures[event_type].tools = [];
      for (const tool_type in gestures[event_type]) {
        tools = gestures[event_type][tool_type];
        if (tools.length > 0) {
          const proxy = make_proxy(tools);
          this.gestures[event_type].tools.push(proxy);
          this.connect(proxy.properties.active.change, this._active_change.bind(this, proxy));
        }
      }
    }

    this.actions = [];
    for (const tool_type in actions) {
      tools = actions[tool_type];
      if (tools.length > 0) {
        this.actions.push(make_proxy(tools));
      }
    }

    this.inspectors = [];
    for (const tool_type in inspectors) {
      tools = inspectors[tool_type];
      if (tools.length > 0) {
        this.inspectors.push(make_proxy(tools, (active=true)));
      }
    }

    for (const et in this.gestures) {
      ({ tools } = this.gestures[et]);
      if (tools.length === 0) {
        continue;
      }
      this.gestures[et].tools = sortBy(tools, tool => tool.default_order);
      if (!(et == 'pinch' || et == 'scroll' || et == 'multi'))
        this.gestures[et].tools[0].active = true;
    }
  }
开发者ID:FourtekIT-incubator,项目名称:bokeh,代码行数:94,代码来源:toolbar_box.ts


示例5: function

 const _widths = function(fmt_strings) {
   const sizes = (fmt_strings.map((fmt_string) => _strftime(now, fmt_string).length));
   const sorted = sortBy(zip(sizes, fmt_strings), function(...args) { const [size,] = args[0]; return size; });
   return unzip(sorted);
 };
开发者ID:FourtekIT-incubator,项目名称:bokeh,代码行数:5,代码来源:datetime_tick_formatter.ts


示例6: _init_tools

  _init_tools() {
    for (const tool of this.tools) {
      if (tool instanceof InspectTool) {
        if (!any(this.inspectors, t => t.id === tool.id)) {
          this.inspectors = this.inspectors.concat([tool]);
        }
      } else if (tool instanceof HelpTool) {
        if (!any(this.help, t => t.id === tool.id)) {
          this.help = this.help.concat([tool]);
        }
      } else if (tool instanceof ActionTool) {
        if (!any(this.actions, t => t.id === tool.id)) {
          this.actions = this.actions.concat([tool]);
        }
      } else if (tool instanceof GestureTool) {
        let event_types = tool.event_type;
        let multi = true;
        if (typeof event_types === 'string') {
          event_types = [event_types];
          multi = false;
        }

        for (let et of event_types) {
          if (!(et in this.gestures)) {
            logger.warn(`Toolbar: unknown event type '${et}' for tool: ${tool.type} (${tool.id})`);
            continue;
          }

          if (multi)
            et = "multi"

          if (!any(this.gestures[et].tools, t => t.id === tool.id))
            this.gestures[et].tools = this.gestures[et].tools.concat([tool]);

          this.connect(tool.properties.active.change, this._active_change.bind(this, tool));
        }
      }
    }

    if (this.active_inspect === 'auto') {
      // do nothing as all tools are active be default

    } else if (this.active_inspect instanceof InspectTool) {
      this.inspectors.map(inspector => { if (inspector !== this.active_inspect) { return inspector.active = false; } });
    } else if (this.active_inspect instanceof Array) {
      this.inspectors.map(inspector => { if (!includes(this.active_inspect, inspector)) { return inspector.active = false; } });
    } else if (this.active_inspect === null) {
      this.inspectors.map(inspector => inspector.active = false);
    }

    const _activate_gesture = tool => {
      if (tool.active) {
        // tool was activated by a proxy, but we need to finish configuration manually
        return this._active_change(tool);
      } else {
        return tool.active = true;
      }
    };

    for (const et in this.gestures) {
      const { tools } = this.gestures[et];
      if (tools.length === 0) {
        continue;
      }
      this.gestures[et].tools = sortBy(tools, tool => tool.default_order);

      if (et === 'tap') {
        if (this.active_tap === null) {
          continue;
        }
        if (this.active_tap === 'auto') {
          _activate_gesture(this.gestures[et].tools[0]);
        } else {
          _activate_gesture(this.active_tap);
        }
      }

      if (et === 'pan') {
        if (this.active_drag === null) {
          continue;
        }
        if (this.active_drag === 'auto') {
          _activate_gesture(this.gestures[et].tools[0]);
        } else {
          _activate_gesture(this.active_drag);
        }
      }

      if (et == 'pinch' || et == 'scroll') {
        if ((this.active_scroll === null) || (this.active_scroll === 'auto')) {
          continue;
        }
        _activate_gesture(this.active_scroll);
      }
    }

    return null;
  }
开发者ID:FourtekIT-incubator,项目名称:bokeh,代码行数:98,代码来源:toolbar.ts


示例7: _init_tools

  protected _init_tools(): void {
    for (const tool of this.tools) {
      if (tool instanceof InspectTool) {
        if (!any(this.inspectors, (t) => t.id == tool.id)) {
          this.inspectors = this.inspectors.concat([tool])
        }
      } else if (tool instanceof HelpTool) {
        if (!any(this.help, (t) => t.id == tool.id)) {
          this.help = this.help.concat([tool])
        }
      } else if (tool instanceof ActionTool) {
        if (!any(this.actions, (t) => t.id == tool.id)) {
          this.actions = this.actions.concat([tool])
        }
      } else if (tool instanceof GestureTool) {
        let event_types: GestureType[]
        let multi: boolean
        if (isString(tool.event_type)) {
          event_types = [tool.event_type]
          multi = false
        } else {
          event_types = tool.event_type || []
          multi = true
        }

        for (let et of event_types) {
          if (!(et in this.gestures)) {
            logger.warn(`Toolbar: unknown event type '${et}' for tool: ${tool.type} (${tool.id})`)
            continue
          }

          if (multi)
            et = "multi"

          if (!any(this.gestures[et].tools, (t) => t.id == tool.id))
            this.gestures[et].tools = this.gestures[et].tools.concat([tool])

          this.connect(tool.properties.active.change, this._active_change.bind(this, tool))
        }
      }
    }

    if (this.active_inspect == 'auto') {
      // do nothing as all tools are active be default
    } else if (this.active_inspect instanceof InspectTool) {
      for (const inspector of this.inspectors) {
        if (inspector != this.active_inspect)
          inspector.active = false
      }
    } else if (isArray(this.active_inspect)) {
      for (const inspector of this.inspectors) {
        if (!includes(this.active_inspect, inspector))
          inspector.active = false
      }
    } else if (this.active_inspect == null) {
      for (const inspector of this.inspectors)
        inspector.active = false
    }

    const _activate_gesture = (tool: Tool) => {
      if (tool.active) {
        // tool was activated by a proxy, but we need to finish configuration manually
        this._active_change(tool)
      } else
        tool.active = true
    }

    for (const et in this.gestures) {
      const gesture = this.gestures[et as GestureType]

      if (gesture.tools.length == 0)
        continue

      gesture.tools = sortBy(gesture.tools, (tool) => tool.default_order)

      if (et == 'tap') {
        if (this.active_tap == null)
          continue

        if (this.active_tap == 'auto')
          _activate_gesture(gesture.tools[0])
        else
          _activate_gesture(this.active_tap)
      }

      if (et == 'pan') {
        if (this.active_drag == null)
          continue

        if (this.active_drag == 'auto')
          _activate_gesture(gesture.tools[0])
        else
          _activate_gesture(this.active_drag)
      }

      if (et == 'pinch' || et == 'scroll') {
        if (this.active_scroll == null || this.active_scroll == 'auto')
          continue
        _activate_gesture(this.active_scroll)
      }
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript array.sum函数代码示例发布时间:2022-05-24
下一篇:
TypeScript array.reversed函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap