svelte-tiny-linked-charts 1.4.2 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -22,9 +22,7 @@ npm install svelte-tiny-linked-charts --save-dev
22
22
 
23
23
  Include the chart in your app.
24
24
  ```js
25
- import LinkedChart from "svelte-tiny-linked-charts"
26
- import LinkedLabel from "svelte-tiny-linked-charts"
27
- import LinkedValue from "svelte-tiny-linked-charts"
25
+ import { LinkedChart, LinkedLabel, LinkedValue } from "svelte-tiny-linked-charts"
28
26
  ```
29
27
  ```svelte
30
28
  <LinkedChart />
@@ -100,6 +98,7 @@ valuePrepend | | String to prepend the value.
100
98
  valueAppend | | String to append to the value.
101
99
  valuePosition | static | Can be set to "floating" to follow the position of the hover.
102
100
  scaleMax | 0 | Use this to overwrite the automatic scale set to the highest value in your array.
101
+ scaleMax | 0 | Use this to overwrite the default value floor of 0.
103
102
  type | bar | Can be set to "line" to display a line chart instead.
104
103
  lineColor | fill | Color of the line if used with type="line".
105
104
  tabindex | -1 | Sets the tabindex of each bar.
@@ -26,6 +26,7 @@
26
26
  export let valuePosition = "static"
27
27
  export let valueUndefined = 0
28
28
  export let scaleMax = 0
29
+ export let scaleMin = 0
29
30
  export let type = "bar"
30
31
  export let lineColor = fill
31
32
  export let tabindex = -1
@@ -58,8 +59,13 @@
58
59
  }
59
60
 
60
61
  function getHeight(value) {
61
- if (value < hideBarBelow) return 0
62
- return Math.max(Math.ceil((parseInt(height) / highestValue) * value - (type == "line" ? barWidth / 2 : 0)) || 0, barMinHeight)
62
+ if (value < hideBarBelow || value < scaleMin) return 0
63
+
64
+ const maxValue = scaleMax || highestValue
65
+ const minValue = scaleMin || 0
66
+
67
+ const scaledValue = (value - minValue) / (maxValue - minValue)
68
+ return Math.max(Math.ceil(scaledValue * parseInt(height)), barMinHeight)
63
69
  }
64
70
 
65
71
  function getBarWidth() {
@@ -27,6 +27,7 @@ export default class LinkedChart extends SvelteComponent<{
27
27
  valuePosition?: string;
28
28
  valueUndefined?: number;
29
29
  scaleMax?: number;
30
+ scaleMin?: number;
30
31
  type?: string;
31
32
  lineColor?: string;
32
33
  tabindex?: number;
@@ -72,6 +73,7 @@ declare const __propDef: {
72
73
  valuePosition?: string;
73
74
  valueUndefined?: number;
74
75
  scaleMax?: number;
76
+ scaleMin?: number;
75
77
  type?: string;
76
78
  lineColor?: string;
77
79
  tabindex?: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-tiny-linked-charts",
3
- "version": "1.4.2",
3
+ "version": "1.5.0",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run package",