@quartic/bokehjs
Version:
Interactive, novel data visualization
63 lines (45 loc) • 1.78 kB
text/coffeescript
import {Variable, Expression, Constraint, Operator, Strength, Solver as ConstraintSolver} from "kiwi"
import {Events} from "../events"
_constrainer = (op) ->
() =>
expr = Object.create(Expression.prototype)
Expression.apply(expr, arguments)
return new Constraint(expr, op)
_weak_constrainer = (op) ->
() ->
args = [null]
for arg in arguments
args.push(arg)
new Constraint( new (Function.prototype.bind.apply(Expression, args)), op, Strength.weak )
export {Variable, Expression, Constraint, Operator, Strength}
export EQ = _constrainer(Operator.Eq)
export LE = _constrainer(Operator.Le)
export GE = _constrainer(Operator.Ge)
export WEAK_EQ = _weak_constrainer(Operator.Eq)
export WEAK_LE = _weak_constrainer(Operator.Le)
export WEAK_GE = _weak_constrainer(Operator.Ge)
export class Solver
extends Events
constructor: () ->
= new ConstraintSolver()
clear: () ->
= new ConstraintSolver()
toString: () -> "Solver[num_constraints=#{@num_constraints()}, num_edit_variables=#{@num_edit_variables()}]"
num_constraints: () ->
._cnMap._array.length
num_edit_variables: () ->
._editMap._array.length
update_variables: (trigger=true) ->
.updateVariables()
if trigger
('layout_update')
add_constraint: (constraint) ->
.addConstraint(constraint)
remove_constraint: (constraint, silent=false) ->
.removeConstraint(constraint, silent)
add_edit_variable: (variable, strength) ->
.addEditVariable(variable, strength)
remove_edit_variable: (variable, silent=false) ->
.removeEditVariable(variable, strength, silent)
suggest_value: (variable, value) ->
.suggestValue(variable, value)