| 174 | |
| 175 | compareValues: function (a, b, fn) { |
| 176 | function normalizeNumberString(str) { |
| 177 | if (typeof str !== "string") return str; |
| 178 | str = str.trim(); |
| 179 | const hasComma = str.includes(','); |
| 180 | const hasDot = str.includes('.'); |
| 181 | |
| 182 | if (hasComma && hasDot) { |
| 183 | if (str.lastIndexOf(',') > str.lastIndexOf('.')) { |
| 184 | // comma as decimal separator |
| 185 | str = str.replace(/\./g, ''); |
| 186 | str = str.replace(',', '.'); |
| 187 | } else { |
| 188 | // dot as decimal separator |
| 189 | str = str.replace(/,/g, ''); |
| 190 | } |
| 191 | } else if (hasComma) { |
| 192 | const idx = str.lastIndexOf(','); |
| 193 | const digits = str.length - idx - 1; |
| 194 | if (digits <= 2) { |
| 195 | str = str.replace(',', '.'); |
| 196 | } else { |
| 197 | str = str.replace(/,/g, ''); |
| 198 | } |
| 199 | } else if (hasDot) { |
| 200 | const idx = str.lastIndexOf('.'); |
| 201 | const digits = str.length - idx - 1; |
| 202 | if (digits > 2) { |
| 203 | str = str.replace(/\./g, ''); |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | return str.replace(/\s/g, ''); |
| 208 | } |
| 209 | |
| 210 | const normalizedA = OCA.Analytics.Visualization.normalizeThresholdString(a); |
| 211 | const normalizedB = OCA.Analytics.Visualization.normalizeThresholdString(b); |