mirror of
https://github.com/freqtrade/frequi.git
synced 2024-11-11 02:33:51 +00:00
Add Area chart helpers
This commit is contained in:
parent
7d2be4e6df
commit
8dd846d95b
48
src/shared/charts/areaPlotDataset.ts
Normal file
48
src/shared/charts/areaPlotDataset.ts
Normal file
|
@ -0,0 +1,48 @@
|
|||
import { PlotConfig } from '@/types';
|
||||
|
||||
/**
|
||||
* Calculate diff over 2 dataset columns and adds it to the end of the dataset
|
||||
* modifies the incomming dataset array inplace!
|
||||
*/
|
||||
export function calculateDiff(
|
||||
columns: string[],
|
||||
data: Array<number[]>,
|
||||
colFrom: string,
|
||||
colTo: string,
|
||||
): number[][] {
|
||||
const fromIdx = columns.indexOf(colFrom);
|
||||
const toIdx = columns.indexOf(colTo);
|
||||
columns.push(`${colFrom}-${colTo}`);
|
||||
|
||||
return data.map((original, idx) => {
|
||||
// Prevent mutation of original data
|
||||
const candle = original.slice();
|
||||
const diff = idx === 0 ? 0 : candle[toIdx] - candle[fromIdx];
|
||||
candle.push(diff);
|
||||
return candle;
|
||||
});
|
||||
}
|
||||
|
||||
export function getDiffColumns(plotConfig: PlotConfig): string[][] {
|
||||
const result: string[][] = [];
|
||||
if ('main_plot' in plotConfig) {
|
||||
Object.entries(plotConfig.main_plot).forEach(([key, value]) => {
|
||||
if (value.fill_to) {
|
||||
result.push([key, value.fill_to]);
|
||||
}
|
||||
});
|
||||
}
|
||||
if ('subplots' in plotConfig) {
|
||||
Object.entries(plotConfig.subplots).forEach(([_, subplots]) => {
|
||||
Object.entries(subplots).forEach(([key, value]) => {
|
||||
if (value.fill_to) {
|
||||
result.push([key, value.fill_to]);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
console.log('getDiffColumns', result);
|
||||
return result;
|
||||
}
|
||||
|
||||
export default calculateDiff;
|
|
@ -7,6 +7,7 @@ export enum ChartType {
|
|||
export interface IndicatorConfig {
|
||||
color?: string;
|
||||
type?: ChartType;
|
||||
fill_to?: string;
|
||||
}
|
||||
|
||||
export interface PlotConfig {
|
||||
|
|
Loading…
Reference in New Issue
Block a user