Skip to content

Commit ca80eea

Browse files
committed
WIP populate LinesWrapper
1 parent 451e8e8 commit ca80eea

File tree

3 files changed

+86
-23
lines changed

3 files changed

+86
-23
lines changed

src/lib/components/data-vis/line-chart/Line.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@
2121
pathFillColor = "none",
2222
pathStrokeDashArray = "none",
2323
areaFillColor,
24-
includeArea,
24+
includeArea = false,
2525
includeMarkers = false,
2626
markerShape = "circle",
2727
markerRadius = 5,
2828
markerFill = "grey",
2929
markerStroke = "white",
3030
markerStrokeWidth = 3,
3131
lineFunction,
32+
areaFunction,
3233
curveFunction,
3334
xFunction,
3435
lineEnding = null,
@@ -114,7 +115,6 @@
114115
{#if includeArea}
115116
<path d={areaFunction(dataArray)} fill={areaFillColor}></path>
116117
{/if}
117-
{console.log(tier)}
118118
<path
119119
d={lineFunction(dataArray)}
120120
fill="none"

src/lib/components/data-vis/line-chart/Lines.svelte

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
chartWidth,
1515
xFunction,
1616
yFunction,
17-
areaFunction,
1817
labelClicked = $bindable(),
1918
labelHovered = $bindable(),
2019
lineHovered = $bindable(),

src/wrappers/components/data-vis/line-chart/LinesWrapper.svelte

Lines changed: 84 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@
166166
line,
167167
area,
168168
} from "d3-shape";
169+
import { scaleLinear, scaleLog, scaleTime } from "d3-scale";
169170
170171
let { data } = $props();
171172
@@ -305,10 +306,84 @@
305306
category: "data",
306307
visible: false,
307308
},
309+
{
310+
name: "curveFunction",
311+
category: "lineFunction",
312+
isProp: true,
313+
options: [
314+
"curveLinear",
315+
"curveLinearClosed",
316+
"curveCardinal",
317+
"curveBasis",
318+
"curveStep",
319+
"curveMonotoneX",
320+
],
321+
},
308322
{
309323
name: "lineFunction",
310-
category: "data",
311-
visible: false,
324+
category: "lineFunction",
325+
isProp: true,
326+
functionElements: {
327+
functionAsString: `function (dataArray) {
328+
return line()
329+
.x((d) => xFunction(d.x))
330+
.y((d) => yFunction(d.y))
331+
.curve(
332+
{
333+
curveLinear: curveLinear,
334+
curveLinearClosed: curveLinearClosed,
335+
curveCardinal: curveCardinal,
336+
curveBasis: curveBasis,
337+
curveStep: curveStep,
338+
curveMonotoneX: curveMonotoneX,
339+
}[getValue("curveFunction")],
340+
)(dataArray);
341+
});`,
342+
},
343+
},
344+
{
345+
name: "yDomainLowerBound",
346+
category: "yScale",
347+
isProp: false,
348+
value: Math.min(
349+
...data.dataInFormatForLineChart[0].lines
350+
.map((el) => el.data)
351+
.flat()
352+
.map((el) => el.y),
353+
),
354+
},
355+
{
356+
name: "yDomainUpperBound",
357+
category: "yScale",
358+
isProp: false,
359+
value: Math.max(
360+
...data.dataInFormatForLineChart[0].lines
361+
.map((el) => el.data)
362+
.flat()
363+
.map((el) => el.y),
364+
),
365+
},
366+
{
367+
name: "xDomainLowerBound",
368+
category: "xScale",
369+
isProp: false,
370+
value: Math.min(
371+
...data.dataInFormatForLineChart[0].lines
372+
.map((el) => el.data)
373+
.flat()
374+
.map((el) => el.x),
375+
),
376+
},
377+
{
378+
name: "xDomainUpperBound",
379+
category: "xScale",
380+
isProp: false,
381+
value: Math.max(
382+
...data.dataInFormatForLineChart[0].lines
383+
.map((el) => el.data)
384+
.flat()
385+
.map((el) => el.x),
386+
),
312387
},
313388
]),
314389
);
@@ -456,22 +531,13 @@
456531
)(dataArray);
457532
});
458533
459-
let areaFunction = $derived(
460-
area()
461-
.y0((d) => yFunction(0))
462-
.x((d) => xFunction(d.x))
463-
.y1((d) => yFunction(d.y))
464-
.curve(curveLinear),
465-
);
466-
467534
let basicLineParams = $derived({
468-
lineFunction: lineFunction,
469-
xFunction: xFunction,
470-
yFunction: yFunction,
471-
areaFunction: areaFunction,
472-
onClick: onClick,
473-
onMouseEnter: onMouseEnter,
474-
onMouseLeave: onMouseLeave,
535+
lineFunction: getValue(lineFunction),
536+
xFunction: getValue(xFunction),
537+
yFunction: getValue(yFunction),
538+
onClick: getValue(onClick),
539+
onMouseEnter: getValue(onMouseEnter),
540+
onMouseLeave: getValue(onMouseLeave),
475541
invisibleStrokeWidth: 20,
476542
});
477543
@@ -540,12 +606,12 @@
540606
541607
let derivedParametersObject = $derived({
542608
derivedDataArray,
609+
lineFunction,
543610
dataArray,
544611
tieredLineParams,
545612
defaultLineParams,
546613
tieredDataObject,
547614
globalTierRules,
548-
lineFunction,
549615
});
550616
551617
/**
@@ -579,8 +645,6 @@
579645
),
580646
);
581647
582-
$inspect(parametersObject);
583-
584648
let parametersParsingErrorsObject = $state({});
585649
586650
$effect(() => {

0 commit comments

Comments
 (0)