I am using hill-chart with SvelteKit on minb.
Initially the Hill Chart works fine, but when I save the x and y coordinates to the database and then refresh the page, the y coordinate seems to be capped to about half of the height.
I tried:
- different width x height combos
- adding a width and height to the
<svg />
element before running hill.render()
- having a separate
id
(css selector, not to be confused with data point id) and target
for each Hill Chart as I'm rendering multiple of them per document
but none of them worked.
I understand this issue is not fully clear, I'll hopefully add a minimal reproduction once I'm done with exams.
In the meantime, I looked into the source code and found this:
normalizeData() {
this.data = this.data.map((point) => {
return {
id: point.id ? point.id : uId(),
color: point.color,
description: point.description,
link: point.link,
x: point.x ? point.x : 0,
y: point.y ? point.y : hillFn(point.x ? point.x : 0),
size: point.size ? point.size : 10,
};
});
}
Saving only the x coordinate to the database works as expected, because the y coordinate is derived from it.
I hope this workaround helps someone.
EDIT
- Create a SvelteKit project using
yarn create vite
-> Svelte
-> SvelteKit
-> Skeleton Project
cd
into the project directory.
- Run
yarn
, yarn add hill-chart
- Add this code to
src/routes/+page.svelte
:
<script lang="ts">
import { onMount } from "svelte";
import HillChart from "hill-chart";
const createHillChart = () => {
const hillChartData = [
{
color: "cyan",
title: "Title",
size: 10,
x: 50,
y: 50,
},
];
const hill = new HillChart(hillChartData);
hill.render();
hill.on("moved", (data: any) => {
console.log(data.x, data.y);
});
};
onMount(createHillChart);
</script>
<h1>Minimal Reproduction</h1>
<svg id="hill-chart" />
<style>
@import "hill-chart/dist/cjs/styles.css";
</style>
Expected Outcome
The item should be at 50, 50
like so:
Observed Outcome
The item is at (what appears to be) 50, 25
: