本文整理汇总了TypeScript中core/util/array.range函数的典型用法代码示例。如果您正苦于以下问题:TypeScript range函数的具体用法?TypeScript range怎么用?TypeScript range使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了range函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: get_ticks_no_defaults
get_ticks_no_defaults(data_low: number, data_high: number, _cross_loc: any, desired_n_ticks: number) {
const num_minor_ticks = this.num_minor_ticks
const minor_ticks = []
const base = this.base
const log_low = Math.log(data_low) / Math.log(base)
const log_high = Math.log(data_high) / Math.log(base)
const log_interval = log_high - log_low
let ticks: number[]
if (!isFinite(log_interval)) {
ticks = []
} else if (log_interval < 2) { // treat as linear ticker
const interval = this.get_interval(data_low, data_high, desired_n_ticks)
const start_factor = Math.floor(data_low / interval)
const end_factor = Math.ceil(data_high / interval)
ticks = range(start_factor, end_factor + 1)
.filter((factor) => factor != 0)
.map((factor) => factor*interval)
.filter((tick) => data_low <= tick && tick <= data_high)
if (num_minor_ticks > 0 && ticks.length > 0) {
const minor_interval = interval / num_minor_ticks
const minor_offsets = range(0, num_minor_ticks).map((i) => i*minor_interval)
for (const x of minor_offsets.slice(1)) {
minor_ticks.push(ticks[0] - x)
}
for (const tick of ticks) {
for (const x of minor_offsets) {
minor_ticks.push(tick + x)
}
}
}
} else {
const startlog = Math.ceil(log_low * 0.999999)
const endlog = Math.floor(log_high * 1.000001)
const interval = Math.ceil((endlog - startlog) / 9.0)
ticks = range(startlog, endlog + 1, interval)
.map((i) => Math.pow(base, i))
.filter((tick) => data_low <= tick && tick <= data_high)
if (num_minor_ticks > 0 && ticks.length > 0) {
const minor_interval = Math.pow(base, interval) / num_minor_ticks
const minor_offsets = range(1, num_minor_ticks+1).map((i) => i*minor_interval)
for (const x of minor_offsets) {
minor_ticks.push(ticks[0] / x)
}
minor_ticks.push(ticks[0])
for (const tick of ticks) {
for (const x of minor_offsets) {
minor_ticks.push(tick * x)
}
}
}
}
return {
major: ticks,
minor: minor_ticks,
}
}
示例2: get_indices
get_indices(): number[] {
const length = this.get_length()
return range(0, length != null ? length : 1)
}
示例3: _get_new_list_array
_get_new_list_array(length: number): number[][] {
return (range(0, length).map((_i) => []))
}
示例4: _get_new_nan_array
_get_new_nan_array(length: number): number[] {
return (range(0, length).map((_i) => NaN))
}
示例5: range
const values = (c: number) => range(10).map((v) => c*v)
示例6: it
it("should allow MultiSelect", async () => {
const options = range(16).map((i) => `Option ${i+1}`)
const obj = new MultiSelect({options, size: 6})
await display(obj, [500, 300])
})
示例7: render
render(): void {
if (!this.model.visible)
return
const t0 = Date.now()
const glsupport = this.glyph.glglyph
this.glyph.map_data()
const dtmap = Date.now() - t0
const tmask = Date.now()
// all_indices is in full data space, indices is converted to subset space
// either by mask_data (that uses the spatial index) or manually
let indices = this.glyph.mask_data(this.all_indices)
if (indices.length === this.all_indices.length) {
indices = range(0, this.all_indices.length)
}
const dtmask = Date.now() - tmask
const {ctx} = this.plot_view.canvas_view
ctx.save()
// selected is in full set space
const {selected} = this.model.data_source
let selected_full_indices: number[]
if (!selected || selected.is_empty()) {
selected_full_indices = []
} else {
if (this.glyph instanceof LineView && selected.selected_glyph === this.glyph.model) {
selected_full_indices = this.model.view.convert_indices_from_subset(indices)
} else {
selected_full_indices = selected.indices
}
}
// inspected is in full set space
const {inspected} = this.model.data_source
let inspected_full_indices: number[]
if (!inspected || (inspected.length === 0)) {
inspected_full_indices = []
} else {
if (inspected['0d'].glyph) {
inspected_full_indices = this.model.view.convert_indices_from_subset(indices)
} else if (inspected['1d'].indices.length > 0) {
inspected_full_indices = inspected['1d'].indices
} else {
inspected_full_indices = ((() => {
const result = []
for (const i of Object.keys(inspected["2d"].indices)) {
result.push(parseInt(i))
}
return result
})())
}
}
// inspected is transformed to subset space
const inspected_subset_indices: number[] = ((() => {
const result = []
for (const i of indices) {
if (includes(inspected_full_indices, this.all_indices[i]))
result.push(i)
}
return result
})())
const {lod_threshold} = this.plot_model
let glyph: GlyphView
let nonselection_glyph: GlyphView
let selection_glyph: GlyphView
if ((this.model.document != null ? this.model.document.interactive_duration() > 0 : false)
&& !glsupport && lod_threshold != null && this.all_indices.length > lod_threshold) {
// Render decimated during interaction if too many elements and not using GL
indices = this.decimated
glyph = this.decimated_glyph
nonselection_glyph = this.decimated_glyph
selection_glyph = this.selection_glyph
} else {
glyph = this.model.muted && this.muted_glyph != null ? this.muted_glyph : this.glyph
nonselection_glyph = this.nonselection_glyph
selection_glyph = this.selection_glyph
}
if (this.hover_glyph != null && inspected_subset_indices.length)
indices = difference(indices, inspected_subset_indices)
// Render with no selection
let dtselect: number | null = null
let trender: number
if (!(selected_full_indices.length && this.have_selection_glyphs())) {
trender = Date.now()
if (this.glyph instanceof LineView) {
if (this.hover_glyph && inspected_subset_indices.length)
this.hover_glyph.render(ctx, this.model.view.convert_indices_from_subset(inspected_subset_indices), this.glyph)
else
glyph.render(ctx, this.all_indices, this.glyph)
} else {
glyph.render(ctx, indices, this.glyph)
if (this.hover_glyph && inspected_subset_indices.length)
//.........这里部分代码省略.........
示例8: initialize
initialize(): void {
super.initialize()
this._resolutions = range(this.min_zoom, this.max_zoom+1).map((z) => this.get_resolution(z))
}
示例9: indices_map_to_subset
indices_map_to_subset() {
this.indices_map = {}
return range(0, this.indices.length).map((i) =>
(this.indices_map[this.indices[i]] = i))
}