+
+
+/* Create a gsl_histogram from a freq_tab */
+gsl_histogram *
+freq_tab_to_hist(const struct freq_tab *ft, const struct variable *var)
+{
+ int i;
+ double x_min = DBL_MAX;
+ double x_max = -DBL_MAX;
+
+ gsl_histogram *hist;
+ const double bins = 11;
+
+ struct hsh_iterator hi;
+ struct hsh_table *fh = ft->data;
+ struct freq *frq;
+
+ /* Find out the extremes of the x value */
+ for ( frq = hsh_first(fh, &hi); frq != 0; frq = hsh_next(fh, &hi) )
+ {
+ if ( is_missing(&frq->v, var))
+ continue;
+
+ if ( frq->v.f < x_min ) x_min = frq->v.f ;
+ if ( frq->v.f > x_max ) x_max = frq->v.f ;
+ }
+
+ hist = histogram_create(bins, x_min, x_max);
+
+ for( i = 0 ; i < ft->n_valid ; ++i )
+ {
+ frq = &ft->valid[i];
+ gsl_histogram_accumulate(hist, frq->v.f, frq->c);
+ }
+
+ return hist;
+}
+
+
+static struct slice *
+freq_tab_to_slice_array(const struct freq_tab *frq_tab,
+ const struct variable *var,
+ int *n_slices);
+
+
+/* Allocate an array of slices and fill them from the data in frq_tab
+ n_slices will contain the number of slices allocated.
+ The caller is responsible for freeing slices
+*/
+static struct slice *
+freq_tab_to_slice_array(const struct freq_tab *frq_tab,
+ const struct variable *var,
+ int *n_slices)
+{
+ int i;
+ struct slice *slices;
+
+ *n_slices = frq_tab->n_valid;
+
+ slices = xmalloc ( *n_slices * sizeof (struct slice ) );
+
+ for (i = 0 ; i < *n_slices ; ++i )
+ {
+ const struct freq *frq = &frq_tab->valid[i];
+
+ slices[i].label = value_to_string(&frq->v, var);
+
+ slices[i].magnetude = frq->c;
+ }
+
+ return slices;
+}
+
+
+
+
+static void
+do_piechart(const struct variable *var, const struct freq_tab *frq_tab)
+{
+ struct slice *slices;
+ int n_slices;
+
+ slices = freq_tab_to_slice_array(frq_tab, var, &n_slices);
+
+ piechart_plot(var_to_string(var), slices, n_slices);
+
+ free(slices);
+}
+
+