nodes: 0, module; 1, function_definition; 2, function_name:ToJSCode; 3, parameters; 4, block; 5, identifier:self; 6, identifier:name; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, expression_statement; 11, if_statement; 12, expression_statement; 13, comment:# We first create the table with the given name; 14, expression_statement; 15, if_statement; 16, comment:# We add the columns to the table; 17, for_statement; 18, expression_statement; 19, comment:# We now go over the data and add each row; 20, for_statement; 21, return_statement; 22, identifier:columns_order; 23, None; 24, identifier:order_by; 25, tuple; 26, comment:"""Writes the data table as a JS code string.
  
      This method writes a string of JS code that can be run to
      generate a DataTable with the specified data. Typically used for debugging
      only.
  
      Args:
        name: The name of the table. The name would be used as the DataTable's
              variable name in the created JS code.
        columns_order: Optional. Specifies the order of columns in the
                       output table. Specify a list of all column IDs in the order
                       in which you want the table created.
                       Note that you must list all column IDs in this parameter,
                       if you use it.
        order_by: Optional. Specifies the name of the column(s) to sort by.
                  Passed as is to _PreparedData.
  
      Returns:
        A string of JS code that, when run, generates a DataTable with the given
        name and the data stored in the DataTable object.
        Example result:
          "var tab1 = new google.visualization.DataTable();
           tab1.addColumn("string", "a", "a");
           tab1.addColumn("number", "b", "b");
           tab1.addColumn("boolean", "c", "c");
           tab1.addRows(10);
           tab1.setCell(0, 0, "a");
           tab1.setCell(0, 1, 1, null, {"foo": "bar"});
           tab1.setCell(0, 2, true);
           ...
           tab1.setCell(9, 0, "c");
           tab1.setCell(9, 1, 3, "3$");
           tab1.setCell(9, 2, false);"
  
      Raises:
        DataTableException: The data does not match the type.
      """; 27, assignment; 28, comparison_operator:columns_order is None; 29, block; 30, assignment; 31, assignment; 32, attribute; 33, block; 34, pattern_list; 35, call; 36, block; 37, augmented_assignment; 38, tuple_pattern; 39, call; 40, comment:# We add all the elements of this row by their order; 41, block; 42, identifier:jscode; 43, identifier:encoder; 44, call; 45, identifier:columns_order; 46, None; 47, expression_statement; 48, identifier:col_dict; 49, call; 50, identifier:jscode; 51, binary_operator:"var %s = new google.visualization.DataTable();\n" % name; 52, identifier:self; 53, identifier:custom_properties; 54, expression_statement; 55, identifier:i; 56, identifier:col; 57, identifier:enumerate; 58, argument_list; 59, expression_statement; 60, if_statement; 61, identifier:jscode; 62, binary_operator:"%s.addRows(%d);\n" % (name, len(self.__data)); 63, identifier:i; 64, tuple_pattern; 65, identifier:enumerate; 66, argument_list; 67, for_statement; 68, if_statement; 69, identifier:DataTableJSONEncoder; 70, argument_list; 71, assignment; 72, identifier:dict; 73, argument_list; 74, string:"var %s = new google.visualization.DataTable();\n"; 75, identifier:name; 76, augmented_assignment; 77, identifier:columns_order; 78, augmented_assignment; 79, subscript; 80, block; 81, string:"%s.addRows(%d);\n"; 82, tuple; 83, identifier:row; 84, identifier:cp; 85, call; 86, tuple_pattern; 87, call; 88, block; 89, identifier:cp; 90, block; 91, identifier:columns_order; 92, list_comprehension; 93, list_comprehension; 94, identifier:jscode; 95, binary_operator:"%s.setTableProperties(%s);\n" % (
            name, encoder.encode(self.custom_properties)); 96, identifier:jscode; 97, binary_operator:"%s.addColumn(%s, %s, %s);\n" % (
            name,
            encoder.encode(col_dict[col]["type"]),
            encoder.encode(col_dict[col]["label"]),
            encoder.encode(col_dict[col]["id"])); 98, subscript; 99, string:"custom_properties"; 100, expression_statement; 101, identifier:name; 102, call; 103, attribute; 104, argument_list; 105, identifier:j; 106, identifier:col; 107, identifier:enumerate; 108, argument_list; 109, if_statement; 110, expression_statement; 111, if_statement; 112, expression_statement; 113, subscript; 114, for_in_clause; 115, tuple; 116, for_in_clause; 117, string:"%s.setTableProperties(%s);\n"; 118, tuple; 119, string:"%s.addColumn(%s, %s, %s);\n"; 120, tuple; 121, identifier:col_dict; 122, identifier:col; 123, augmented_assignment; 124, identifier:len; 125, argument_list; 126, identifier:self; 127, identifier:_PreparedData; 128, identifier:order_by; 129, identifier:columns_order; 130, boolean_operator; 131, block; 132, assignment; 133, call; 134, block; 135, else_clause; 136, augmented_assignment; 137, identifier:col; 138, string:"id"; 139, identifier:col; 140, attribute; 141, subscript; 142, identifier:col; 143, identifier:col; 144, attribute; 145, identifier:name; 146, call; 147, identifier:name; 148, call; 149, call; 150, call; 151, identifier:jscode; 152, binary_operator:"%s.setColumnProperties(%d, %s);\n" % (
              name, i, encoder.encode(col_dict[col]["custom_properties"])); 153, attribute; 154, comparison_operator:col not in row; 155, comparison_operator:row[col] is None; 156, continue_statement; 157, identifier:value; 158, call; 159, identifier:isinstance; 160, argument_list; 161, expression_statement; 162, if_statement; 163, comment:# We have a formatted value or custom property as well; 164, expression_statement; 165, block; 166, identifier:jscode; 167, binary_operator:"%s.setRowProperties(%d, %s);\n" % (
              name, i, encoder.encode(cp)); 168, identifier:self; 169, identifier:__columns; 170, identifier:col; 171, string:"id"; 172, identifier:self; 173, identifier:__columns; 174, attribute; 175, argument_list; 176, attribute; 177, argument_list; 178, attribute; 179, argument_list; 180, attribute; 181, argument_list; 182, string:"%s.setColumnProperties(%d, %s);\n"; 183, tuple; 184, identifier:self; 185, identifier:__data; 186, identifier:col; 187, identifier:row; 188, subscript; 189, None; 190, attribute; 191, argument_list; 192, identifier:value; 193, identifier:tuple; 194, assignment; 195, comparison_operator:len(value) == 3; 196, block; 197, augmented_assignment; 198, expression_statement; 199, string:"%s.setRowProperties(%d, %s);\n"; 200, tuple; 201, identifier:encoder; 202, identifier:encode; 203, attribute; 204, identifier:encoder; 205, identifier:encode; 206, subscript; 207, identifier:encoder; 208, identifier:encode; 209, subscript; 210, identifier:encoder; 211, identifier:encode; 212, subscript; 213, identifier:name; 214, identifier:i; 215, call; 216, identifier:row; 217, identifier:col; 218, identifier:self; 219, identifier:CoerceValue; 220, subscript; 221, subscript; 222, identifier:cell_cp; 223, string:""; 224, call; 225, integer:3; 226, expression_statement; 227, identifier:jscode; 228, parenthesized_expression; 229, augmented_assignment; 230, identifier:name; 231, identifier:i; 232, call; 233, identifier:self; 234, identifier:custom_properties; 235, subscript; 236, string:"type"; 237, subscript; 238, string:"label"; 239, subscript; 240, string:"id"; 241, attribute; 242, argument_list; 243, identifier:row; 244, identifier:col; 245, subscript; 246, string:"type"; 247, identifier:len; 248, argument_list; 249, assignment; 250, binary_operator:"%s.setCell(%d, %d, %s, %s%s);\n" %
                       (name, i, j,
                        self.EscapeForJSCode(encoder, value[0]),
                        self.EscapeForJSCode(encoder, value[1]), cell_cp); 251, identifier:jscode; 252, binary_operator:"%s.setCell(%d, %d, %s);\n" % (
                name, i, j, self.EscapeForJSCode(encoder, value)); 253, attribute; 254, argument_list; 255, identifier:col_dict; 256, identifier:col; 257, identifier:col_dict; 258, identifier:col; 259, identifier:col_dict; 260, identifier:col; 261, identifier:encoder; 262, identifier:encode; 263, subscript; 264, identifier:col_dict; 265, identifier:col; 266, identifier:value; 267, identifier:cell_cp; 268, binary_operator:", %s" % encoder.encode(row[col][2]); 269, string:"%s.setCell(%d, %d, %s, %s%s);\n"; 270, tuple; 271, string:"%s.setCell(%d, %d, %s);\n"; 272, tuple; 273, identifier:encoder; 274, identifier:encode; 275, identifier:cp; 276, subscript; 277, string:"custom_properties"; 278, string:", %s"; 279, call; 280, identifier:name; 281, identifier:i; 282, identifier:j; 283, call; 284, call; 285, identifier:cell_cp; 286, identifier:name; 287, identifier:i; 288, identifier:j; 289, call; 290, identifier:col_dict; 291, identifier:col; 292, attribute; 293, argument_list; 294, attribute; 295, argument_list; 296, attribute; 297, argument_list; 298, attribute; 299, argument_list; 300, identifier:encoder; 301, identifier:encode; 302, subscript; 303, identifier:self; 304, identifier:EscapeForJSCode; 305, identifier:encoder; 306, subscript; 307, identifier:self; 308, identifier:EscapeForJSCode; 309, identifier:encoder; 310, subscript; 311, identifier:self; 312, identifier:EscapeForJSCode; 313, identifier:encoder; 314, identifier:value; 315, subscript; 316, integer:2; 317, identifier:value; 318, integer:0; 319, identifier:value; 320, integer:1; 321, identifier:row; 322, identifier:col
code: def ToJSCode(self, name, columns_order=None, order_by=()):
      """Writes the data table as a JS code string.
  
      This method writes a string of JS code that can be run to
      generate a DataTable with the specified data. Typically used for debugging
      only.
  
      Args:
        name: The name of the table. The name would be used as the DataTable's
              variable name in the created JS code.
        columns_order: Optional. Specifies the order of columns in the
                       output table. Specify a list of all column IDs in the order
                       in which you want the table created.
                       Note that you must list all column IDs in this parameter,
                       if you use it.
        order_by: Optional. Specifies the name of the column(s) to sort by.
                  Passed as is to _PreparedData.
  
      Returns:
        A string of JS code that, when run, generates a DataTable with the given
        name and the data stored in the DataTable object.
        Example result:
          "var tab1 = new google.visualization.DataTable();
           tab1.addColumn("string", "a", "a");
           tab1.addColumn("number", "b", "b");
           tab1.addColumn("boolean", "c", "c");
           tab1.addRows(10);
           tab1.setCell(0, 0, "a");
           tab1.setCell(0, 1, 1, null, {"foo": "bar"});
           tab1.setCell(0, 2, true);
           ...
           tab1.setCell(9, 0, "c");
           tab1.setCell(9, 1, 3, "3$");
           tab1.setCell(9, 2, false);"
  
      Raises:
        DataTableException: The data does not match the type.
      """
  
      encoder = DataTableJSONEncoder()
  
      if columns_order is None:
        columns_order = [col["id"] for col in self.__columns]
      col_dict = dict([(col["id"], col) for col in self.__columns])
  
      # We first create the table with the given name
      jscode = "var %s = new google.visualization.DataTable();\n" % name
      if self.custom_properties:
        jscode += "%s.setTableProperties(%s);\n" % (
            name, encoder.encode(self.custom_properties))
  
      # We add the columns to the table
      for i, col in enumerate(columns_order):
        jscode += "%s.addColumn(%s, %s, %s);\n" % (
            name,
            encoder.encode(col_dict[col]["type"]),
            encoder.encode(col_dict[col]["label"]),
            encoder.encode(col_dict[col]["id"]))
        if col_dict[col]["custom_properties"]:
          jscode += "%s.setColumnProperties(%d, %s);\n" % (
              name, i, encoder.encode(col_dict[col]["custom_properties"]))
      jscode += "%s.addRows(%d);\n" % (name, len(self.__data))
  
      # We now go over the data and add each row
      for (i, (row, cp)) in enumerate(self._PreparedData(order_by)):
        # We add all the elements of this row by their order
        for (j, col) in enumerate(columns_order):
          if col not in row or row[col] is None:
            continue
          value = self.CoerceValue(row[col], col_dict[col]["type"])
          if isinstance(value, tuple):
            cell_cp = ""
            if len(value) == 3:
              cell_cp = ", %s" % encoder.encode(row[col][2])
            # We have a formatted value or custom property as well
            jscode += ("%s.setCell(%d, %d, %s, %s%s);\n" %
                       (name, i, j,
                        self.EscapeForJSCode(encoder, value[0]),
                        self.EscapeForJSCode(encoder, value[1]), cell_cp))
          else:
            jscode += "%s.setCell(%d, %d, %s);\n" % (
                name, i, j, self.EscapeForJSCode(encoder, value))
        if cp:
          jscode += "%s.setRowProperties(%d, %s);\n" % (
              name, i, encoder.encode(cp))
      return jscode