From 1c6f059eb4fd48116aed9a2199f7308f18e7de93 Mon Sep 17 00:00:00 2001 From: Allan Jardine Date: Tue, 12 Sep 2023 09:35:30 +0100 Subject: [PATCH] Update src with change from #579 --- dataRender/percentageBars.js | 32 +++++++------ dataRender/percentageBars.min.js | 2 +- dataRender/percentageBars.min.mjs | 2 +- dataRender/percentageBars.mjs | 70 ++++++++++++++++++++-------- dataRender/src/percentageBars.ts | 76 ++++++++++++++++++++++--------- make.sh | 14 +++--- 6 files changed, 133 insertions(+), 63 deletions(-) diff --git a/dataRender/percentageBars.js b/dataRender/percentageBars.js index 81b592a6..3aa9f329 100644 --- a/dataRender/percentageBars.js +++ b/dataRender/percentageBars.js @@ -107,7 +107,6 @@ DataTable.render.percentBar = function (pShape, cText, cBorder, cBar, cBack, vRo bType = bType || 'ridge'; //Bar templates var styleRule1 = 'max-width:100px;height:12px;margin:0 auto;'; - return function (d, type, row) { //Remove % if found in the value //Round to the given parameter vRound @@ -123,7 +122,6 @@ DataTable.render.percentBar = function (pShape, cText, cBorder, cBar, cBack, vRo if (typeof d !== 'number' && typeof d !== 'string') { return d; } - var cBackConditional; var cBarConditional; var cTextConditional; @@ -133,39 +131,43 @@ DataTable.render.percentBar = function (pShape, cText, cBorder, cBar, cBack, vRo if (s >= conditionalColors[i].min && s <= conditionalColors[i].max) { if (conditionalColors[i].barColor) { cBarConditional = conditionalColors[i].barColor; - } else { + } + else { cBarConditional = cBar; } if (conditionalColors[i].backgroundColor) { cBackConditional = conditionalColors[i].backgroundColor; - } else { + } + else { cBackConditional = cBack; } if (conditionalColors[i].textColor) { cTextConditional = conditionalColors[i].textColor; - } else { + } + else { cTextConditional = cText; } break; } } - } else { + } + else { cBackConditional = cBack; cBarConditional = cBar; cTextConditional = cText; } var styleRule2 = 'border:2px ' + - bType + - ' ' + - cBorder + - ';line-height:12px;font-size:14px;color:' + - cText + - ';background:' + - cBackConditional + - ';position:relative;'; + bType + + ' ' + + cBorder + + ';line-height:12px;font-size:14px;color:' + + cText + + ';background:' + + cBackConditional + + ';position:relative;'; //Bar template var styleRule3 = 'height:12px;line-height:12px;text-align:center;background-color:' + - cBarConditional + ';padding:auto 6px;'; + cBarConditional + ';padding:auto 6px;'; //Square is default, make template round if pShape == round if (pShape == 'round') { styleRule2 += 'border-radius:5px;'; diff --git a/dataRender/percentageBars.min.js b/dataRender/percentageBars.min.js index 3e351ef3..3be59968 100644 --- a/dataRender/percentageBars.min.js +++ b/dataRender/percentageBars.min.js @@ -1,2 +1,2 @@ /*! © Drijkoningen Dirk - datatables.net/license */ -!function(n){var i,o;"function"==typeof define&&define.amd?define(["jquery","datatables.net"],function(e){return n(e,window,document)}):"object"==typeof exports?(i=require("jquery"),o=function(e,t){t.fn.dataTable||require("datatables.net")(e,t)},"undefined"==typeof window?module.exports=function(e,t){return e=e||window,t=t||i(e),o(e,t),n(t,0,e.document)}:(o(window,i),module.exports=n(i,window,window.document))):n(jQuery,window,document)}(function(e,t,n,i){"use strict";e=e.fn.dataTable;return e.render.percentBar=function(e,t,n,i,o,r,d){r=r||0;var u="border:2px "+(d=d||"ridge")+" "+(n=n||"#BCBCBC")+";line-height:12px;font-size:14px;color:"+(t=t||"#000")+";background:"+(o=o||"#E6E6E6")+";position:relative;",a="height:12px;line-height:12px;text-align:center;background-color:"+(i=i||"#5FD868")+";padding:auto 6px;";return"round"==(e=e||"square")&&(u+="border-radius:5px;",a+="border-top-left-radius:4px;border-bottom-left-radius:4px;"),function(e,t,n){var i=parseFloat(e.toString().replace(/\s%|%/g,"")).toFixed(r);return 100
'+i+"%
"}},e}); \ No newline at end of file +!function(r){var n,o;"function"==typeof define&&define.amd?define(["jquery","datatables.net"],function(e){return r(e,window,document)}):"object"==typeof exports?(n=require("jquery"),o=function(e,t){t.fn.dataTable||require("datatables.net")(e,t)},"undefined"==typeof window?module.exports=function(e,t){return e=e||window,t=t||n(e),o(e,t),r(t,0,e.document)}:(o(window,n),module.exports=r(n,window,window.document))):r(jQuery,window,document)}(function(e,t,r,n){"use strict";e=e.fn.dataTable;return e.render.percentBar=function(a,u,l,f,p,s,c,x){a=a||"square",u=u||"#000",l=l||"#BCBCBC",f=f||"#5FD868",p=p||"#E6E6E6",s=s||0,c=c||"ridge";return function(e,t,r){var n,o,i=parseFloat(e.toString().replace(/\s%|%/g,"")).toFixed(s);if(100=x[d].min&&i<=x[d].max){o=x[d].barColor||f,n=x[d].backgroundColor||p,x[d].textColor||u;break}}else n=p,o=f,0;t="border:2px "+c+" "+l+";line-height:12px;font-size:14px;color:"+u+";background:"+n+";position:relative;",e="height:12px;line-height:12px;text-align:center;background-color:"+o+";padding:auto 6px;";return"round"==a&&(t+="border-radius:5px;",e+="border-top-left-radius:4px;border-bottom-left-radius:4px;"),'
'+i+"%
"}},e}); \ No newline at end of file diff --git a/dataRender/percentageBars.min.mjs b/dataRender/percentageBars.min.mjs index a636d6a3..b1f4d94d 100644 --- a/dataRender/percentageBars.min.mjs +++ b/dataRender/percentageBars.min.mjs @@ -1,2 +1,2 @@ /*! © Drijkoningen Dirk - datatables.net/license */ -import jQuery from"jquery";import DataTable from"datatables.net";let $=jQuery;DataTable.render.percentBar=function(t,e,r,i,a,o,d){o=o||0;var n="border:2px "+(d=d||"ridge")+" "+(r=r||"#BCBCBC")+";line-height:12px;font-size:14px;color:"+(e=e||"#000")+";background:"+(a=a||"#E6E6E6")+";position:relative;",p="height:12px;line-height:12px;text-align:center;background-color:"+(i=i||"#5FD868")+";padding:auto 6px;";return"round"==(t=t||"square")&&(n+="border-radius:5px;",p+="border-top-left-radius:4px;border-bottom-left-radius:4px;"),function(t,e,r){var i=parseFloat(t.toString().replace(/\s%|%/g,"")).toFixed(o);return 100
'+i+"%
"}};export default DataTable; \ No newline at end of file +import jQuery from"jquery";import DataTable from"datatables.net";let $=jQuery;DataTable.render.percentBar=function(d,l,p,u,s,x,b,f){d=d||"square",l=l||"#000",p=p||"#BCBCBC",u=u||"#5FD868",s=s||"#E6E6E6",x=x||0,b=b||"ridge";return function(e,t,r){var i,o,a=parseFloat(e.toString().replace(/\s%|%/g,"")).toFixed(x);if(100=f[n].min&&a<=f[n].max){o=f[n].barColor||u,i=f[n].backgroundColor||s,f[n].textColor||l;break}}else i=s,o=u,0;t="border:2px "+b+" "+p+";line-height:12px;font-size:14px;color:"+l+";background:"+i+";position:relative;",e="height:12px;line-height:12px;text-align:center;background-color:"+o+";padding:auto 6px;";return"round"==d&&(t+="border-radius:5px;",e+="border-top-left-radius:4px;border-bottom-left-radius:4px;"),'
'+a+"%
"}};export default DataTable; \ No newline at end of file diff --git a/dataRender/percentageBars.mjs b/dataRender/percentageBars.mjs index 8bbceb1f..eb0d553f 100644 --- a/dataRender/percentageBars.mjs +++ b/dataRender/percentageBars.mjs @@ -57,7 +57,7 @@ let $ = jQuery; * } ] * } ); */ -DataTable.render.percentBar = function (pShape, cText, cBorder, cBar, cBack, vRound, bType) { +DataTable.render.percentBar = function (pShape, cText, cBorder, cBar, cBack, vRound, bType, conditionalColors) { pShape = pShape || 'square'; cText = cText || '#000'; cBorder = cBorder || '#BCBCBC'; @@ -67,23 +67,6 @@ DataTable.render.percentBar = function (pShape, cText, cBorder, cBar, cBack, vRo bType = bType || 'ridge'; //Bar templates var styleRule1 = 'max-width:100px;height:12px;margin:0 auto;'; - var styleRule2 = 'border:2px ' + - bType + - ' ' + - cBorder + - ';line-height:12px;font-size:14px;color:' + - cText + - ';background:' + - cBack + - ';position:relative;'; - var styleRule3 = 'height:12px;line-height:12px;text-align:center;background-color:' + - cBar + - ';padding:auto 6px;'; - //Square is default, make template round if pShape == round - if (pShape == 'round') { - styleRule2 += 'border-radius:5px;'; - styleRule3 += 'border-top-left-radius:4px;border-bottom-left-radius:4px;'; - } return function (d, type, row) { //Remove % if found in the value //Round to the given parameter vRound @@ -99,6 +82,57 @@ DataTable.render.percentBar = function (pShape, cText, cBorder, cBar, cBack, vRo if (typeof d !== 'number' && typeof d !== 'string') { return d; } + var cBackConditional; + var cBarConditional; + var cTextConditional; + // do conditional colors based on user input + if (conditionalColors) { + for (var i = 0; i < conditionalColors.length; i++) { + if (s >= conditionalColors[i].min && s <= conditionalColors[i].max) { + if (conditionalColors[i].barColor) { + cBarConditional = conditionalColors[i].barColor; + } + else { + cBarConditional = cBar; + } + if (conditionalColors[i].backgroundColor) { + cBackConditional = conditionalColors[i].backgroundColor; + } + else { + cBackConditional = cBack; + } + if (conditionalColors[i].textColor) { + cTextConditional = conditionalColors[i].textColor; + } + else { + cTextConditional = cText; + } + break; + } + } + } + else { + cBackConditional = cBack; + cBarConditional = cBar; + cTextConditional = cText; + } + var styleRule2 = 'border:2px ' + + bType + + ' ' + + cBorder + + ';line-height:12px;font-size:14px;color:' + + cText + + ';background:' + + cBackConditional + + ';position:relative;'; + //Bar template + var styleRule3 = 'height:12px;line-height:12px;text-align:center;background-color:' + + cBarConditional + ';padding:auto 6px;'; + //Square is default, make template round if pShape == round + if (pShape == 'round') { + styleRule2 += 'border-radius:5px;'; + styleRule3 += 'border-top-left-radius:4px;border-bottom-left-radius:4px;'; + } //Return the code for the bar return ('