Validations

SomeGraphs.Validations Module

Validate graph data.

Rendering graphs requires two objects: data and configuration. Both objects need to be internally consistent, as does their combination. This is especially relevant for the graph configuration. When creating UI for filling in these objects, we can do limited validation of each field on its own based on its type (e.g. (e.g., ensure that a "color" field contains a valid color name). Some restrictions, however, are not easily deduced from the field type, or relate different fields to each other. Replicating all the restrictions in the UI is tedious and error prone.

We therefore provide a framework here for validating the objects and generate a hopefully informative error message if anything is wrong. This can be used by the UI to validate the data without worrying about the details.

SomeGraphs.Validations.ValidationContext Type

A context (path of field names and/or indices) leading to a validated value. A string indicates access of a data member, an integer indicates accessing a vector or matrix element.

SomeGraphs.Validations.validate Function
validate(context::ValidationContext, value::Validated)::Nothing end
validate(context::ValidationContext, value::Validated, extra::Any)::Nothing end
validate(context::ValidationContext, value::Validated, extra::Any, another::Any)::Nothing end

Validate the value which was accessed via the context , possibly using some extra informative. Will throw ArgumentError if the value isn't valid.

SomeGraphs.Validations.validate_in Function
validate_in(validation::Function, context::ValidationContext, where::Union{AbstractString, Integer})::Nothing

Invoke the validation function with the context updated to include some where .

SomeGraphs.Validations.validate_field Function
validate_field(context::ValidationContext, field::AbstractString, value::Validated)::Nothing
validate_field(context::ValidationContext, field::AbstractString, value::Validated, extra::Any)::Nothing
validate_field(context::ValidationContext, field::AbstractString, value::Validated, extra::Any, another::Any)::Nothing

Validate the value of a field .

SomeGraphs.Validations.validate_is_range Function
validate_is_range(
    context::ValidationContext,
    low_where::AbstractString,
    low_value::Maybe{Real},
    high_where::AbstractString,
    high_value::Maybe{Real},
)::Nothing

Validate that if both low_value and high_value are specified, they define a non-empty range.

SomeGraphs.Validations.validate_vector_length Function
validate_vector_length(
    context::ValidationContext,
    field::AbstractString,
    vector::Maybe{AbstractVector},
    expected_base::AbstractString,
    expected_length::Integer
)::Nothing

Validate that a field containing a vector has (if it is specified) the expected_length of an expected_base field.

SomeGraphs.Validations.validate_vector_entries Function
validate_vector_entries(
    validation::Function,
    context::ValidationContext,
    [field::AbstractString,]
    vector::Maybe{AbstractVector},
    [mask::Maybe{Union{AbstractVector{Bool},BitVector}} = nothing]
)::Nothing

Validate all the entries of a field containing a vector using the validation function. It is given the entry's index, and its value. The context is updated to include the index for the duration of the function.

If a mask is specified, entries with a false value in the mask will not be validated.

SomeGraphs.Validations.validate_matrix_size Function
validate_matrix_size(
    context::ValidationContext,
    matrix::Maybe{AbstractMatrix},
    field::AbstractString,
    expected_size::Tuple{Integer, Integer}
)::Nothing

Validate that a field containing matrix has (if it is specified) the expected_size of a base_field .

SomeGraphs.Validations.validate_matrix_entries Function
validate_matrix_entries(
    validation::Function,
    context::ValidationContext,
    field::AbstractString,
    matrix::Maybe{AbstractMatrix}
)::Nothing

Validate all the entries of a field containing a matrix using the validation function. It is given the entry's row and column indices, and its value. The context is updated to include the indices for the duration of the function.

SomeGraphs.Validations.validate_dict_entries Function
validate_dict_entries(
    validation::Function,
    context::ValidationContext,
    [field::AbstractString,]
    dict::Maybe{AbstractDict}
)::Nothing

Validate all the entries of a field containing a dict using the validation function. It is given the entry's key and value. The context is updated to include the key for the duration of the function.

Index