Class Predicate

java.lang.Object
smile.plot.vega.Predicate

public class Predicate extends Object
To test a data point in a filter transform or a test property in conditional encoding, a predicate definition of the following forms must be specified: - a Vega expression string, where datum can be used to refer to the current data object. For example, datum.b2 > 60 would test if the value in the field b2 for each data point is over 60. - one of the field predicates: equal, lt, lte, gt, gte, range, oneOf, or valid. - a parameter predicate, which defines the names of a selection that the data point should belong to (or a logical composition of selections). - a logical composition of (1), (2), or (3).
  • Constructor Details

    • Predicate

      public Predicate(String expr)
      Constructor.
      Parameters:
      expr - a Vega expression string.
    • Predicate

      public Predicate(String param, boolean empty)
      Constructor of parameter predicate. For example, with {"param": "brush"}, only data values that fall within the selection named brush will remain in the dataset. Notice, by default, empty selections are considered to contain all data values. We can toggle this behavior by setting the optional empty property true on the predicate.
      Parameters:
      param - Filter using a parameter name.
      empty - For selection parameters, the predicate of empty selections returns true by default. Override this behavior, by setting this property false.
  • Method Details

    • timeUnit

      public Predicate timeUnit(String timeUnit)
      Sets the time unit for a temporal field. Vega-Lite supports the following time units: "year" - Gregorian calendar years. "quarter" - Three-month intervals, starting in one of January, April, July, and October. "month" - Calendar months (January, February, etc.). "date" - Calendar day of the month (January 1, January 2, etc.). "week" - Sunday-based weeks. Days before the first Sunday of the year are considered to be in week 0, the first Sunday of the year is the start of week 1, the second Sunday week 2, etc. "day" - Day of the week (Sunday, Monday, etc.). "dayofyear" - Day of the year (1, 2, …, 365, etc.). "hours" - Hours of the day (12:00am, 1:00am, etc.). "minutes" - Minutes in an hour (12:00, 12:01, etc.). "seconds" - Seconds in a minute (12:00:00, 12:00:01, etc.). "milliseconds" - Milliseconds in a second.
      Parameters:
      timeUnit - Time unit.
      Returns:
      this object.
    • of

      public static Predicate of(String field, String op, boolean value)
      Test if a field in the data point satisfies certain conditions.
      Parameters:
      field - the field to be tested.
      op - equal, lt (less than), lte (less than or equal), gt (greater than), or gte(greater than or equal).
      value - the value to compare.
      Returns:
      a field predicate.
    • of

      public static Predicate of(String field, String op, double value)
      Test if a field in the data point satisfies certain conditions.
      Parameters:
      field - the field to be tested.
      op - equal, lt (less than), lte (less than or equal), gt (greater than), or gte(greater than or equal).
      value - the value to compare.
      Returns:
      a field predicate.
    • of

      public static Predicate of(String field, String op, String value)
      Test if a field in the data point satisfies certain conditions.
      Parameters:
      field - the field to be tested.
      op - equal, lt (less than), lte (less than or equal), gt (greater than), or gte(greater than or equal).
      value - the value to compare.
      Returns:
      a field predicate.
    • range

      public static Predicate range(String field, double min, double max)
      Test if a field in the data point satisfies certain conditions.
      Parameters:
      field - the field to be tested.
      min - inclusive minimum values for a field value of a data item to be included in the filtered data.
      max - inclusive maximum values for a field value of a data item to be included in the filtered data.
      Returns:
      a field predicate.
    • oneOf

      public static Predicate oneOf(String field, double... values)
      Test if a field in the data point satisfies certain conditions.
      Parameters:
      field - the field to be tested.
      values - a set of values that the field's value should be a member of, for a data item included in the filtered data.
      Returns:
      a field predicate.
    • oneOf

      public static Predicate oneOf(String field, String... values)
      Test if a field in the data point satisfies certain conditions.
      Parameters:
      field - the field to be tested.
      values - a set of values that the field's value should be a member of, for a data item included in the filtered data.
      Returns:
      a field predicate.
    • valid

      public static Predicate valid(String field)
      Test if a field is valid, meaning it is neither null nor NaN.
      Parameters:
      field - the field to be tested.
      Returns:
      a field predicate.
    • and

      public static Predicate and(Predicate... predicates)
      Logical AND composition to combine predicates.
      Parameters:
      predicates - the predicates.
      Returns:
      AND predicate.
    • or

      public static Predicate or(Predicate... predicates)
      Logical OR composition to combine predicates.
      Parameters:
      predicates - the predicates.
      Returns:
      OR predicate.
    • not

      public static Predicate not(Predicate predicate)
      Logical NOT operation.
      Parameters:
      predicate - the predicate.
      Returns:
      NOT predicate.