예제 #1
0
func paramToInt(value *js.Object) int32 {
	result := int32(value.Int())

	if value.String() == "true" {
		result = 1
	}

	return result
}
예제 #2
0
func isEmpty(v, t *js.Object) bool {
	switch t.Get("kind").Int() {
	case boolKind:
		return !v.Bool()
	case int8Kind, int16Kind, int32Kind, intKind, uint8Kind, uint16Kind, uint32Kind, uintKind:
		return v.Int() == 0
	case int64Kind, uint64Kind:
		return v.Int64() == 0
	case float32Kind, float64Kind:
		return v.Float() == 0
	case arrayKind, sliceKind, stringKind:
		return v.Length() == 0
	case ptrKind:
		return v == t.Get("nil")
	case interfaceKind:
		if v.Get("$val") == js.Undefined {
			return true
		}
		return isEmpty(v.Get("$val"), v.Get("constructor"))
	case mapKind:
		return js.Global.Get("Object").Call("keys", v).Length() == 0
	}
	return false
}
예제 #3
0
파일: d3.go 프로젝트: nplanel/d3
//Invert calls the scale to interpolate a range value into its domain.
func (self *linearScaleImpl) Invert(obj js.Object, fn ExtractorFunc) int64 {
	if fn != nil {
		return int64(self.obj.Call("invert", fn(obj)).Int())
	}
	return int64(self.obj.Call("invert", obj.Int()).Int())
}
예제 #4
0
파일: d3.go 프로젝트: nplanel/d3
//Linear calls the scale to interpolate a value into its range.
func (self *linearScaleImpl) Linear(obj js.Object, fn ExtractorFunc) int64 {
	if fn != nil {
		return int64(self.obj.Invoke(fn(obj)).Int())
	}
	return int64(self.obj.Invoke(obj.Int()).Int())
}