Skip to content

feat: Support threshold gradients#4

Merged
niklavsBariss merged 4 commits intomasterfrom
develop
Oct 8, 2025
Merged

feat: Support threshold gradients#4
niklavsBariss merged 4 commits intomasterfrom
develop

Conversation

@niklavsBariss
Copy link
Copy Markdown
Member

In this PR I've added support for thresholds and multi-color-gradient

Screen_recording_20251006_084549.mp4

Video also contains area gradient behaviour with negative values. Have to decide what to do with that

Copy link
Copy Markdown
Collaborator

@janisievins janisievins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Pāris ieteikumi/komentāri no malas

Comment thread README.md Outdated
Comment thread README.md Outdated
Comment thread README.md Outdated
Comment thread README.md Outdated
Comment thread src/drawFunction.js
Comment on lines +136 to +149
function getDatasetColor(dataset, value) {
if (dataset.color.type === 'thresholds') {
const crossedThreshold = dataset.color.thresholds.find(
(threshold) => value >= threshold.value
)

if (crossedThreshold) {
return crossedThreshold.color
}

return dataset.color.baseColor
}
return dataset.color
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ja pareizi saprotu, dataset.color.type šobrīd var būt undefined vai 'thresholds'? Varētu būt vēl kaut kas uz nākotni? Domāju, varbūt switch labāk izmantot un katru case tad var nokomentēt/nodokumentēt.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export type Dataset = {
  measurementName: string
  color:
    | string
    | {
        type: 'thresholds'
        baseColor: string
        /**
         * Must be sorted by value descending (highest value first)
         */
        thresholds: { value: number; color: string }[]
        /**
         * Gradient transition distance around thresholds.
         * Must be non-negative. Should be less than half the distance between thresholds.
         * @default 0 - no blur
         */
        gradientBlur?: number
      }

Šobrīd nav paredzēti citi tipi

Comment thread src/drawFunction.js Outdated
Comment thread src/drawFunction.js Outdated
Comment thread src/drawFunction.js Outdated
Comment thread src/types.ts Outdated
@niklavsBariss niklavsBariss merged commit b7b21b0 into master Oct 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants