Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Limited the data item size to labels length if available #350

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions packages/lib/src/composables/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,20 @@ import { ContainerSize } from '@/types/size';
import { Options } from './options';
import { warn, Warnings } from '@/utils/warnings';

function computeValues(values: Array<DatasetValue<number>>) {
return values.map((value) => {
function skipNonRenderableDataItems(
dataItems: Array<DatasetValue<number>>,
numberOfLabels: number
) {
return numberOfLabels > 0 && dataItems.length > numberOfLabels
? dataItems.slice(0, numberOfLabels)
: dataItems;
}

function computeValues(
values: Array<DatasetValue<number>>,
numberOfLabels: number
) {
return skipNonRenderableDataItems(values, numberOfLabels).map((value) => {
// If value is not a DatasetValueObject, convert it into one
return isDatasetValueObject(value)
? value
Expand Down Expand Up @@ -91,7 +103,10 @@ export function useBase(
// Prevent re-computing internal datasets
if (isInternalDataset(dataset)) return dataset;

const _values = computeValues(dataset.values);
const _values = computeValues(
dataset.values,
labels?.value?.length ?? 0
);
const _color = computeColor(
dataset.color,
color?.value,
Expand Down
25 changes: 20 additions & 5 deletions packages/lib/src/docs/storybook-data/base-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const DATASETS = {
data: [
{
values: [
60, 80, 70, 30, 60, 90, 120, 220, 170, 190, 150, 80, 100, 125, 70,
60, 80, 70, 30, 60, 90, 120, 220, 170, 190, 150, 80, 100, 125, 70, 90,
],
label: 'Dogs',
},
Expand Down Expand Up @@ -45,7 +45,7 @@ const DATASETS = {
},
{
label: 'Dogs',
values: [5000, 8000, 2000, 4000],
values: [5000, 8000, 2000, 4000, 5000, 10000, 1000000],
},
{
label: 'Horses',
Expand All @@ -72,7 +72,7 @@ const DATASETS = {
},
{
label: 'Dogs',
values: [30, 20, 10, 25],
values: [30, 20, 10, 25, 50, 56],
},
{
label: 'Birds',
Expand Down Expand Up @@ -141,7 +141,22 @@ const DATASETS = {
CatsMetIn2023: {
data: [
{
values: [15, 25, 30, null, 40, 50, 60, 12, 30, 12, 344, 400],
values: [
15,
25,
30,
null,
40,
50,
60,
12,
30,
12,
344,
400,
3440,
4001,
],
label: 'Cats',
},
],
Expand All @@ -163,7 +178,7 @@ const DATASETS = {
AnimalsMetIn2023: {
data: [
{
values: [15, 25, 30, null, 40, 50, 60, 12, 30],
values: [15, 25, 30, null, 40, 50, 60, 12, 30, 50, 60, 80, 199],
label: 'Cats',
},
{
Expand Down
Loading