Predicate

A predicate is used to define an inclusion or exclusion criterion. The find method in the Scene class, for example, takes an array of predicates as its parameter.

Predicates based on visual properties

A predicate based on a visual property is defined as:

  • {channel: channel, value: value} if the criterion demands an exact match, for example, the following code will return all the objects in the scene whose fill color is red:
    scene.find([{channel: "fillColor", value: "red"}])
  • {channel: channel, range: [low, high]} if the criterion demands the visual property is within the specified range, for example, the following code will return all the objects in the scene whose x position is between the range:
    scene.find([{channel: "x", range: [0, 200]}])
  • {channel: channel, values: [values]} if the criterion demands the visual property matches any value in the specified value array, for example, the following code will return all the objects in the scene whose type is either a rectangle or a circle:
    scene.find([{channel: "type", values: ["rectangle", "circle"]}])

Predicates based on data values

A predicate based on a data field is defined as:

  • {field: field, value: value} if the criterion demands an exact match, for example, the following code will return all the objects in the scene whose data scope has the value “male” for the field “gender”:
    scene.find([{field: "gender", value: "male"}])
  • {field: field, range: [low, high]} if the criterion demands the field value is within the specified range, for example, the following code will return all the objects in the scene whose data scope has a value between 20 and 50 for the field “age”:
    scene.find([{field: "age", range: [20, 50]}])
  • {field: field, values: [values]} if the criterion demands the field value matches any value in the specified array, for example, the following code will return all the objects in the scene whose whose data scope has a value related to education for the field “occupation”:
    scene.find([{field: "occupation", values: ["teacher", "professor", "lecturer"]}])
  • {fields: [field1, field2], operator: operator} if the criterion demands the values of the two specified fields satisfy the specified operator relation, for example, the following code will return all the objects in the scene whose whose data scope’s “income” value is greater than the “spending” value:
    scene.find([{fields: ["income", "spending"], operator: ">"}])