Commit e3ebd2ef authored by Paul Asmuth's avatar Paul Asmuth
Browse files

DRAW AXIS/CHART syntax

parent 3f69c2c7
Loading
Loading
Loading
Loading
+13 −20
Original line number Diff line number Diff line
@@ -53,25 +53,19 @@ point chart examples:
--- TimeDomain!
--- max interpolation gap -> draw as missing data

BEGIN BAR CHART WITH
DRAW BAR CHART
  [TITLE title]
  [SUBTITLE subtitle]
  [ORIENTATION {HORIZONTAL|VERTICAL}]
  [STACKED {TRUE|FALSE}]
  [LABELS {INSIDE|OUTSIDE|OFF}];

DRAW AXIS {TOP|RIGHT|BOTTOM|LEFT}
  [TITLE title]
  [DOMAIN min, max [LOGARITHMIC]];

SELECT
    axpr as title  expr
  subtitle = expr;
  [orientation = {HORIZONTAL|VERTICAL}]
  [stacked = [TRUE|FALSE]]
  [labels = [{INSIDE|OUTSIDE|OFF}]];
  [FROM select_statement];

CREATE AXIS
  position = {TOP|RIGHT|BOTTOM|BOTH|LEFT}
  title = expr
  min = expr
  max = expr
  logarithmic = expr
  [FROM select_statement];

CREATE SERIES
  name = expr
  series = expr
  x = expr
  y = expr
  z = expr
@@ -79,7 +73,6 @@ CREATE SERIES
  linestyle = expr
  pointstyle = expr
  color = expr
  [FROM select_statement];


SELECT
+2 −10
Original line number Diff line number Diff line
@@ -19,13 +19,7 @@ namespace query {
class AxisStatement : public Executable {
public:

  AxisStatement(
      std::vector<std::string>&& columns,
      Executable* child) :
      columns_(std::move(columns)),
      child_(child) {
    child->setTarget(this);
  }
  AxisStatement() {}

  void execute() override {}

@@ -34,7 +28,7 @@ public:
  }

  size_t getNumCols() const override {
    return columns_.size();
    return 0;
  }

  const std::vector<std::string>& getColumns() const override {
@@ -43,14 +37,12 @@ public:

  template <typename T>
  void executeDrawable(T* drawable) {
    child_->execute();
    drawable->addAxis(ui::AxisDefinition::LEFT); // FIPXAUL
    drawable->addAxis(ui::AxisDefinition::BOTTOM); // FIPXAUL
  }

protected:
  std::vector<std::string> columns_;
  Executable* child_;
};

}
+49 −33
Original line number Diff line number Diff line
@@ -196,15 +196,13 @@ ASTNode* Parser::statement() {
  switch (cur_token_->getType()) {
    case Token::T_SELECT:
      return selectStatement();
    case Token::T_CREATE:
      return createStatement();
    case Token::T_BEGIN:
      return beginStatement();
    case Token::T_DRAW:
      return drawStatement();
  }

  RAISE(
      ParseError,
      "unexpected token '%s', expected one of SELECT, CREATE or BEGIN",
      "unexpected token '%s', expected one of SELECT, DRAW or IMPORT",
      Token::getTypeName(cur_token_->getType()));

  return nullptr;
@@ -276,66 +274,84 @@ ASTNode* Parser::selectStatement() {
  return select;
}

ASTNode* Parser::createStatement() {
  consumeToken();

  switch (cur_token_->getType()) {
    case Token::T_SERIES:
      consumeToken();
      if (cur_token_->getType() == Token::T_WITH) {
        consumeToken();
        auto series = new ASTNode(ASTNode::T_SERIES);
        series->appendChild(selectStatement());
        return series;
ASTNode* Parser::drawStatement() {
  if (lookahead(2, Token::T_CHART)) {
    return chartStatement();
  }
    case Token::T_AXIS:
      consumeToken();
      if (cur_token_->getType() == Token::T_WITH) {
        consumeToken();
        auto series = new ASTNode(ASTNode::T_AXIS);
        series->appendChild(selectStatement());
        return series;

  if (lookahead(2, Token::T_AXIS)) {
    return axisStatement();
  }

  RAISE(
      ParseError,
      "invalid DRAW statement. syntax is DRAW <type> {AXIS|CHART}");
  return nullptr;
}

ASTNode* Parser::chartStatement() {
  auto chart = new ASTNode(ASTNode::T_DRAW);
  consumeToken();

  switch (cur_token_->getType()) {
    case Token::T_BAR:
      chart->setToken(consumeToken());
      break;

    default:
      RAISE(
          ParseError,
          "unexpected token '%s', expected one of SERIES or AXIS",
          "unexpected token '%s', expected one of BAR, LINE or AREA",
          Token::getTypeName(cur_token_->getType()));
      return nullptr;
  }

  if (!expectAndConsume(Token::T_CHART)) {
    return nullptr;
  }

/*
  if (consumeIf(Token::T_WITH)) {
    draw->appendChild(selectStatement());
  } else {
  }
*/

ASTNode* Parser::beginStatement() {
  auto draw = new ASTNode(ASTNode::T_DRAW);
  consumeIf(Token::T_SEMICOLON);
  return chart;
}

ASTNode* Parser::axisStatement() {
  auto axis = new ASTNode(ASTNode::T_AXIS);
  consumeToken();

  switch (cur_token_->getType()) {
    case Token::T_BAR:
      draw->setToken(consumeToken());
    case Token::T_LEFT:
      axis->setToken(consumeToken());
      break;

    default:
      RAISE(
          ParseError,
          "unexpected token '%s', expected one of BAR, LINE or AREA",
          "unexpected token '%s', expected one of TOP, RIGHT, BOTTOM, LEFT",
          Token::getTypeName(cur_token_->getType()));
      return nullptr;
  }

  if (!expectAndConsume(Token::T_CHART)) {
  if (!expectAndConsume(Token::T_AXIS)) {
    return nullptr;
  }

/*
  if (consumeIf(Token::T_WITH)) {
    draw->appendChild(selectStatement());
  } else {
    consumeIf(Token::T_SEMICOLON);
  }
*/

  return draw;
  consumeIf(Token::T_SEMICOLON);
  return axis;
}

ASTNode* Parser::selectSublist() {
+3 −2
Original line number Diff line number Diff line
@@ -83,8 +83,9 @@ protected:
  ASTNode* selectStatement();
  ASTNode* selectSublist();
  ASTNode* tableName();
  ASTNode* createStatement();
  ASTNode* beginStatement();
  ASTNode* drawStatement();
  ASTNode* chartStatement();
  ASTNode* axisStatement();

  ASTNode* fromClause();
  ASTNode* whereClause();
+18 −20
Original line number Diff line number Diff line
@@ -314,7 +314,7 @@ TEST_CASE(QueryTest, TestSelectDerivedColumnWithTableName, [] () {

TEST_CASE(QueryTest, TestSelectMustBeFirstAssert, [] () {
  const char* err_msg = "unexpected token 'T_GROUP', expected one of SELECT, "
      "CREATE or BEGIN";
      "DRAW or IMPORT";

  EXPECT_EXCEPTION(err_msg, [] () {
    auto parser = parseTestQuery("GROUP BY SELECT");
@@ -831,26 +831,22 @@ TEST_CASE(QueryTest, TestSimpleDrawQuery, [] () {


  auto query = Query(
      "  BEGIN BAR CHART;"
      ""
      "  CREATE AXIS WITH SELECT 'left' AS position;"
      "  DRAW BAR CHART;"
      "  DRAW LEFT AXIS;"
      ""
      "  CREATE SERIES WITH"
      "  SELECT"
      "      one AS x, two AS y"
      "    'series1' as series, one AS x, two AS y"
      "  FROM"
      "    testtable;"
      ""
      "  CREATE SERIES WITH"
      "  SELECT"
      "      one as x, two + 5 as y"
      "    'series2' as series, one as x, two + 5 as y"
      "  from"
      "    testtable;"
      ""
      "  CREATE SERIES WITH"
      "  SELECT"
      "      one as x, two / 2 + 4 as y"
      "    from"
      "    'series3' as series, one as x, two / 2 + 4 as y"
      "  FROM"
      "    testtable;"
      "",
      &repo);
@@ -860,6 +856,7 @@ TEST_CASE(QueryTest, TestSimpleDrawQuery, [] () {
  //chart->renderSVG();
});

/*
TEST_CASE(QueryTest, TestDerivedSeriesDrawQuery, [] () {
  TableRepository repo;
  repo.addTableRef("testtable",
@@ -881,4 +878,5 @@ TEST_CASE(QueryTest, TestDerivedSeriesDrawQuery, [] () {
  query.execute();
  auto chart = query.getChart(0);
  //chart->renderSVG();
});
});\
*/
Loading