Use dedicated version api of libvala internally as well
[vala-gnome.git] / libvaladoc / charts / chart.vala
blob4e642d1ce96e30da3b491feb54ae1349eb0b7174
1 /* chart.vala
3 * Copyright (C) 2008 Florian Brosch
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 * Author:
20 * Florian Brosch <flo.brosch@gmail.com>
23 [CCode (cname = "valadoc_compat_gvc_init")]
24 extern void valadoc_gvc_init ();
26 public class Valadoc.Charts.Chart : Api.Visitor {
27 protected Gvc.Context context;
28 protected Gvc.Graph graph;
29 protected Factory factory;
31 static construct {
32 valadoc_gvc_init ();
35 public Chart (Factory factory, Api.Node node) {
36 graph = factory.create_graph (node);
37 this.factory = factory;
38 node.accept (this);
41 public void save (string file_name, string file_type = "png") {
42 if (context == null) {
43 context = factory.create_context (graph);
45 context.render_filename (graph, file_type, file_name);
48 public void write (GLib.FileStream file, string file_type) {
49 if (context == null) {
50 context = factory.create_context (graph);
52 context.render (graph, file_type, file);
55 public uint8[]? write_buffer (string file_type) {
56 if (context == null) {
57 context = factory.create_context (graph);
60 uint8[]? data;
62 /* This will return null in data if it fails. */
63 context.render_data (graph, file_type, out data);
64 return data;
67 ~Chart () {
68 if (context != null) {
69 context.free_layout (graph);