Skip to content

Commit

Permalink
Add axis types as chart operator flags
Browse files Browse the repository at this point in the history
  • Loading branch information
dit7ya committed Apr 25, 2024
1 parent 901c003 commit aa4fdb7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog/next/features/4147-chart-axis-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The chart operator now accepts the flags `--x-axis-type` and `--y-axis-type` for `bar`, `line`, and `area` charts, with the possible values being `log` and `linear`, with `linear` as the default value. Setting these flags defines the scale (logarithmic or linear) on the Tenzir App chart visualization.
12 changes: 12 additions & 0 deletions libtenzir/builtins/operators/chart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -724,10 +724,14 @@ chart_definition chart_definitions[] = {
{.attr = "x", .flag = "-x,--x-axis", .type = flag_type::field_name, .default_ = nth_field{0}, .allow_lists = false, .req = requirement::strictly_increasing,},
{.attr = "y", .flag = "-y,--y-axis", .type = flag_type::field_name, .default_ = nth_field{1, nth_field::all_the_rest}, .allow_lists = true,},
{.attr = "position", .flag = "--position", .type = flag_type::attribute_value, .default_ = attribute_value{"grouped"}, .allow_lists = false,},
{.attr = "xAxisType", .flag = "--x-axis-type", .type = flag_type::attribute_value, .default_ = attribute_value{"linear"}, .allow_lists = false,},
{.attr = "yAxisType", .flag = "--y-axis-type", .type = flag_type::attribute_value, .default_ = attribute_value{"linear"}, .allow_lists = false,},
},
.verifications = {
disallow_mixmatch_between_explicit_and_implicit_arguments({"x", "y"}),
require_attribute_value_one_of("position", {"grouped", "stacked"}),
require_attribute_value_one_of("xAxisType", {"log", "linear"}),
require_attribute_value_one_of("yAxisType", {"log", "linear"}),
},
},
// `area` is equivalent to `line`.
Expand All @@ -738,10 +742,14 @@ chart_definition chart_definitions[] = {
{.attr = "x", .flag = "-x,--x-axis", .type = flag_type::field_name, .default_ = nth_field{0}, .allow_lists = false, .req = requirement::strictly_increasing,},
{.attr = "y", .flag = "-y,--y-axis", .type = flag_type::field_name, .default_ = nth_field{1, nth_field::all_the_rest}, .allow_lists = true,},
{.attr = "position", .flag = "--position", .type = flag_type::attribute_value, .default_ = attribute_value{"grouped"}, .allow_lists = false,},
{.attr = "xAxisType", .flag = "--x-axis-type", .type = flag_type::attribute_value, .default_ = attribute_value{"linear"}, .allow_lists = false,},
{.attr = "yAxisType", .flag = "--y-axis-type", .type = flag_type::attribute_value, .default_ = attribute_value{"linear"}, .allow_lists = false,},
},
.verifications = {
disallow_mixmatch_between_explicit_and_implicit_arguments({"x", "y"}),
require_attribute_value_one_of("position", {"grouped", "stacked"}),
require_attribute_value_one_of("xAxisType", {"log", "linear"}),
require_attribute_value_one_of("yAxisType", {"log", "linear"}),
},
},
// `bar` is equivalent to `line`, except the requirement on `x` is for the values to be unique.
Expand All @@ -752,10 +760,14 @@ chart_definition chart_definitions[] = {
{.attr = "x", .flag = "-x,--x-axis", .type = flag_type::field_name, .default_ = nth_field{0}, .allow_lists = false, .req = requirement::unique,},
{.attr = "y", .flag = "-y,--y-axis", .type = flag_type::field_name, .default_ = nth_field{1, nth_field::all_the_rest}, .allow_lists = true,},
{.attr = "position", .flag = "--position", .type = flag_type::attribute_value, .default_ = attribute_value{"grouped"}, .allow_lists = false,},
{.attr = "xAxisType", .flag = "--x-axis-type", .type = flag_type::attribute_value, .default_ = attribute_value{"linear"}, .allow_lists = false,},
{.attr = "yAxisType", .flag = "--y-axis-type", .type = flag_type::attribute_value, .default_ = attribute_value{"linear"}, .allow_lists = false,},
},
.verifications = {
disallow_mixmatch_between_explicit_and_implicit_arguments({"x", "y"}),
require_attribute_value_one_of("position", {"grouped", "stacked"}),
require_attribute_value_one_of("xAxisType", {"log", "linear"}),
require_attribute_value_one_of("yAxisType", {"log", "linear"}),
},
},
// `pie` chart is equivalent to `line` and `bar`, except
Expand Down
12 changes: 12 additions & 0 deletions web/docs/operators/chart.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ Control how the values are grouped when rendered as a chart.
Possible values are `grouped` and `stacked`.
Defaults to `grouped`.

### `x-axis-type=<x-axis-type>` (`line`, `area`, and `bar` charts only)

Sets the x-axis scale type.
Possible values are `linear` and `log`.
Defaults to `linear`.

### `y-axis-type=<y-axis-type>` (`line`, `area`, and `bar` charts only)

Sets the y-axis scale type.
Possible values are `linear` and `log`.
Defaults to `linear`.

### `--name <field>` (`pie` chart only)

Set the field used for the names of the segments.
Expand Down

0 comments on commit aa4fdb7

Please sign in to comment.