Skip to content

Commit

Permalink
bars
Browse files Browse the repository at this point in the history
  • Loading branch information
severinlandolt committed Dec 12, 2024
1 parent e7900f3 commit 85e491c
Show file tree
Hide file tree
Showing 16 changed files with 84 additions and 341 deletions.
2 changes: 1 addition & 1 deletion src/components/chart-elements/LineChart/LineChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import React, { Fragment, useState } from "react";
import {
CartesianGrid,
Dot,
Label,
Legend,
Line,
LineChart as ReChartsLineChart,
ResponsiveContainer,
Tooltip,
XAxis,
YAxis,
Label,
} from "recharts";
import { AxisDomain } from "recharts/types/util/types";

Expand Down
62 changes: 12 additions & 50 deletions src/components/vis-elements/CategoryBar/CategoryBar.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
"use client";
import React, { useMemo } from "react";
import { bgColors } from "components/spark-elements/common/style";
import Tooltip, { useTooltip } from "components/util-elements/Tooltip/Tooltip";
import {
getColorClassNames,
makeClassName,
sumNumericArray,
themeColorRange,
tremorTwMerge,
} from "lib";
import { colorPalette } from "lib/theme";
import { Color } from "../../../lib";

const makeCategoryBarClassName = makeClassName("CategoryBar");
import { Color, sumNumericArray, themeColorRange, tremorTwMerge } from "lib";
import React, { useMemo } from "react";

const getMarkerBgColor = (
markerValue: number | undefined,
Expand All @@ -23,7 +14,7 @@ const getMarkerBgColor = (
let prefixSum = 0;
for (let i = 0; i < values.length; i++) {
const currentWidthPercentage = values[i];
const currentBgColor = getColorClassNames(colors[i], colorPalette.background).bgColor;
const currentBgColor = bgColors[colors[i] as Color];

prefixSum += currentWidthPercentage;
if (prefixSum >= markerValue) return currentBgColor;
Expand All @@ -42,13 +33,7 @@ const BarLabels = ({ values }: { values: number[] }) => {
return (
<div
className={tremorTwMerge(
makeCategoryBarClassName("labels"),
// common
"text-tremor-default relative mb-2 flex h-5 w-full",
// light
"text-tremor-content",
// dark
"dark:text-dark-tremor-content",
"text-tremor-default text-tremor-content-default relative mb-2 flex h-5 w-full",
)}
>
{values.slice(0, values.length).map((widthPercentage, idx) => {
Expand Down Expand Up @@ -85,7 +70,7 @@ const BarLabels = ({ values }: { values: number[] }) => {
);
};

export interface CategoryBarProps extends React.HTMLAttributes<HTMLDivElement> {
interface CategoryBarProps extends React.HTMLAttributes<HTMLDivElement> {
values: number[];
colors?: Color[];
markerValue?: number;
Expand Down Expand Up @@ -123,21 +108,11 @@ const CategoryBar = React.forwardRef<HTMLDivElement, CategoryBarProps>((props, r
return (
<>
<Tooltip text={tooltip} {...tooltipProps} />
<div
ref={ref}
className={tremorTwMerge(makeCategoryBarClassName("root"), className)}
{...other}
>
<div ref={ref} className={tremorTwMerge(className)} {...other}>
{showLabels ? <BarLabels values={values} /> : null}
<div
className={tremorTwMerge(
makeCategoryBarClassName("barWrapper"),
"relative flex h-2 w-full items-center",
)}
>
<div className={tremorTwMerge("relative flex h-2 w-full items-center")}>
<div
className={tremorTwMerge(
// common
"rounded-tremor-full flex h-full flex-1 items-center overflow-hidden",
)}
>
Expand All @@ -147,11 +122,7 @@ const CategoryBar = React.forwardRef<HTMLDivElement, CategoryBarProps>((props, r
return (
<div
key={`item-${idx}`}
className={tremorTwMerge(
makeCategoryBarClassName("categoryBar"),
"h-full",
getColorClassNames(baseColor, colorPalette.background).bgColor,
)}
className={tremorTwMerge("h-full", bgColors[baseColor as Color])}
style={{ width: `${percentage}%` }}
/>
);
Expand All @@ -160,10 +131,7 @@ const CategoryBar = React.forwardRef<HTMLDivElement, CategoryBarProps>((props, r
{markerValue !== undefined ? (
<div
ref={tooltipProps.refs.setReference}
className={tremorTwMerge(
makeCategoryBarClassName("markerWrapper"),
"absolute right-1/2 w-5 -translate-x-1/2",
)}
className={tremorTwMerge("absolute right-1/2 w-5 -translate-x-1/2")}
style={{
left: `${markerPositionLeft}%`,
transition: showAnimation ? "all 1s" : "",
Expand All @@ -172,13 +140,7 @@ const CategoryBar = React.forwardRef<HTMLDivElement, CategoryBarProps>((props, r
>
<div
className={tremorTwMerge(
makeCategoryBarClassName("marker"),
// common
"rounded-tremor-full mx-auto h-4 w-1 ring-2",
// light
"ring-tremor-brand-inverted",
// dark
"dark:ring-dark-tremor-brand-inverted",
"rounded-tremor-full ring-tremor-brand-inverted mx-auto h-4 w-1 ring-2",
markerBgColor,
)}
/>
Expand All @@ -192,4 +154,4 @@ const CategoryBar = React.forwardRef<HTMLDivElement, CategoryBarProps>((props, r

CategoryBar.displayName = "CategoryBar";

export default CategoryBar;
export { CategoryBar, type CategoryBarProps };
2 changes: 1 addition & 1 deletion src/components/vis-elements/CategoryBar/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { default as CategoryBar } from "./CategoryBar";
export { CategoryBar } from "./CategoryBar";
export type { CategoryBarProps } from "./CategoryBar";
111 changes: 0 additions & 111 deletions src/components/vis-elements/DeltaBar/DeltaBar.tsx

This file was deleted.

2 changes: 0 additions & 2 deletions src/components/vis-elements/DeltaBar/index.ts

This file was deleted.

24 changes: 0 additions & 24 deletions src/components/vis-elements/DeltaBar/styles.ts

This file was deleted.

Loading

0 comments on commit 85e491c

Please sign in to comment.