2024-02-03 20:23:31 -07:00
|
|
|
import React from "react";
|
|
|
|
import { Text, View } from "react-native";
|
2024-01-17 14:29:28 -07:00
|
|
|
|
2024-02-03 20:23:31 -07:00
|
|
|
import { chartLabel } from "../chart-styles";
|
2024-01-17 14:29:28 -07:00
|
|
|
|
2024-02-03 20:23:31 -07:00
|
|
|
type Axis = "RIGHT" | "LEFT";
|
2024-01-17 14:29:28 -07:00
|
|
|
|
|
|
|
interface YLabel {
|
2024-02-03 20:23:31 -07:00
|
|
|
axis: Axis;
|
|
|
|
displayName: string;
|
|
|
|
color: string;
|
2024-01-17 14:29:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
type ChartLabelProps = {
|
2024-02-03 20:23:31 -07:00
|
|
|
title: string;
|
|
|
|
yLabels: Array<YLabel>;
|
2024-01-17 14:29:28 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
const renderLabels = (yLabels: Array<YLabel>) => {
|
2024-02-03 20:23:31 -07:00
|
|
|
return yLabels.map((label) => (
|
|
|
|
<View
|
|
|
|
key={`${label.axis}-${label.displayName}`}
|
|
|
|
style={chartLabel.labelInnerRow}
|
|
|
|
>
|
|
|
|
<View
|
|
|
|
style={[chartLabel.labelColorBox, { backgroundColor: label.color }]}
|
|
|
|
/>
|
|
|
|
<View style={chartLabel.labelTextMargin}>
|
|
|
|
<Text style={chartLabel.labelText}>{label.displayName}</Text>
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
));
|
2024-01-17 14:29:28 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
export default function ChartLabel({ title, yLabels }: ChartLabelProps) {
|
2024-02-03 20:23:31 -07:00
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<View style={chartLabel.titleRow}>
|
|
|
|
<Text style={chartLabel.titleText}>{title}</Text>
|
|
|
|
</View>
|
|
|
|
<View style={chartLabel.labelOuterRow}>{renderLabels(yLabels)}</View>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|