-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #791 from olegchernenko/master
- Loading branch information
Showing
15 changed files
with
94 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** Interface to be implemented by the object in order to be used as a price formatter */ | ||
export interface IPriceFormatter { | ||
/** | ||
* Formatting function | ||
* | ||
* @param price - original price to be formatted | ||
* @returns formatted price | ||
*/ | ||
format(price: number): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
tests/e2e/graphics/test-cases/series/series-price-formatter.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
function generateData() { | ||
const res = []; | ||
const time = new Date(Date.UTC(2018, 0, 1, 0, 0, 0, 0)); | ||
for (let i = 0; i < 60; ++i) { | ||
res.push({ | ||
time: time.getTime() / 1000, | ||
value: i, | ||
}); | ||
|
||
time.setUTCDate(time.getUTCDate() + 1); | ||
} | ||
return res; | ||
} | ||
|
||
function runTestCase(container) { | ||
const chart = LightweightCharts.createChart(container); | ||
|
||
const lineSeries = chart.addLineSeries({ | ||
priceFormat: { | ||
type: 'price', | ||
precision: 4, | ||
minMove: 0.005, | ||
}, | ||
}); | ||
lineSeries.setData(generateData()); | ||
console.assert(lineSeries.priceFormatter().format(12.1) === '12.1000', 'Wrong format'); | ||
|
||
lineSeries.applyOptions({ | ||
priceFormat: { | ||
type: 'volume', | ||
precision: 5, | ||
minMove: 0.05, | ||
}, | ||
}); | ||
console.assert(lineSeries.priceFormatter().format(1000) === '1K', 'Wrong format'); | ||
|
||
lineSeries.applyOptions({ | ||
priceFormat: { | ||
type: 'percent', | ||
precision: 3, | ||
minMove: 0.05, | ||
}, | ||
}); | ||
console.assert(lineSeries.priceFormatter().format(12.1) === '12.0%', 'Wrong format'); | ||
|
||
lineSeries.applyOptions({ | ||
priceFormat: { | ||
type: 'custom', | ||
minMove: 0.02, | ||
formatter: price => 'price=' + price.toFixed(2), | ||
}, | ||
}); | ||
console.assert(lineSeries.priceFormatter().format(12.1) === 'price=12.10', 'Wrong format'); | ||
} |