Skip to content

Commit

Permalink
Update src with change from #579
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanJard committed Sep 12, 2023
1 parent 6c36a57 commit 1c6f059
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 63 deletions.
32 changes: 17 additions & 15 deletions dataRender/percentageBars.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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;';
Expand Down
2 changes: 1 addition & 1 deletion dataRender/percentageBars.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dataRender/percentageBars.min.mjs
Original file line number Diff line number Diff line change
@@ -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&&(i=100),"display"!==e?i:"number"!=typeof t&&"string"!=typeof t?t:'<div style="max-width:100px;height:12px;margin:0 auto;"><div style="'+n+'"><div style="'+p+"width:"+i+'%;"></div><div style="width:100%;text-align:center;position:absolute;left:0;top:0;">'+i+"%</div></div></div>"}};export default DataTable;
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<a&&(a=100),"display"!==t)return a;if("number"!=typeof e&&"string"!=typeof e)return e;if(f){for(var n=0;n<f.length;n++)if(a>=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;"),'<div style="max-width:100px;height:12px;margin:0 auto;"><div style="'+t+'"><div style="'+e+"width:"+a+'%;"></div><div style="width:100%;text-align:center;position:absolute;left:0;top:0;">'+a+"%</div></div></div>"}};export default DataTable;
70 changes: 52 additions & 18 deletions dataRender/percentageBars.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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
Expand All @@ -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 ('<div style="' +
styleRule1 +
Expand Down
76 changes: 55 additions & 21 deletions dataRender/src/percentageBars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ DataTable.render.percentBar = function (
cBar,
cBack,
vRound,
bType
bType,
conditionalColors
) {
pShape = pShape || 'square';
cText = cText || '#000';
Expand All @@ -88,26 +89,6 @@ DataTable.render.percentBar = function (

//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
Expand All @@ -126,6 +107,59 @@ DataTable.render.percentBar = function (
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 (
'<div style="' +
Expand Down
14 changes: 7 additions & 7 deletions make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ PLUGINS="${DT_SRC}/extensions/Plugins"
# ts_plugin $file
# done

# for file in $PLUGINS/dataRender/src/*.ts; do
# ts_plugin $file
# done
for file in $PLUGINS/dataRender/src/*.ts; do
ts_plugin $file
done

# for file in $PLUGINS/features/*/src/*.ts; do
# ts_plugin $file
Expand All @@ -121,8 +121,8 @@ PLUGINS="${DT_SRC}/extensions/Plugins"
# ts_plugin $file
# done

echo_section " Languages"
for file in $PLUGINS/i18n/*.json; do
lang_plugin $file
done
# echo_section " Languages"
# for file in $PLUGINS/i18n/*.json; do
# lang_plugin $file
# done

0 comments on commit 1c6f059

Please sign in to comment.