diff --git a/README.md b/README.md index 8c886ea..a59e18c 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ Is possible to apply a custom parsing for each column content. By default, is ap Regex: ``` -/[\d|.|,]+/ +/[\d|\-|.|,]+/ ``` #### Example diff --git a/dist/columnHeatmap.min.js b/dist/columnHeatmap.min.js index ebcc3ef..129ddbd 100644 --- a/dist/columnHeatmap.min.js +++ b/dist/columnHeatmap.min.js @@ -1 +1 @@ -!function(t){t.columnHeatmap={name:"columnHeatmap",version:"1.0",release:"2020-06-15",author:"Paulo Kramer",site:"https://www.paulokramer.com",documentation:"https://www.paulokramer.com/plugins/columnHeatmap#documentacao"},t.fn.columnHeatmap=function(e){var n=t.extend({columns:[],contrast:!0,inverse:!1,animated:!0,animationSpeed:.1,fn_parseValue:null,colorStartPoint:0},e);try{if(!this.is("table"))throw"Selected element isn't a table";if(0==n.columns.length)throw"You need to specify the columns";if(n.colorStartPoint<0||n.colorStartPoint>360)throw`colorStartPoint need to be beetween 0 and 360, current: ${n.colorStartPoint}`;let e=this.find("tbody tr"),a=[];t.each(n.columns,(o,r)=>{e.each((e,o)=>{0==e&&(a[r.toString()]=new Array,a[r.toString()].values=new Array,a[r.toString()].tds=new Array);let l=t(o).find("td")[r];if(a[r.toString()].tds.push(l),"function"==typeof n.fn_parseValue){let e=fn_parseValue(t(l).text());if(void 0===e)throw"None value returned in fn_parseValue";a[r.toString()].values.push(e)}else{let e=t(l).text().match(/[\d|.|,]+/)[0];a[r.toString()].values.push(parseFloat(e))}})}),a=a.filter(t=>t),t.each(a,(t,e)=>{e&&e.values&&(a[t].min=null,a[t].max=null,a[t].min=e.values.reduce(function(t,e){return Math.min(t,e)}),a[t].max=e.values.reduce(function(t,e){return Math.max(t,e)}))}),t.each(a,(e,a)=>{t.each(a.values,(e,o)=>{let r=function(t,e,a){var o=100*(t-e)/(a-e);n.inverse&&(o=100-o);return{color:"hsl("+(Math.abs(-1*(o-100))+n.colorStartPoint)+", 70%, 65%)",perc:o}}(o,a.min,a.max);n.animated&&t(a.tds[e]).css("transition",`background-color ${n.animationSpeed}s linear, color ${n.animationSpeed}s linear`),t(a.tds[e]).css("background-color",r.color),r.perc>70&&n.contrast&&t(a.tds[e]).css("color","#fff")})})}catch(e){return void console.error(`[${t.columnHeatmap.name}::Error] ${e}`)}}}(jQuery); \ No newline at end of file +!function(t){t.columnHeatmap={name:"columnHeatmap",version:"1.0",release:"2020-06-15",author:"Paulo Kramer",site:"https://www.paulokramer.com",documentation:"https://github.com/PauloAK/jQuery-columnHeatMap"},t.fn.columnHeatmap=function(e){var n=t.extend({columns:[],contrast:!0,inverse:!1,animated:!0,animationSpeed:.1,fn_parseValue:null,colorStartPoint:0},e);try{if(!this.is("table"))throw"Selected element isn't a table";if(0==n.columns.length)throw"You need to specify the columns";if(n.colorStartPoint<0||n.colorStartPoint>360)throw`colorStartPoint need to be beetween 0 and 360, current: ${n.colorStartPoint}`;let e=this.find("tbody tr"),a=[];t.each(n.columns,(o,r)=>{e.each((e,o)=>{0==e&&(a[r.toString()]=new Array,a[r.toString()].values=new Array,a[r.toString()].tds=new Array);let l=t(o).find("td")[r];if(a[r.toString()].tds.push(l),"function"==typeof n.fn_parseValue){let e=fn_parseValue(t(l).text());if(void 0===e)throw"None value returned in fn_parseValue";a[r.toString()].values.push(e)}else{let e=t(l).text().match(/[\d|\-|.|,]+/)[0];a[r.toString()].values.push(parseFloat(e))}})}),a=a.filter(t=>t),t.each(a,(t,e)=>{e&&e.values&&(a[t].min=null,a[t].max=null,a[t].min=e.values.reduce(function(t,e){return Math.min(t,e)}),a[t].max=e.values.reduce(function(t,e){return Math.max(t,e)}))}),t.each(a,(e,a)=>{t.each(a.values,(e,o)=>{let r=function(t,e,a){var o=100*(t-e)/(a-e);n.inverse&&(o=100-o);return{color:"hsl("+(Math.abs(-1*(o-100))+n.colorStartPoint)+", 70%, 65%)",perc:o}}(o,a.min,a.max);n.animated&&t(a.tds[e]).css("transition",`background-color ${n.animationSpeed}s linear, color ${n.animationSpeed}s linear`),t(a.tds[e]).css("background-color",r.color),r.perc>70&&n.contrast&&t(a.tds[e]).css("color","#fff")})})}catch(e){return void console.error(`[${t.columnHeatmap.name}::Error] ${e}`)}}}(jQuery); diff --git a/src/columnHeatmap.js b/src/columnHeatmap.js index 4d727ad..9faf9a4 100644 --- a/src/columnHeatmap.js +++ b/src/columnHeatmap.js @@ -55,7 +55,7 @@ } } else { // Get only numbers from the cell, (with float points) - let numbers = $(td).text().match(/[\d|.|,]+/)[0]; + let numbers = $(td).text().match(/[\d|\-|.|,]+/)[0]; data[col.toString()]['values'].push(parseFloat(numbers)); }