Skip to content

Commit

Permalink
Fix bar chart rendering bug #1561
Browse files Browse the repository at this point in the history
  • Loading branch information
mattcolozzo authored and texodus committed Oct 6, 2021
1 parent ebced4c commit bd7b126
Show file tree
Hide file tree
Showing 12 changed files with 590 additions and 192 deletions.
37 changes: 17 additions & 20 deletions cpp/perspective/src/cpp/computed_expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,17 @@ namespace perspective {
// of brackets and sequences. ExprTk defaults will replace "true" and "false"
// with 1 and 0, which we don't want. Using the tokens "true" and "false"
// will raise a syntax error, which is the correct behavior.
std::size_t
t_computed_expression_parser::PARSER_COMPILE_OPTIONS =
exprtk::parser<t_tscalar>::settings_t::e_joiner +
exprtk::parser<t_tscalar>::settings_t::e_numeric_check +
exprtk::parser<t_tscalar>::settings_t::e_bracket_check +
exprtk::parser<t_tscalar>::settings_t::e_sequence_check;
// exprtk::parser<t_tscalar>::settings_t::e_commutative_check;
// exprtk::parser<t_tscalar>::settings_t::e_strength_reduction;

std::shared_ptr<exprtk::parser<t_tscalar>>
t_computed_expression_parser::PARSER =
std::make_shared<exprtk::parser<t_tscalar>>(t_computed_expression_parser::PARSER_COMPILE_OPTIONS);
std::size_t t_computed_expression_parser::PARSER_COMPILE_OPTIONS
= exprtk::parser<t_tscalar>::settings_t::e_joiner
+ exprtk::parser<t_tscalar>::settings_t::e_numeric_check
+ exprtk::parser<t_tscalar>::settings_t::e_bracket_check
+ exprtk::parser<t_tscalar>::settings_t::e_sequence_check;
// exprtk::parser<t_tscalar>::settings_t::e_commutative_check;
// exprtk::parser<t_tscalar>::settings_t::e_strength_reduction;

std::shared_ptr<exprtk::parser<t_tscalar>> t_computed_expression_parser::PARSER
= std::make_shared<exprtk::parser<t_tscalar>>(
t_computed_expression_parser::PARSER_COMPILE_OPTIONS);

// Exprtk functions without any state can be initialized statically
computed_function::bucket t_computed_expression_parser::BUCKET_FN
Expand Down Expand Up @@ -100,11 +99,9 @@ computed_function::to_string
t_computed_expression_parser::TO_STRING_VALIDATOR_FN
= computed_function::to_string(nullptr);

t_tscalar
t_computed_expression_parser::TRUE_SCALAR = mktscalar(true);
t_tscalar t_computed_expression_parser::TRUE_SCALAR = mktscalar(true);

t_tscalar
t_computed_expression_parser::FALSE_SCALAR = mktscalar(false);
t_tscalar t_computed_expression_parser::FALSE_SCALAR = mktscalar(false);

#define REGISTER_COMPUTE_FUNCTIONS(vocab) \
computed_function::day_of_week day_of_week_fn \
Expand Down Expand Up @@ -203,9 +200,9 @@ t_computed_expression_parser::FALSE_SCALAR = mktscalar(false);
sym_table.add_function( \
"datetime", t_computed_expression_parser::MAKE_DATETIME_FN);

#define REGISTER_SCALAR_CONSTANTS() \
sym_table.add_constant("True", t_computed_expression_parser::TRUE_SCALAR); \
sym_table.add_constant("False", t_computed_expression_parser::FALSE_SCALAR); \
#define REGISTER_SCALAR_CONSTANTS() \
sym_table.add_constant("True", t_computed_expression_parser::TRUE_SCALAR); \
sym_table.add_constant("False", t_computed_expression_parser::FALSE_SCALAR);

/******************************************************************************
*
Expand Down Expand Up @@ -239,7 +236,7 @@ t_computed_expression::compute(std::shared_ptr<t_data_table> source_table,

// Custom functions from computed_functions.cpp
REGISTER_COMPUTE_FUNCTIONS(vocab)

exprtk::expression<t_tscalar> expr_definition;
std::vector<std::pair<std::string, t_tscalar>> values;
tsl::hopscotch_map<std::string, std::shared_ptr<t_column>> columns;
Expand Down
9 changes: 5 additions & 4 deletions cpp/perspective/src/cpp/computed_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ namespace computed_function {
t_tscalar rval;
rval.clear();
rval.m_type = DTYPE_BOOL;

t_scalar_view _low(parameters[0]);
t_scalar_view _val(parameters[1]);
t_scalar_view _high(parameters[2]);
Expand All @@ -1073,7 +1073,7 @@ namespace computed_function {
if (!low.is_valid() || !val.is_valid() || !high.is_valid()) {
return rval;
}

rval.set((low <= val) && (val <= high));
return rval;
}
Expand Down Expand Up @@ -1406,11 +1406,12 @@ namespace computed_function {
}

to_boolean::to_boolean()
: exprtk::igeneric_function<t_tscalar>("T") {}
: exprtk::igeneric_function<t_tscalar>("T") {}

to_boolean::~to_boolean() {}

t_tscalar to_boolean::operator()(t_parameter_list parameters) {
t_tscalar
to_boolean::operator()(t_parameter_list parameters) {
t_tscalar val;
t_tscalar rval;
rval.clear();
Expand Down
3 changes: 2 additions & 1 deletion cpp/perspective/src/cpp/expression_tables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ t_expression_tables::calculate_transitions(

bool prev_valid = prev_column.is_valid(ridx);
bool curr_valid = current_column.is_valid(ridx);
bool prev_curr_eq = prev_valid && curr_valid && (prev_value == curr_value);
bool prev_curr_eq
= prev_valid && curr_valid && (prev_value == curr_value);

t_value_transition transition;

Expand Down
17 changes: 8 additions & 9 deletions cpp/perspective/src/cpp/scalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ SUPPRESS_WARNINGS_VC(4800)

namespace perspective {

bool operator>(const std::size_t& lhs, const t_tscalar& rhs) {
return rhs.operator<(lhs);
bool
operator>(const std::size_t& lhs, const t_tscalar& rhs) {
return rhs.operator<(lhs);
}

#define BINARY_OPERATOR_BODY(OP) \
Expand All @@ -49,18 +50,16 @@ bool operator>(const std::size_t& lhs, const t_tscalar& rhs) {
* function-style cast through `T(0)`, `T(1)` etc. Because we can't guarantee
* what int this function is called with, we treat it as a double to
* prevent overflow.
*
*
* DO NOT USE THIS CONSTRUCTOR IN PERSPECTIVE - all `t_tscalar` objects
* should be constructed without initializer and then `set` should be called:
*
*
* t_tscalar x;
* x.set(1.2345);
*
* @param v
*
* @param v
*/
t_tscalar::t_tscalar(int v) {
this->set(static_cast<double>(v));
}
t_tscalar::t_tscalar(int v) { this->set(static_cast<double>(v)); }

bool
t_tscalar::is_none() const {
Expand Down
3 changes: 2 additions & 1 deletion cpp/perspective/src/cpp/view_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ t_view_config::fill_aggspecs(std::shared_ptr<t_schema> schema) {
if (is_column_only) {
// Always sort by `ANY` in column only views
agg_type = t_aggtype::AGGTYPE_ANY;
} else if ((is_row_pivot && is_row_sort) || (is_column_pivot && !is_row_sort)) {
} else if ((is_row_pivot && is_row_sort)
|| (is_column_pivot && !is_row_sort)) {
// Otherwise if the hidden column is in pivot on the same axis,
// use `UNIQUE`
agg_type = t_aggtype::AGGTYPE_UNIQUE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ namespace computed_function {
/**
* @brief Convert a column or scalar to a boolean, which returns True if the
* value is truthy or False otherwise.
*
*
* boolean(1)
* boolean(null)
*/
Expand Down
Loading

0 comments on commit bd7b126

Please sign in to comment.