mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-31 00:16:47 +01:00
Dashboard chart fill (#6167)
This commit is contained in:
parent
5a75093cbc
commit
3e7c2bb30e
@ -19,14 +19,12 @@ export const FlagsChart: VFC<IFlagsChartProps> = ({ flagTrends }) => {
|
|||||||
data: flagTrends.map((item) => item.total),
|
data: flagTrends.map((item) => item.total),
|
||||||
borderColor: theme.palette.primary.light,
|
borderColor: theme.palette.primary.light,
|
||||||
backgroundColor: theme.palette.primary.light,
|
backgroundColor: theme.palette.primary.light,
|
||||||
fill: true,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Stale',
|
label: 'Stale',
|
||||||
data: flagTrends.map((item) => item.stale),
|
data: flagTrends.map((item) => item.stale),
|
||||||
borderColor: theme.palette.warning.border,
|
borderColor: theme.palette.warning.border,
|
||||||
backgroundColor: theme.palette.warning.border,
|
backgroundColor: theme.palette.warning.border,
|
||||||
fill: true,
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
|
@ -8,6 +8,7 @@ import {
|
|||||||
Legend,
|
Legend,
|
||||||
TimeScale,
|
TimeScale,
|
||||||
Chart,
|
Chart,
|
||||||
|
Filler,
|
||||||
type ChartData,
|
type ChartData,
|
||||||
type ScatterDataPoint,
|
type ScatterDataPoint,
|
||||||
} from 'chart.js';
|
} from 'chart.js';
|
||||||
@ -162,7 +163,8 @@ const customHighlightPlugin = {
|
|||||||
|
|
||||||
const LineChartComponent: VFC<{
|
const LineChartComponent: VFC<{
|
||||||
data: ChartData<'line', (number | ScatterDataPoint | null)[], unknown>;
|
data: ChartData<'line', (number | ScatterDataPoint | null)[], unknown>;
|
||||||
}> = ({ data }) => {
|
aspectRatio?: number;
|
||||||
|
}> = ({ data, aspectRatio }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { locationSettings } = useLocationSettings();
|
const { locationSettings } = useLocationSettings();
|
||||||
|
|
||||||
@ -178,6 +180,8 @@ const LineChartComponent: VFC<{
|
|||||||
options={options}
|
options={options}
|
||||||
data={data}
|
data={data}
|
||||||
plugins={[customHighlightPlugin]}
|
plugins={[customHighlightPlugin]}
|
||||||
|
height={aspectRatio ? 100 : undefined}
|
||||||
|
width={aspectRatio ? 100 * aspectRatio : undefined}
|
||||||
/>
|
/>
|
||||||
<ChartTooltip tooltip={tooltip} />
|
<ChartTooltip tooltip={tooltip} />
|
||||||
</>
|
</>
|
||||||
@ -192,6 +196,7 @@ Chart.register(
|
|||||||
TimeScale,
|
TimeScale,
|
||||||
Tooltip,
|
Tooltip,
|
||||||
Legend,
|
Legend,
|
||||||
|
Filler,
|
||||||
);
|
);
|
||||||
|
|
||||||
// for lazy-loading
|
// for lazy-loading
|
||||||
|
@ -3,6 +3,7 @@ import 'chartjs-adapter-date-fns';
|
|||||||
import { useTheme } from '@mui/material';
|
import { useTheme } from '@mui/material';
|
||||||
import { ExecutiveSummarySchema } from 'openapi';
|
import { ExecutiveSummarySchema } from 'openapi';
|
||||||
import { LineChart } from '../LineChart/LineChart';
|
import { LineChart } from '../LineChart/LineChart';
|
||||||
|
import { type ScriptableContext } from 'chart.js';
|
||||||
|
|
||||||
interface IUsersChartProps {
|
interface IUsersChartProps {
|
||||||
userTrends: ExecutiveSummarySchema['userTrends'];
|
userTrends: ExecutiveSummarySchema['userTrends'];
|
||||||
@ -18,20 +19,38 @@ export const UsersChart: VFC<IUsersChartProps> = ({ userTrends }) => {
|
|||||||
label: 'Total users',
|
label: 'Total users',
|
||||||
data: userTrends.map((item) => item.total),
|
data: userTrends.map((item) => item.total),
|
||||||
borderColor: theme.palette.primary.light,
|
borderColor: theme.palette.primary.light,
|
||||||
backgroundColor: theme.palette.primary.light,
|
backgroundColor: (context: ScriptableContext<'line'>) => {
|
||||||
|
const chart = context.chart;
|
||||||
|
const { ctx, chartArea } = chart;
|
||||||
|
if (!chartArea) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const gradient = ctx.createLinearGradient(
|
||||||
|
0,
|
||||||
|
chartArea.bottom,
|
||||||
|
0,
|
||||||
|
chartArea.top,
|
||||||
|
);
|
||||||
|
gradient.addColorStop(0, 'rgba(129, 122, 254, 0)');
|
||||||
|
gradient.addColorStop(1, 'rgba(129, 122, 254, 0.12)');
|
||||||
|
return gradient;
|
||||||
|
},
|
||||||
fill: true,
|
fill: true,
|
||||||
|
order: 3,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Active users',
|
label: 'Active users',
|
||||||
data: userTrends.map((item) => item.active),
|
data: userTrends.map((item) => item.active),
|
||||||
borderColor: theme.palette.success.border,
|
borderColor: theme.palette.success.border,
|
||||||
backgroundColor: theme.palette.success.border,
|
backgroundColor: theme.palette.success.border,
|
||||||
|
order: 2,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Inactive users',
|
label: 'Inactive users',
|
||||||
data: userTrends.map((item) => item.inactive),
|
data: userTrends.map((item) => item.inactive),
|
||||||
borderColor: theme.palette.warning.border,
|
borderColor: theme.palette.warning.border,
|
||||||
backgroundColor: theme.palette.warning.border,
|
backgroundColor: theme.palette.warning.border,
|
||||||
|
order: 1,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
|
Loading…
Reference in New Issue
Block a user