Skip to content

Commit

Permalink
Breaking changes
Browse files Browse the repository at this point in the history
  • Loading branch information
geoperez committed Nov 14, 2023
1 parent a333237 commit af583b8
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 117 deletions.
2 changes: 1 addition & 1 deletion .ncurc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"upgrade": true,
"reject": ["@headlessui/react"]
"reject": ["@headlessui/react","@rspack/cli"]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@tremor/react": "^3.11.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"recharts": "2.9.2",
"recharts": "2.9.3",
"tailwind-merge": "^2.0.0",
"tailwind-styled-components": "^2.2.0",
"uno-js": "^3.57.0"
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 10 additions & 8 deletions sample/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
Blur,
Burger,
ChartBar,
ComposedLineChart,
DataChart,
ErrorBoundary,
Footer,
Expand Down Expand Up @@ -198,10 +199,14 @@ const Application = () => {
<AwaitableMetric>{!loading ? '100%' : undefined}</AwaitableMetric>
</Card>
<Card>
<Text>Metric 3</Text>
<AwaitableMetric>{!loading ? '100%' : undefined}</AwaitableMetric>
<PieChart
rawData={loading ? undefined : chartData}
dataCallback={(d) => Object.values(d).map((x: any) => ({ name: x.name, value: x.Value }))}
legendFormatType='money'
/>
</Card>
<Card>
<Text className='font-medium'>Line Chart</Text>
<DataChart
rawData={loading ? undefined : chartData}
dataCallback={identity}
Expand All @@ -223,12 +228,9 @@ const Application = () => {
/>
</Card>
<Card className='h-96'>
<Text className='font-medium'>Pie Chart</Text>
<PieChart
rawData={loading ? undefined : chartData}
dataCallback={(d) => Object.values(d).map((x: any) => ({ name: x.name, value: x.Value }))}
legendFormatType='money'
/>
<Text className='font-medium'>Composited Chart</Text>
<ComposedLineChart rawData={loading ? undefined : chartData} dataCallback={identity}
lines={[{ dataKey: 'name', yAxisId: 'left' }]} />
</Card>
<Col numColSpan={3}>
<Card>
Expand Down
71 changes: 20 additions & 51 deletions src/ChartBar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
import React, { ReactElement, useEffect, useState } from 'react';
import {
Bar,
BarChart,
Brush,
Cell,
Legend,
ReferenceLine,
ResponsiveContainer,
Tooltip,
XAxis,
YAxis,
} from 'recharts';
import { Bar, BarChart, Brush, Cell, ResponsiveContainer, XAxis, YAxis } from 'recharts';
import { Color, Flex } from '@tremor/react';
import { twMerge } from 'tailwind-merge';
import objectHash from 'object-hash';
import { constructCategoryColors } from '@tremor/react/dist/components/chart-elements/common/utils';
import { colorPalette, themeColorRange } from '@tremor/react/dist/lib/theme';
import ChartTooltip from '@tremor/react/dist/components/chart-elements/common/ChartTooltip';
import { getColorClassNames } from '@tremor/react/dist/lib/utils';
import { BaseColors } from '@tremor/react/dist/lib/constants';
import ChartLegend from '@tremor/react/dist/components/chart-elements/common/ChartLegend';
import { ChartComponent, LegendFormatType } from '../constants';
import { NoData } from '../NoData';
import { formatTicks, getValueFormatted } from '../utils';
import { formatTicks } from '../utils';
import { ChartBarShimmer } from '../ChartShimmers';
import { ChartDecorators } from '../ChartCommon';
import { tremorTwMerge } from '@tremor/react/dist/lib/tremorTwMerge';

type XAxisPrimaryFormatter = {
(input: string): string;
Expand Down Expand Up @@ -96,8 +85,7 @@ export const ChartBar = <T,>({
{dataStore.length > 0 ? (
<ResponsiveContainer>
<BarChart data={dataStore} maxBarSize={barSize} onClick={onClickEvent}>
{xAxis && !multiXAxis && <XAxis dataKey='name' />}
{xAxis && multiXAxis && <XAxis dataKey='name' tickFormatter={multiXAxis.primary} />}
{xAxis && <XAxis dataKey='name' tickFormatter={multiXAxis?.primary} />}
{xAxis && multiXAxis && (
<XAxis
dataKey='name'
Expand All @@ -117,42 +105,23 @@ export const ChartBar = <T,>({
unit={unit}
allowDecimals={false}
width={70}
/>
{refLineY && (
<ReferenceLine
y={refLineY.value}
label={{
position: 'insideTopRight',
value: refLineY.label,
fontSize: 11,
offset: 7,
}}
stroke={refLineY.color}
/>
)}
<Tooltip
wrapperStyle={{ outline: 'none' }}
isAnimationActive={false}
cursor={{ stroke: '#d1d5db', strokeWidth: 1 }}
content={({ active, payload, label }) => (
<ChartTooltip
active={active}
payload={payload}
label={label as string}
valueFormatter={(value: number) => getValueFormatted(value, legendFormatType)}
categoryColors={categoryColors}
/>
className={tremorTwMerge(
// common
'text-tremor-label',
// light
'fill-tremor-content',
// dark
'dark:fill-dark-tremor-content',
)}
/>
{legend && (
<Legend
iconType='circle'
height={legendHeight}
content={({ payload }) =>
ChartLegend({ payload }, categoryColors, setLegendHeight, undefined, undefined)
}
/>
)}
{ChartDecorators({
refLineY,
legendFormatType,
categoryColors,
legend,
legendHeight,
setLegendHeight,
})}
{keys.map((property) =>
stacked ? (
<Bar
Expand Down
62 changes: 11 additions & 51 deletions src/DataChart/index.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
import React, { useEffect, useState } from 'react';
import {
CartesianGrid,
Legend,
Line,
LineChart,
ReferenceLine,
ResponsiveContainer,
Tooltip,
XAxis,
YAxis,
} from 'recharts';
import { CartesianGrid, Line, LineChart, ResponsiveContainer, XAxis, YAxis } from 'recharts';
import { Flex } from '@tremor/react';
import { twMerge } from 'tailwind-merge';
import ChartTooltip from '@tremor/react/dist/components/chart-elements/common/ChartTooltip';
import { constructCategoryColors } from '@tremor/react/dist/components/chart-elements/common/utils';
import { colorPalette, themeColorRange } from '@tremor/react/dist/lib/theme';
import ChartLegend from '@tremor/react/dist/components/chart-elements/common/ChartLegend';
import { getColorClassNames } from '@tremor/react/dist/lib/utils';
import { tremorTwMerge } from '@tremor/react/dist/lib/tremorTwMerge';
import { ChartComponent } from '../constants';
import { NoData } from '../NoData';
import { formatTicks, getValueFormatted } from '../utils';
import { formatTicks } from '../utils';
import { ChartLineShimmer } from '../ChartShimmers';
import { ChartDecorators } from '../ChartCommon';

export type DataChartSettings<TDataIn> = ChartComponent<TDataIn, Record<string, unknown>[]> & {
legend?: boolean;
Expand Down Expand Up @@ -111,43 +100,14 @@ export const DataChart = <T,>({
'dark:fill-dark-tremor-content',
)}
/>
{refLineY && (
<ReferenceLine
y={refLineY.value}
label={{
position: 'insideTopRight',
value: refLineY.label,
fontSize: 11,
offset: 7,
}}
stroke={refLineY.color}
/>
)}
<Tooltip
wrapperStyle={{ outline: 'none' }}
isAnimationActive={false}
cursor={{ stroke: '#d1d5db', strokeWidth: 1 }}
content={({ active, payload, label }) => (
<ChartTooltip
active={active}
payload={payload}
label={label as string}
valueFormatter={(value: number) => getValueFormatted(value, legendFormatType)}
categoryColors={categoryColors}
/>
)}
position={{ y: 0 }}
/>
{legend && (
<Legend
iconType='circle'
verticalAlign='top'
height={legendHeight}
content={({ payload }) =>
ChartLegend({ payload }, categoryColors, setLegendHeight, undefined, undefined)
}
/>
)}
{ChartDecorators({
refLineY,
legendFormatType,
categoryColors,
legend,
legendHeight,
setLegendHeight,
})}
{getChartSeries(dataStore).map((property: string, index: number) => (
<Line
className={getColorClassNames(colors[index], colorPalette.text).strokeColor}
Expand Down

0 comments on commit af583b8

Please sign in to comment.