Merge pull request #5676 from mempool/mononaut/balance-chart-ticks
Fix fiat tick precision on address balance chart
This commit is contained in:
		
						commit
						aef361b01a
					
				@ -123,7 +123,7 @@ export class AddressGraphComponent implements OnChanges, OnDestroy {
 | 
				
			|||||||
                    } else if (this.conversions && this.conversions['USD']) {
 | 
					                    } else if (this.conversions && this.conversions['USD']) {
 | 
				
			||||||
                      price = this.conversions['USD'];
 | 
					                      price = this.conversions['USD'];
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    return { ...item, price: price }
 | 
					                    return { ...item, price: price };
 | 
				
			||||||
                  });
 | 
					                  });
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
              }),
 | 
					              }),
 | 
				
			||||||
@ -350,7 +350,7 @@ export class AddressGraphComponent implements OnChanges, OnDestroy {
 | 
				
			|||||||
            show: this.showYAxis,
 | 
					            show: this.showYAxis,
 | 
				
			||||||
            color: 'rgb(110, 112, 121)',
 | 
					            color: 'rgb(110, 112, 121)',
 | 
				
			||||||
            formatter: function(val) {
 | 
					            formatter: function(val) {
 | 
				
			||||||
              return `$${this.amountShortenerPipe.transform(val, 0, undefined, true)}`;
 | 
					              return `$${this.amountShortenerPipe.transform(val, 3, undefined, true, true)}`;
 | 
				
			||||||
            }.bind(this)
 | 
					            }.bind(this)
 | 
				
			||||||
          },
 | 
					          },
 | 
				
			||||||
          splitLine: {
 | 
					          splitLine: {
 | 
				
			||||||
@ -418,7 +418,7 @@ export class AddressGraphComponent implements OnChanges, OnDestroy {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  onChartClick(e) {
 | 
					  onChartClick(e) {
 | 
				
			||||||
    if (this.hoverData?.length && this.hoverData[0]?.[2]?.txid) {
 | 
					    if (this.hoverData?.length && this.hoverData[0]?.[2]?.txid) {
 | 
				
			||||||
      this.zone.run(() => { 
 | 
					      this.zone.run(() => {
 | 
				
			||||||
        const url = this.relativeUrlPipe.transform(`/tx/${this.hoverData[0][2].txid}`);
 | 
					        const url = this.relativeUrlPipe.transform(`/tx/${this.hoverData[0][2].txid}`);
 | 
				
			||||||
        if (e.event.event.shiftKey || e.event.event.ctrlKey || e.event.event.metaKey) {
 | 
					        if (e.event.event.shiftKey || e.event.event.ctrlKey || e.event.event.metaKey) {
 | 
				
			||||||
          window.open(url);
 | 
					          window.open(url);
 | 
				
			||||||
@ -483,7 +483,7 @@ export class AddressGraphComponent implements OnChanges, OnDestroy {
 | 
				
			|||||||
    // Add a point at today's date to make the graph end at the current time
 | 
					    // Add a point at today's date to make the graph end at the current time
 | 
				
			||||||
    extendedSummary.unshift({ time: Date.now() / 1000, value: 0 });
 | 
					    extendedSummary.unshift({ time: Date.now() / 1000, value: 0 });
 | 
				
			||||||
    extendedSummary.reverse();
 | 
					    extendedSummary.reverse();
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    let oneHour = 60 * 60;
 | 
					    let oneHour = 60 * 60;
 | 
				
			||||||
    // Fill gaps longer than interval
 | 
					    // Fill gaps longer than interval
 | 
				
			||||||
    for (let i = 0; i < extendedSummary.length - 1; i++) {
 | 
					    for (let i = 0; i < extendedSummary.length - 1; i++) {
 | 
				
			||||||
@ -496,7 +496,7 @@ export class AddressGraphComponent implements OnChanges, OnDestroy {
 | 
				
			|||||||
        i += hours - 1;
 | 
					        i += hours - 1;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
    return extendedSummary.reverse();
 | 
					    return extendedSummary.reverse();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -8,8 +8,12 @@ export class AmountShortenerPipe implements PipeTransform {
 | 
				
			|||||||
    const digits = args[0] ?? 1;
 | 
					    const digits = args[0] ?? 1;
 | 
				
			||||||
    const unit = args[1] || undefined;
 | 
					    const unit = args[1] || undefined;
 | 
				
			||||||
    const isMoney = args[2] || false;
 | 
					    const isMoney = args[2] || false;
 | 
				
			||||||
 | 
					    const sigfigs = args[3] || false; // if true, "digits" is the number of significant digits, not the number of decimal places
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (num < 1000) {
 | 
					    if (num < 1000) {
 | 
				
			||||||
 | 
					      if (sigfigs) {
 | 
				
			||||||
 | 
					        return Number(num.toPrecision(digits));
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
      return num.toFixed(digits);
 | 
					      return num.toFixed(digits);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -25,10 +29,15 @@ export class AmountShortenerPipe implements PipeTransform {
 | 
				
			|||||||
    const rx = /\.0+$|(\.[0-9]*[1-9])0+$/;
 | 
					    const rx = /\.0+$|(\.[0-9]*[1-9])0+$/;
 | 
				
			||||||
    const item = lookup.slice().reverse().find((item) => num >= item.value);
 | 
					    const item = lookup.slice().reverse().find((item) => num >= item.value);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (unit !== undefined) {
 | 
					    if (!item) {
 | 
				
			||||||
      return item ? (num / item.value).toFixed(digits).replace(rx, '$1') + ' ' + item.symbol + unit : '0';
 | 
					      return '0';
 | 
				
			||||||
    } else {
 | 
					 | 
				
			||||||
      return item ? (num / item.value).toFixed(digits).replace(rx, '$1') + item.symbol : '0';
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const scaledNum = num / item.value;
 | 
				
			||||||
 | 
					    const formattedNum = Number(sigfigs ? scaledNum.toPrecision(digits) : scaledNum.toFixed(digits)).toString();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return unit !== undefined
 | 
				
			||||||
 | 
					      ? formattedNum + ' ' + item.symbol + unit
 | 
				
			||||||
 | 
					      : formattedNum + item.symbol;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user