static _value_to_json(key, value, optional_parent_object) {
   if (isObject(value) && (key === 'data')) {
     return serialization.encode_column_data(value, optional_parent_object._shapes)
   } else {
     return HasProps._value_to_json(key, value, optional_parent_object)
   }
 }
export const slice = function(ind, length) {
  let ref, start, step, stop
  if (isObject(ind)) {
    return [ind.start != null ? ind.start : 0, ind.stop != null ? ind.stop : length, ind.step != null ? ind.step : 1]
  }
  return [start, stop, step] = ref = [ind, ind+1, 1], ref
}
Ejemplo n.º 3
0
      it(`should roundtrip ${typ.name} arrays`, () => {
        const array = new typ([1, 2])
        const shape = [2]
        const e = ser.encode_base64(array, shape)
        expect(isObject(e)).to.be.true
        expect(Object.keys(e).length).to.be.equal(3)
        expect(e.dtype).to.equal(ser.DTYPES[typ.name as ser.ArrayName])
        expect(e.shape).to.be.deep.equal([2])

        const [d, s] = ser.decode_base64(e)
        expect(array).to.be.deep.equal(d)
        expect(shape).to.be.deep.equal(s)
      })
Ejemplo n.º 4
0
function strip_ids(value: any): void {
  if (isArray(value)) {
    for (const v of value) {
      strip_ids(v)
    }
  } else if (isObject(value)) {
    if ('id' in value) {
      delete value.id
    }
    for (const k in value) {
      strip_ids(value[k])
    }
  }
}
Ejemplo n.º 5
0
function deep_value_to_json(_key: string, value: any, _optional_parent_object: any): any {
  if (value instanceof HasProps) {
    return {type: value.type, attributes: value.attributes_as_json()}
  } else if (isArray(value)) {
    const ref_array: any[] = []
    for (let i = 0; i < value.length; i++) {
      ref_array.push(deep_value_to_json(i.toString(), value[i], value))
    }
    return ref_array
  } else if (isObject(value)) {
    const ref_obj: {[key: string]: any} = {}
    for (const subkey in value) {
      if (value.hasOwnProperty(subkey))
        ref_obj[subkey] = deep_value_to_json(subkey, value[subkey], value)
    }
    return ref_obj
  } else
    return value
}
Ejemplo n.º 6
0
function check_matching_defaults(name: string, python_defaults: {[key: string]: any}, bokehjs_defaults: {[key: string]: any}): boolean {
  const different: string[] = []
  const python_missing: string[] = []
  const bokehjs_missing: string[] = []
  for (const k in bokehjs_defaults) {
    const js_v = bokehjs_defaults[k]

    // special case for graph renderer node_renderer
    if (name === "GraphRenderer" && k === "node_renderer")
      continue

    // special case for graph renderer node_renderer
    if (name === "GraphRenderer" && k === "edge_renderer")
      continue

    // special case for date picker, default is "now"
    if (name === 'DatePicker' && k === 'value')
      continue

    // special case for date time tickers, class hierarchy and attributes are handled differently
    if (name === "DatetimeTicker" && k === "tickers")
      continue

    // special case for Title derived text properties
    if (name === "Title" && (k === "text_align" || k === "text_baseline"))
      continue

    // special case for selections that have a method added to them
    if (k === 'selected')
      delete js_v['0d'].get_view

    if (k === 'id')
      continue

    if (k in python_defaults) {
      let py_v = python_defaults[k]
      strip_ids(py_v)

      if (!isEqual(py_v, js_v)) {

        // these two conditionals compare 'foo' and {value: 'foo'}
        if (isObject(js_v) && 'value' in js_v && isEqual(py_v, js_v['value']))
          continue
        if (isObject(py_v) && 'value' in py_v && isEqual(py_v['value'], js_v))
          continue

        if (isObject(js_v) && 'attributes' in js_v && isObject(py_v) && 'attributes' in py_v) {
          if (js_v['type'] === py_v['type']) {
            check_matching_defaults(`${name}.${k}`, py_v['attributes'], js_v['attributes'])
            continue
          }
        }

        // compare arrays of objects
        if (isArray(js_v) && isArray(py_v)) {
          let equal = true

          // palettes in JS are stored as int color values
          if (k === 'palette')
            py_v = py_v.map((x: string) => parseInt(x.slice(1), 16))

          if (js_v.length !== py_v.length)
            equal = false
          else {
            for (let i = 0; i < js_v.length; i++) {
              delete (js_v[i] as any).id
              delete (py_v[i] as any).id
              if (!isEqual(js_v[i], py_v[i])) {
                equal = false
                break
              }
            }
          }

          if (equal)
            continue
        }

        different.push(`${name}.${k}: bokehjs defaults to ${safe_stringify(js_v)} but python defaults to ${safe_stringify(py_v)}`)
      }
    } else {
      python_missing.push(`${name}.${k}: bokehjs defaults to ${safe_stringify(js_v)} but python has no such property`)
    }
  }

  for (const k in python_defaults) {
    if (!(k in bokehjs_defaults)) {
      const v = python_defaults[k]
      bokehjs_missing.push(`${name}.${k}: python defaults to ${safe_stringify(v)} but bokehjs has no such property`)
    }
  }

  function complain(failures: string[], message: string): void {
    if (failures.length > 0) {
      console.error(message)
      for (const f of failures)
        console.error(`    ${f}`)
    }
  }

  complain(different, `${name}: defaults are out of sync between Python and bokehjs`)
  complain(python_missing, `${name}: python is missing some properties found in bokehjs`)
  complain(bokehjs_missing, `${name}: bokehjs is missing some properties found in Python`)

  return different.length === 0 && python_missing.length === 0 && bokehjs_missing.length === 0
}
Ejemplo n.º 7
0
export function isField<T>(obj: Vectorized<T>): obj is Field {
  return isObject(obj) && "field" in (obj as any)
}
Ejemplo n.º 8
0
export function isValue<T>(obj: Scalar<T> | Vectorized<T>): obj is Value<T> {
  return isObject(obj) && "value" in (obj as any)
}
Ejemplo n.º 9
0
 static _value_to_json(key: string, value: any, optional_parent_object: any): any {
   if (isObject(value) && key === 'data')
     return encode_column_data(value, optional_parent_object._shapes)
   else
     return HasProps._value_to_json(key, value, optional_parent_object)
 }