Skip to content

Commit 8a4e987

Browse files
committed
front: migrate chartHelpers files to ts
1 parent fce88db commit 8a4e987

File tree

10 files changed

+176
-288
lines changed

10 files changed

+176
-288
lines changed

front/src/applications/operationalStudies/consts.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
PowerRestrictionRangeItem,
1515
} from 'common/api/osrdEditoastApi';
1616
import { LinearMetadataItem } from 'common/IntervalsDataViz/types';
17+
import { HeightPosition } from 'reducers/osrdsimulation/types';
1718

1819
export const BLOCKTYPES = [
1920
{
@@ -217,7 +218,10 @@ interface Profile {
217218
isStriped: boolean;
218219
}
219220

220-
interface ElectricalConditionSegment {
221+
export const DRAWING_KEYS: (keyof HeightPosition)[] = ['position', 'height'];
222+
export type DrawingKeys = typeof DRAWING_KEYS;
223+
224+
export interface ElectricalConditionSegment {
221225
position_start: number;
222226
position_end: number;
223227
position_middle: number;
@@ -376,7 +380,7 @@ export const createProfileSegment = (
376380
return segment;
377381
};
378382

379-
interface PowerRestrictionSegment {
383+
export interface PowerRestrictionSegment {
380384
position_start: number;
381385
position_end: number;
382386
position_middle: number;

front/src/modules/simulationResult/components/ChartHelpers/drawCurve.jsx

-41
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import * as d3 from 'd3';
2+
import { Chart, ConsolidatedPosition } from 'reducers/osrdsimulation/types';
3+
import { ArrayElement, ArrayElementKeys } from 'utils/types';
4+
import { GevPreparedata } from '../SpeedSpaceChart/prepareData';
5+
6+
const drawCurve = <
7+
T extends ArrayElement<GevPreparedata[keyof GevPreparedata]> | ConsolidatedPosition
8+
>(
9+
chart: Chart,
10+
classes: string,
11+
dataSimulation: T[],
12+
groupID: string,
13+
interpolation: string,
14+
keyValues: ArrayElementKeys<T[]>[],
15+
name: string,
16+
rotate: boolean,
17+
isSelected = true
18+
) => {
19+
const drawZone = chart.drawZone.select(`#${groupID}`);
20+
21+
drawZone
22+
.append('path')
23+
.attr('class', `line zoomable ${classes}`)
24+
.datum(dataSimulation)
25+
.attr('fill', 'none')
26+
.attr('stroke-width', 1)
27+
.attr(
28+
'd',
29+
d3
30+
.line<T>()
31+
.x((d) => chart.x((rotate ? d[keyValues[1]] : d[keyValues[0]]) as number))
32+
.y((d) => chart.y((rotate ? d[keyValues[0]] : d[keyValues[1]]) as number))
33+
.curve(d3[interpolation as keyof d3.CurveFactory])
34+
);
35+
36+
if (isSelected) {
37+
drawZone
38+
.append('circle')
39+
.attr('class', `pointer ${classes}`)
40+
.attr('id', `pointer-${name}`)
41+
.attr('transform', 'translate(-0.5,0)')
42+
.attr('r', 3)
43+
.style('opacity', 0);
44+
}
45+
};
46+
47+
export default drawCurve;

0 commit comments

Comments
 (0)