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

WIP: Add jsdoc and import type #423

Open
wants to merge 2 commits 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
42 changes: 34 additions & 8 deletions src/lib/charts/styles.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as CSS from 'csstype'
import { SymbolOptions } from '@deltares/fews-web-oc-charts'
import type { SvgPropertiesHyphen } from 'csstype'
import type { SymbolOptions } from '@deltares/fews-web-oc-charts'

const SymbolType = {
Circle: 0,
Expand All @@ -13,11 +13,16 @@ const SymbolType = {

type SymbolType = (typeof SymbolType)[keyof typeof SymbolType]

/**
* Converts FEWS line style and color to CSS style properties for SVG elements.
* @param item - An object containing lineStyle and color properties.
* @returns An object containing CSS style properties for SVG elements.
*/
export function cssStyleFromFewsLine(item: {
lineStyle?: string
color?: string
}): CSS.SvgPropertiesHyphen {
const style: CSS.SvgPropertiesHyphen = {}
}): SvgPropertiesHyphen {
const style: SvgPropertiesHyphen = {}

style['fill'] = 'none'

Expand All @@ -42,22 +47,43 @@ export function cssStyleFromFewsLine(item: {
style['stroke-linecap'] = 'round'
break
}
style.stroke = item.color === '#000000' ? 'currentColor' : item.color
style.stroke = colorFromFewsColor(item.color)
return style
}

/**
* Returns the input color if it is not equal to '#000000', otherwise returns 'currentColor'.
* @param color - The input color to be checked.
* @returns css color.
*/
export function colorFromFewsColor<T = string | undefined>(color: T): T {
const currentColor = 'currentColor' as T
return color === '#000000' ? currentColor : color
}

/**
* Returns a CSS style object for a FEWS marker.
* @param item An object containing the marker style and color.
* @returns A CSS style object with stroke and fill properties set to the specified color.
*/
export function cssStyleFromFewsMarker(item: {
markerStyle?: string
color?: string
}): CSS.SvgPropertiesHyphen {
const color = item.color === '#000000' ? 'currentColor' : item.color
const style: CSS.SvgPropertiesHyphen = {
}): SvgPropertiesHyphen {
const color = colorFromFewsColor(item.color)
const style: SvgPropertiesHyphen = {
stroke: color,
fill: color,
}
return style
}

/**
* Returns a SymbolOptions object for a chart marker based on the given style and point size.
* @param style - The style of the chart marker.
* @param pointSize - The size of the chart marker.
* @returns A SymbolOptions object for the chart marker.
*/
export function chartMarkerFromFews(
style: string,
pointSize: number = 3,
Expand Down
7 changes: 5 additions & 2 deletions src/lib/charts/timeSeriesDisplayToChartConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
cssStyleFromFewsLine,
cssStyleFromFewsMarker,
chartMarkerFromFews,
} from './styles'
colorFromFewsColor,
} from './styles.js'
import {
AxisOptions,
AxisPosition,
Expand Down Expand Up @@ -51,7 +52,9 @@ export function timeSeriesDisplayToChartConfig(
config.yAxis?.findIndex((yAxis) => {
return yAxis.position === item.yAxis?.axisPosition
}) ?? 0,
color: threshold.color ?? item.color,
color:
colorFromFewsColor(threshold.color) ??
colorFromFewsColor(item.color),
})
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/lib/charts/types/ChartSeries.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as CSS from 'csstype'
import { SymbolOptions } from '@deltares/fews-web-oc-charts'
import { ChartSeriesOptions } from './ChartSeriesOptions'
import type { SvgPropertiesHyphen } from 'csstype'
import type { SymbolOptions } from '@deltares/fews-web-oc-charts'
import type { ChartSeriesOptions } from './ChartSeriesOptions'

export interface ChartSeries {
id: string
Expand All @@ -14,5 +14,5 @@ export interface ChartSeries {
type: string
options: ChartSeriesOptions
unit: string
style: CSS.SvgPropertiesHyphen
style: SvgPropertiesHyphen
}
Loading