Skip to content

Commit

Permalink
mm
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesr66a committed Oct 8, 2024
1 parent 8f6ddba commit dbd9f91
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions apps/functional_chat/pages/api/functions/renderChart.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { NextApiRequest, NextApiResponse } from 'next';

// biome-ignore lint/complexity/noStaticOnlyClass: <explanation>
class Api {
static async spec(req: NextApiRequest, res: NextApiResponse) {
res.json({
Expand Down Expand Up @@ -31,8 +32,8 @@ class Api {
properties: {
label: { type: 'string' },
data: { type: 'array', items: { type: 'number' } },
backgroundColor: {
type: 'array',
backgroundColor: {
type: 'array',
items: { type: 'string' },
description: 'Array of colors for each data point'
},
Expand Down Expand Up @@ -110,13 +111,19 @@ class Api {
];

// Apply default styles if not provided
jsonObj.data.datasets = jsonObj.data.datasets.map((dataset: any, index: number) => ({
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
jsonObj.data.datasets = jsonObj.data.datasets.map((dataset: any, index: number) => ({
backgroundColor: defaultColors?.[index % defaultColors.length] || 'defaultColor', // Added optional chaining and fallback
borderColor: defaultColors?.[index % defaultColors.length]?.replace('0.8', '1') || 'defaultBorderColor', // Added optional chaining and fallback
borderWidth: 1,
...dataset
}));

console.log('dataset');
console.log(dataset);
console.log('jsonObj');
console.log(jsonObj);

// Add default options if not provided
jsonObj.options = {
responsive: true,
Expand Down

0 comments on commit dbd9f91

Please sign in to comment.