Skip to content

Commit

Permalink
Change tooltip docs message
Browse files Browse the repository at this point in the history
  • Loading branch information
danielcaldas committed Dec 18, 2020
1 parent 7360511 commit ff0deca
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions tools/tooltips-docs-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const TOOLTIPS_MAX_WIDTH = 400;
const LIVE_DOCS_LINK = "https://danielcaldas.github.io/react-d3-graph/docs/index.html";

if (!data || !data.length || !data[0].params) {
throw new Error("Invalid JSON provided from jsdoc parser");
throw new Error("Invalid JSON provided from jsdoc parser");
}

/**
Expand All @@ -12,12 +12,12 @@ if (!data || !data.length || !data[0].params) {
* @returns {string} new string which results on converting input string to kebab case.
*/
function strToKebabCase(s) {
const _s = s.replace(".", "-"); // drop all the '.' dots
const _s = s.replace(".", "-"); // drop all the '.' dots

return _s
.replace(/([a-z])([A-Z])/g, "$1-$2")
.replace(/\s+/g, "-")
.toLowerCase();
return _s
.replace(/([a-z])([A-Z])/g, "$1-$2")
.replace(/\s+/g, "-")
.toLowerCase();
}

/**
Expand All @@ -27,9 +27,9 @@ function strToKebabCase(s) {
* official documentation website.
*/
function generatePropertyAnchorLink(name) {
const suffix = strToKebabCase(name);
const suffix = strToKebabCase(name);

return `${LIVE_DOCS_LINK}#${suffix}`;
return `${LIVE_DOCS_LINK}#${suffix}`;
}

/**
Expand All @@ -38,11 +38,11 @@ function generatePropertyAnchorLink(name) {
* @returns {string} the footer for the given property.
*/
function generateCommonFooter(name) {
const href = generatePropertyAnchorLink(name);
const href = generatePropertyAnchorLink(name);

return `\
return `\
<small>\
for more details check the <a target="_blank" href="${href}">official documentation</a>\
<a target="_blank" href="${href}">see full official documentation</a>\
</small>\
`;
}
Expand All @@ -68,25 +68,25 @@ function generateCommonFooter(name) {
* information mapped by the param name.
*/
function getParamInfo(param) {
const { type, optional, defaultvalue, description: rawDescription, name } = param;
const types = type && type.names && type.names;
const ftype = types && types.length ? types.join("|") : "*";
const { type, optional, defaultvalue, description: rawDescription, name } = param;
const types = type && type.names && type.names;
const ftype = types && types.length ? types.join("|") : "*";

// make images smaller so that they fit in the tooltip
const description = rawDescription
.replace(/width="(\d+)"/gi, "width='400'")
.replace(/height="(\d+)"/gi, "height='200'")
.replace("🔗", ""); // drop docs anchor links
// make images smaller so that they fit in the tooltip
const description = rawDescription
.replace(/width="(\d+)"/gi, "width='400'")
.replace(/height="(\d+)"/gi, "height='200'")
.replace("🔗", ""); // drop docs anchor links

return {
[name]: `\
return {
[name]: `\
<h4>${name}</h4>\
<b>type</b>: ${ftype} | <b>default value</b>: ${defaultvalue} | <b>optional</b>: ${optional}\
<h5>Description</h5>\
<div style="max-width: ${TOOLTIPS_MAX_WIDTH}px;">${description}</div>\
${generateCommonFooter(name)}\
`,
};
};
}

/**
Expand All @@ -96,7 +96,7 @@ function getParamInfo(param) {
* @returns {string} final text without javascript code blocks.
*/
function stripJsMdBlocks(s) {
return s.replace(/```javascript(.*)```/gi, "");
return s.replace(/```javascript(.*)```/gi, "");
}

const graphConfigElms = data[0].params.map(getParamInfo).reduce((acc, o) => ({ ...o, ...acc }), {});
Expand Down

0 comments on commit ff0deca

Please sign in to comment.