-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Improve styling of the charts as well as the (#43)
## Before <img width="1629" alt="Screenshot 2024-04-28 at 16 25 23" src="https://github.com/flxdot/carlos/assets/35657654/d341cde2-6b3d-4d9d-94a1-e24ca717d716"> ## After <img width="1549" alt="Screenshot 2024-04-28 at 16 02 52" src="https://github.com/flxdot/carlos/assets/35657654/aef766f5-a27f-466b-9148-1dde7017b794">
- Loading branch information
Showing
21 changed files
with
1,782 additions
and
536 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<component name="ProjectRunConfigurationManager"> | ||
<configuration default="false" name="frontend > test:unit:watch" type="js.build_tools.npm"> | ||
<package-json value="$PROJECT_DIR$/services/frontend/package.json" /> | ||
<command value="run" /> | ||
<scripts> | ||
<script value="test:unit:watch" /> | ||
</scripts> | ||
<node-interpreter value="project" /> | ||
<envs /> | ||
<method v="2" /> | ||
</configuration> | ||
</component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
services/frontend/src/components/charts/chart-analog.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<template> | ||
<chart-base-line | ||
:chart-data="chartData" | ||
:y-axes="yAxes" | ||
:height="props.height" | ||
:show-x-ticks="props.showXTicks" | ||
/> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { | ||
defineProps, | ||
withDefaults, | ||
computed, | ||
ref, | ||
} from 'vue'; | ||
import ChartBaseLine from '@/components/charts/chart-base-line.vue'; | ||
import { | ||
TAxisLimit, | ||
TLineAxisProps, | ||
TLineChartData, | ||
} from '@/components/charts/chart-types.ts'; | ||
import { | ||
chartJsGradient, | ||
getSuitableLimit, | ||
buildAxis, | ||
} from '@/components/charts/chart-utils.ts'; | ||
import { | ||
colorToColorStop, DiscreteGradientDefinition, | ||
GradientCache, GradientDefinition, | ||
} from '@/components/charts/gradients.ts'; | ||
import { | ||
tempEmojis, | ||
} from '@/utils/value-render.ts'; | ||
import { | ||
LineWidth, | ||
} from '@/components/charts/constants.ts'; | ||
import { | ||
DeepPartial, | ||
} from '@/utils/types.ts'; | ||
import { | ||
ITimeseries, toChartJsData, | ||
} from '@/components/charts/timeseries.ts'; | ||
interface IChartAnalogProps { | ||
timeseries: ITimeseries; | ||
limits: TAxisLimit; | ||
ticks: number[]; | ||
color: string | GradientDefinition | DiscreteGradientDefinition; | ||
height?: string; | ||
tickStepSize?: number; | ||
showXTicks?: boolean; | ||
} | ||
const props = withDefaults(defineProps<IChartAnalogProps>(), { | ||
height: '10rem', | ||
tickStepSize: 5, | ||
showXTicks: true, | ||
}); | ||
const lineGradient = ref<GradientCache>({ | ||
chartWidth: undefined, | ||
chartHeight: undefined, | ||
gradient: undefined, | ||
}); | ||
const LineBgGradient = ref<GradientCache>({ | ||
chartWidth: undefined, | ||
chartHeight: undefined, | ||
gradient: undefined, | ||
}); | ||
const actualLimits = computed<TAxisLimit>( | ||
() => getSuitableLimit(props.limits, props.timeseries.values, props.tickStepSize), | ||
); | ||
const chartData = computed<DeepPartial<TLineChartData>>(() => { | ||
let gradient: GradientDefinition | DiscreteGradientDefinition; | ||
if (typeof props.color === 'string') { | ||
gradient = colorToColorStop(props.color); | ||
} else { | ||
gradient = props.color; | ||
} | ||
const borderColor = chartJsGradient(lineGradient.value, gradient, actualLimits.value); | ||
const backgroundColor = chartJsGradient(LineBgGradient.value, gradient, actualLimits.value, true); | ||
return { | ||
datasets: [ | ||
{ | ||
label: 'Temperature', | ||
data: toChartJsData(props.timeseries), | ||
borderWidth: LineWidth, | ||
borderColor, | ||
backgroundColor, | ||
fill: true, | ||
pointStyle: false, | ||
yAxisID: props.timeseries.displayName, | ||
// The tension helps to smooth the line in case of oversampling | ||
tension: 0.1, | ||
}, | ||
], | ||
} as DeepPartial<TLineChartData>; | ||
}); | ||
const yAxes = computed<TLineAxisProps>(() => { | ||
return { | ||
[props.timeseries.displayName]: buildAxis( | ||
'right', | ||
props.timeseries, | ||
actualLimits.value, | ||
props.ticks, | ||
tempEmojis, | ||
), | ||
} as TLineAxisProps; | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.