From 0b65108b8d8813e0ca26fbe4166fc1edde0edff4 Mon Sep 17 00:00:00 2001 From: Anthony Pessy Date: Tue, 20 Aug 2019 15:29:39 +0200 Subject: [PATCH] pass ratio to the data_labels_format callback when appropriate --- docs/reference.html.haml | 7 ++-- htdocs/samples/data_label.html | 51 +++++---------------------- htdocs/samples/data_label_format.html | 6 ++-- spec/data-spec.js | 50 ++++++++++++++++++++++++++ src/text.js | 5 ++- 5 files changed, 70 insertions(+), 49 deletions(-) diff --git a/docs/reference.html.haml b/docs/reference.html.haml index 56480db53..e9579f114 100644 --- a/docs/reference.html.haml +++ b/docs/reference.html.haml @@ -1012,10 +1012,11 @@ = partial :reference_item_link, locals: { id: 'data.labels.format' } %p Set formatter function for data labels. %br - %p The formatter function receives 4 arguments such as v, id, i, j and it must return a string that will be shown as the label. The arguments are: + %p The formatter function receives 5 arguments such as v, ratio, id, i, j and it must return a string that will be shown as the label. The arguments are: %br %ul %li v is the value of the data point where the label is shown. + %li ratio is the ratio of the data point where the label is shown, will be undefined if the data point is not normalized. %li id is the id of the data where the label is shown. %li i is the index of the data point where the label is shown. %li j is the sub index of the data point where the label is shown. @@ -1028,10 +1029,10 @@ %code.html.javascript data: {   labels: { -     format: function (v, id, i, j) { ... } +     format: function (v, ratio, id, i, j) { ... }     // it's possible to set for each data     //format: { -     //    data1: function (v, id, i, j) { ... }, +     //    data1: function (v, ratio, id, i, j) { ... },     //    ...     //}   } diff --git a/htdocs/samples/data_label.html b/htdocs/samples/data_label.html index 1137a8af7..b10574cac 100644 --- a/htdocs/samples/data_label.html +++ b/htdocs/samples/data_label.html @@ -18,6 +18,8 @@