Turi Create  4.0
plot.hpp
1 #ifndef __TC_PLOT_HPP_
2 #define __TC_PLOT_HPP_
3 
4 #include <model_server/lib/toolkit_class_macros.hpp>
5 #include <model_server/lib/toolkit_function_macros.hpp>
6 #include <visualization/server/transformation.hpp>
7 #include <model_server/lib/extensions/model_base.hpp>
8 #include <string>
9 #include <capi/TuriCreate.h>
10 
11 #ifdef __APPLE__
12 #ifndef TC_BUILD_IOS
13 extern "C" {
14 #include <CoreGraphics/CoreGraphics.h>
15 }
16 #endif // TC_BUILD_IOS
17 #endif // __APPLE__
18 
19 namespace turi {
20  namespace visualization {
21 
22  class Plot: public model_base {
23  private:
24  mutable std::string m_id;
25  std::string m_vega_spec;
26  double m_size_array;
27  std::shared_ptr<transformation_base> m_transformer;
28 
29  public:
30  Plot();
31  explicit Plot(const std::string& vega_spec);
32  Plot(const std::string& vega_spec, std::shared_ptr<transformation_base> transformer, double size_array);
33  void show(const std::string& path_to_client, tc_plot_variation variation = tc_plot_variation_default);
34  void materialize() const;
35  std::string get_url() const;
36  const std::string& get_id() const;
37 
38  // vega specification
39  std::string get_spec(tc_plot_variation variation=tc_plot_variation_default,
40  bool include_data=false) const;
41 
42  // streaming data aggregation
43  double get_percent_complete() const; // out of 1.0
44  bool finished_streaming() const;
45  std::string get_next_data() const;
46 
47  // non-streaming data aggregation: causes full materialization
48  std::string get_data() const;
49 
50 #ifdef __APPLE__
51 #ifndef TC_BUILD_IOS
52  // Streaming render (based on current computation -
53  // call materialize first to get a final rendering up front).
54  // Returns true if streaming finished, false otherwise.
55  bool render(CGContextRef context, tc_plot_variation variation=tc_plot_variation_default);
56 
57  // Low-level rendering path - takes a Vega spec as input.
58  static void render(const std::string& vega_spec, CGContextRef context);
59 #endif // TC_BUILD_IOS
60 #endif // __APPLE__
61 
63  REGISTER_CLASS_MEMBER_FUNCTION(Plot::show, "path_to_client", "variation")
64  REGISTER_CLASS_MEMBER_FUNCTION(Plot::materialize)
65  REGISTER_CLASS_MEMBER_FUNCTION(Plot::get_spec, "variation", "include_data")
66  REGISTER_CLASS_MEMBER_FUNCTION(Plot::get_data)
67  REGISTER_CLASS_MEMBER_FUNCTION(Plot::get_url)
69  };
70 
71  std::shared_ptr<Plot> plot_from_vega_spec(const std::string& vega_spec);
72  }
73 }
74 
75 #endif
#define BEGIN_CLASS_MEMBER_REGISTRATION(python_facing_classname)
#define REGISTER_CLASS_MEMBER_FUNCTION(function,...)
STL namespace.
#define END_CLASS_MEMBER_REGISTRATION