Skip to content

Commit c73db8b

Browse files
ealves-ptmarkusdap
authored andcommitted
feat: add option to transform tooltip text
1 parent be609ef commit c73db8b

File tree

5 files changed

+16
-22
lines changed

5 files changed

+16
-22
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ var defaultOptions = {
1212
//e.g. 4000 => €4,000
1313
tooltipFnc: undefined, //accepts function
1414
//build custom tooltip
15+
transformTooltipTextFnc: undefined, // accepts function
16+
// transform tooltip text
1517
class: undefined, // accecpts 'class1', 'class1 class2', etc.
1618
//adds class(es) to tooltip wrapper
1719
appendToBody: false //accepts true or false

dist/chartist-plugin-tooltip.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,6 @@
3131
appendToBody: false,
3232
class: undefined,
3333
pointClass: 'ct-point'
34-
// showTooltips: true,
35-
// tooltipEvents: ['mousemove', 'touchstart', 'touchmove'],
36-
// labelClass: 'ct-label',
37-
// labelOffset: {
38-
// x: 0,
39-
// y: -10
40-
// },
41-
// textAnchor: 'middle'
4234
};
4335

4436
Chartist.plugins = Chartist.plugins || {};
@@ -91,10 +83,14 @@
9183
var hasMeta = !!meta;
9284
var value = $point.getAttribute('ct:value');
9385

94-
if (options.tooltipFnc) {
86+
if (options.transformTooltipTextFnc && typeof options.transformTooltipTextFnc === 'function') {
87+
value = options.transformTooltipTextFnc(value);
88+
}
89+
90+
if (options.tooltipFnc && typeof options.tooltipFnc === 'function') {
9591
tooltipText = options.tooltipFnc(meta, value);
9692
} else {
97-
if(options.metaIsHTML){
93+
if (options.metaIsHTML) {
9894
var txt = document.createElement("textarea");
9995
txt.innerHTML = meta;
10096
meta = txt.value;

dist/chartist-plugin-tooltip.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)