@kws3/ui 1.4.7 → 1.5.6
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/buttons/ConfirmButton.svelte +2 -0
- package/charts/AreaChart.svelte +144 -0
- package/charts/BarChart.svelte +166 -0
- package/charts/Chart.svelte +122 -0
- package/charts/DonutChart.svelte +85 -0
- package/charts/LineChart.svelte +144 -0
- package/charts/MixedChart.svelte +201 -0
- package/charts/PieChart.svelte +86 -0
- package/charts/RadialChart.svelte +117 -0
- package/charts/utils.js +213 -0
- package/controls/Checkbox.svelte +1 -1
- package/controls/NumberInput.svelte +3 -0
- package/forms/select/MultiSelect.svelte +2 -0
- package/helpers/Nl2br.svelte +1 -1
- package/index.js +13 -6
- package/package.json +3 -2
- package/settings.js +11 -0
- package/styles/Chart.scss +42 -0
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
<p class="control">
|
|
29
29
|
{#if _confirm}
|
|
30
30
|
<button
|
|
31
|
+
role="button"
|
|
31
32
|
class="button is-success is-light is-shadowless is-{size} {button_class}"
|
|
32
33
|
type="button"
|
|
33
34
|
on:click|preventDefault|stopPropagation={cancel}>
|
|
@@ -37,6 +38,7 @@
|
|
|
37
38
|
</p>
|
|
38
39
|
<p class="control is-expanded">
|
|
39
40
|
<button
|
|
41
|
+
role="button"
|
|
40
42
|
class="button is-{size} {_doing
|
|
41
43
|
? main_color + ' is-loading'
|
|
42
44
|
: _error
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
@param {object} [options={}] - Chart options, see ApexCharts options for bar charts, Default: `{}`
|
|
6
|
+
@param {array} [labels=[]] - Data labels, Default: `[]`
|
|
7
|
+
@param {array} [sets=[]] - Data sets, Default: `[]`
|
|
8
|
+
@param {array} [data=[]] - Chart data, Default: `[]`
|
|
9
|
+
@param {boolean} [sparklines=false] - Displays the chart as a sparkline chart.
|
|
10
|
+
These are charts with minimal UI and can be
|
|
11
|
+
squeezed into small spaces, Default: `false`
|
|
12
|
+
@param {object} [y_axis_options={}] - Y Axis options, see ApexCharts options for Y Axis, Default: `{}`
|
|
13
|
+
@param {string} [width="100%"] - Chart width, supports CSS size strings, Default: `"100%"`
|
|
14
|
+
@param {string} [height="auto"] - Chart height, supports CSS size strings, Default: `"auto"`
|
|
15
|
+
@param {array} [colors=null] - Chart colors, can be modified globally in framework settings
|
|
16
|
+
|
|
17
|
+
Send an array of colors to override the default colors, or do not send anything to use the default colors, Default: `null`
|
|
18
|
+
@param {string} [class=""] - CSS classes for container, Default: `""`
|
|
19
|
+
|
|
20
|
+
-->
|
|
21
|
+
<Chart
|
|
22
|
+
class={__class}
|
|
23
|
+
options={_options}
|
|
24
|
+
series={_data}
|
|
25
|
+
type="area"
|
|
26
|
+
{height}
|
|
27
|
+
{width} />
|
|
28
|
+
|
|
29
|
+
<script>
|
|
30
|
+
import { Chart } from "@kws3/ui";
|
|
31
|
+
import { areaChartOptions, merge } from "./utils";
|
|
32
|
+
import { defaultChartColors } from "../settings";
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Chart options, see ApexCharts options for bar charts
|
|
36
|
+
*/
|
|
37
|
+
export let options = {},
|
|
38
|
+
/**
|
|
39
|
+
* Data labels
|
|
40
|
+
*/
|
|
41
|
+
labels = [],
|
|
42
|
+
/**
|
|
43
|
+
* Data sets
|
|
44
|
+
*/
|
|
45
|
+
sets = [],
|
|
46
|
+
/**
|
|
47
|
+
* Chart data
|
|
48
|
+
*/
|
|
49
|
+
data = [],
|
|
50
|
+
/**
|
|
51
|
+
* Displays the chart as a sparkline chart.
|
|
52
|
+
* These are charts with minimal UI and can be
|
|
53
|
+
* squeezed into small spaces
|
|
54
|
+
*/
|
|
55
|
+
sparklines = false,
|
|
56
|
+
/**
|
|
57
|
+
* Y Axis options, see ApexCharts options for Y Axis
|
|
58
|
+
*/
|
|
59
|
+
y_axis_options = {},
|
|
60
|
+
/**
|
|
61
|
+
* Chart width, supports CSS size strings
|
|
62
|
+
*/
|
|
63
|
+
width = "100%",
|
|
64
|
+
/**
|
|
65
|
+
* Chart height, supports CSS size strings
|
|
66
|
+
*/
|
|
67
|
+
height = "auto",
|
|
68
|
+
/**
|
|
69
|
+
* Chart colors, can be modified globally in framework settings
|
|
70
|
+
*
|
|
71
|
+
* Send an array of colors to override the default colors, or do not send anything to use the default colors
|
|
72
|
+
* @type {array}
|
|
73
|
+
*/
|
|
74
|
+
colors = null;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* CSS classes for container
|
|
78
|
+
*/
|
|
79
|
+
let klass = "";
|
|
80
|
+
export { klass as class };
|
|
81
|
+
|
|
82
|
+
$: __class =
|
|
83
|
+
"kws-area-chart " + `${sparklines ? "kws-sparklines" : ""} ` + klass;
|
|
84
|
+
|
|
85
|
+
let _data = [];
|
|
86
|
+
let yAxis = {};
|
|
87
|
+
|
|
88
|
+
$: usedColors = colors
|
|
89
|
+
? colors
|
|
90
|
+
: $defaultChartColors
|
|
91
|
+
? $defaultChartColors
|
|
92
|
+
: [];
|
|
93
|
+
|
|
94
|
+
$: data, sets, normaliseAll();
|
|
95
|
+
$: _options = merge(
|
|
96
|
+
areaChartOptions(labels, yAxis, sparklines),
|
|
97
|
+
Object.assign({}, { colors: usedColors }, options)
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
const normaliseAll = () => {
|
|
101
|
+
if (data.length !== sets.length) {
|
|
102
|
+
console.warn("Data and sets lengths do not match");
|
|
103
|
+
}
|
|
104
|
+
normaliseSets();
|
|
105
|
+
normaliseData();
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const normaliseSets = () => {
|
|
109
|
+
yAxis = merge(
|
|
110
|
+
{
|
|
111
|
+
floating: false,
|
|
112
|
+
opposite: false,
|
|
113
|
+
decimalsInFloat: 0,
|
|
114
|
+
axisBorder: {
|
|
115
|
+
show: true,
|
|
116
|
+
},
|
|
117
|
+
axisTicks: {
|
|
118
|
+
show: true,
|
|
119
|
+
},
|
|
120
|
+
labels: {
|
|
121
|
+
show: true,
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
y_axis_options
|
|
125
|
+
);
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const normaliseData = () => {
|
|
129
|
+
_data = [];
|
|
130
|
+
|
|
131
|
+
//ensuring data is an array of arrays
|
|
132
|
+
let sliced_data = (data || []).slice();
|
|
133
|
+
if (!Array.isArray(sliced_data[0])) {
|
|
134
|
+
sliced_data = [sliced_data];
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
sliced_data.forEach((set, idx) => {
|
|
138
|
+
_data.push({
|
|
139
|
+
name: sets[idx],
|
|
140
|
+
data: set,
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
</script>
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
@param {object} [options={}] - Chart options, see ApexCharts options for bar charts, Default: `{}`
|
|
6
|
+
@param {array} [labels=[]] - Data labels, Default: `[]`
|
|
7
|
+
@param {array} [sets=[]] - Data sets, Default: `[]`
|
|
8
|
+
@param {array} [data=[]] - Chart data, Default: `[]`
|
|
9
|
+
@param {boolean} [sparklines=false] - Displays the chart as a sparkline chart.
|
|
10
|
+
These are charts with minimal UI and can be
|
|
11
|
+
squeezed into small spaces, Default: `false`
|
|
12
|
+
@param {boolean} [horizontal=false] - Whether the chart displays horizontal bars, Default: `false`
|
|
13
|
+
@param {boolean} [stacked=false] - Whether the bars are stacked on top of each other, Default: `false`
|
|
14
|
+
@param {boolean} [stacked_full_width=false] - When bars are stacked, should they span the full width/height of the chart, Default: `false`
|
|
15
|
+
@param {object} [y_axis_options={}] - Y Axis options, see ApexCharts options for Y Axis, Default: `{}`
|
|
16
|
+
@param {string} [width="100%"] - Chart width, supports CSS size strings, Default: `"100%"`
|
|
17
|
+
@param {string} [height="auto"] - Chart height, supports CSS size strings, Default: `"auto"`
|
|
18
|
+
@param {array} [colors=null] - Chart colors, can be modified globally in framework settings
|
|
19
|
+
|
|
20
|
+
Send an array of colors to override the default colors, or do not send anything to use the default colors, Default: `null`
|
|
21
|
+
@param {string} [class=""] - CSS classes for container, Default: `""`
|
|
22
|
+
|
|
23
|
+
-->
|
|
24
|
+
<Chart
|
|
25
|
+
class={__class}
|
|
26
|
+
options={_options}
|
|
27
|
+
series={_data}
|
|
28
|
+
type="bar"
|
|
29
|
+
{height}
|
|
30
|
+
{width} />
|
|
31
|
+
|
|
32
|
+
<script>
|
|
33
|
+
import { Chart } from "@kws3/ui";
|
|
34
|
+
import { barChartOptions, merge } from "./utils";
|
|
35
|
+
import { defaultChartColors } from "../settings";
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Chart options, see ApexCharts options for bar charts
|
|
39
|
+
*/
|
|
40
|
+
export let options = {},
|
|
41
|
+
/**
|
|
42
|
+
* Data labels
|
|
43
|
+
*/
|
|
44
|
+
labels = [],
|
|
45
|
+
/**
|
|
46
|
+
* Data sets
|
|
47
|
+
*/
|
|
48
|
+
sets = [],
|
|
49
|
+
/**
|
|
50
|
+
* Chart data
|
|
51
|
+
*/
|
|
52
|
+
data = [],
|
|
53
|
+
/**
|
|
54
|
+
* Displays the chart as a sparkline chart.
|
|
55
|
+
* These are charts with minimal UI and can be
|
|
56
|
+
* squeezed into small spaces
|
|
57
|
+
*/
|
|
58
|
+
sparklines = false,
|
|
59
|
+
/**
|
|
60
|
+
* Whether the chart displays horizontal bars
|
|
61
|
+
*/
|
|
62
|
+
horizontal = false,
|
|
63
|
+
/**
|
|
64
|
+
* Whether the bars are stacked on top of each other
|
|
65
|
+
*/
|
|
66
|
+
stacked = false,
|
|
67
|
+
/**
|
|
68
|
+
* When bars are stacked, should they span the full width/height of the chart
|
|
69
|
+
*/
|
|
70
|
+
stacked_full_width = false,
|
|
71
|
+
/**
|
|
72
|
+
* Y Axis options, see ApexCharts options for Y Axis
|
|
73
|
+
*/
|
|
74
|
+
y_axis_options = {},
|
|
75
|
+
/**
|
|
76
|
+
* Chart width, supports CSS size strings
|
|
77
|
+
*/
|
|
78
|
+
width = "100%",
|
|
79
|
+
/**
|
|
80
|
+
* Chart height, supports CSS size strings
|
|
81
|
+
*/
|
|
82
|
+
height = "auto",
|
|
83
|
+
/**
|
|
84
|
+
* Chart colors, can be modified globally in framework settings
|
|
85
|
+
*
|
|
86
|
+
* Send an array of colors to override the default colors, or do not send anything to use the default colors
|
|
87
|
+
* @type {array}
|
|
88
|
+
*/
|
|
89
|
+
colors = null;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* CSS classes for container
|
|
93
|
+
*/
|
|
94
|
+
let klass = "";
|
|
95
|
+
export { klass as class };
|
|
96
|
+
|
|
97
|
+
$: __class =
|
|
98
|
+
"kws-bar-chart " + `${sparklines ? "kws-sparklines" : ""} ` + klass;
|
|
99
|
+
|
|
100
|
+
let _data = [];
|
|
101
|
+
let yAxis = {};
|
|
102
|
+
|
|
103
|
+
$: usedColors = colors
|
|
104
|
+
? colors
|
|
105
|
+
: $defaultChartColors
|
|
106
|
+
? $defaultChartColors
|
|
107
|
+
: [];
|
|
108
|
+
|
|
109
|
+
$: data, sets, normaliseAll();
|
|
110
|
+
$: _options = merge(
|
|
111
|
+
barChartOptions(
|
|
112
|
+
labels,
|
|
113
|
+
yAxis,
|
|
114
|
+
sparklines,
|
|
115
|
+
horizontal,
|
|
116
|
+
stacked,
|
|
117
|
+
stacked_full_width
|
|
118
|
+
),
|
|
119
|
+
Object.assign({}, { colors: usedColors }, options)
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
const normaliseAll = () => {
|
|
123
|
+
if (data.length !== sets.length) {
|
|
124
|
+
console.warn("Data and sets lengths do not match");
|
|
125
|
+
}
|
|
126
|
+
normaliseSets();
|
|
127
|
+
normaliseData();
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
const normaliseSets = () => {
|
|
131
|
+
yAxis = merge(
|
|
132
|
+
{
|
|
133
|
+
floating: false,
|
|
134
|
+
opposite: false,
|
|
135
|
+
decimalsInFloat: 0,
|
|
136
|
+
axisBorder: {
|
|
137
|
+
show: true,
|
|
138
|
+
},
|
|
139
|
+
axisTicks: {
|
|
140
|
+
show: true,
|
|
141
|
+
},
|
|
142
|
+
labels: {
|
|
143
|
+
show: true,
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
y_axis_options
|
|
147
|
+
);
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const normaliseData = () => {
|
|
151
|
+
_data = [];
|
|
152
|
+
|
|
153
|
+
//ensuring data is an array of arrays
|
|
154
|
+
let sliced_data = (data || []).slice();
|
|
155
|
+
if (!Array.isArray(sliced_data[0])) {
|
|
156
|
+
sliced_data = [sliced_data];
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
sliced_data.forEach((set, idx) => {
|
|
160
|
+
_data.push({
|
|
161
|
+
name: sets[idx],
|
|
162
|
+
data: set,
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
};
|
|
166
|
+
</script>
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
@param {object} [options={}] - Chart options, Default: `{}`
|
|
6
|
+
@param {string} [type="bar"] - Chart type, Default: `"bar"`
|
|
7
|
+
@param {array} [series=[]] - Series data, Default: `[]`
|
|
8
|
+
@param {string} [width="100%"] - Chart width, Default: `"100%"`
|
|
9
|
+
@param {string} [height="auto"] - Chart height, Default: `"auto"`
|
|
10
|
+
@param {string} [class=""] - CSS classes for container, Default: `""`
|
|
11
|
+
|
|
12
|
+
-->
|
|
13
|
+
<div class="kws-chart {klass}" bind:this={canvas} />
|
|
14
|
+
|
|
15
|
+
<script>
|
|
16
|
+
import { onMount, createEventDispatcher } from "svelte";
|
|
17
|
+
import ApexCharts from "apexcharts/dist/apexcharts.esm";
|
|
18
|
+
import { merge } from "./utils";
|
|
19
|
+
|
|
20
|
+
const fire = createEventDispatcher();
|
|
21
|
+
let canvas, chart;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Chart options
|
|
25
|
+
*/
|
|
26
|
+
export let options = {},
|
|
27
|
+
/**
|
|
28
|
+
* Chart type
|
|
29
|
+
*/
|
|
30
|
+
type = "bar",
|
|
31
|
+
/**
|
|
32
|
+
* Series data
|
|
33
|
+
*/
|
|
34
|
+
series = [],
|
|
35
|
+
/**
|
|
36
|
+
* Chart width
|
|
37
|
+
*/
|
|
38
|
+
width = "100%",
|
|
39
|
+
/**
|
|
40
|
+
* Chart height
|
|
41
|
+
*/
|
|
42
|
+
height = "auto";
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* CSS classes for container
|
|
46
|
+
*/
|
|
47
|
+
let klass = "";
|
|
48
|
+
export { klass as class };
|
|
49
|
+
|
|
50
|
+
onMount(() => {
|
|
51
|
+
init();
|
|
52
|
+
return () => {
|
|
53
|
+
chart && chart.destroy();
|
|
54
|
+
};
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
$: width, height, type, refresh();
|
|
58
|
+
$: series, seriesChanged();
|
|
59
|
+
$: options, optionsChanged();
|
|
60
|
+
|
|
61
|
+
const patchEvents = (evs) => {
|
|
62
|
+
const events = {};
|
|
63
|
+
if (typeof evs != "undefined") {
|
|
64
|
+
for (var type in evs) {
|
|
65
|
+
events[type] = (a, b, c) => {
|
|
66
|
+
fire(type, [a, b, c]);
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return events;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const init = () => {
|
|
74
|
+
chart && chart.destroy();
|
|
75
|
+
|
|
76
|
+
const newOptions = {
|
|
77
|
+
chart: {
|
|
78
|
+
type,
|
|
79
|
+
height,
|
|
80
|
+
width,
|
|
81
|
+
},
|
|
82
|
+
type,
|
|
83
|
+
series,
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
var events = {};
|
|
87
|
+
|
|
88
|
+
if (typeof options.chart.events != "undefined") {
|
|
89
|
+
events = patchEvents(options.chart.events);
|
|
90
|
+
options.chart.events = {};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const config = merge(options, newOptions);
|
|
94
|
+
|
|
95
|
+
if (canvas) {
|
|
96
|
+
config.chart.events = events;
|
|
97
|
+
chart = new ApexCharts(canvas, config);
|
|
98
|
+
chart.render();
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const refresh = () => {
|
|
103
|
+
chart && chart.destroy();
|
|
104
|
+
init();
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const seriesChanged = () => {
|
|
108
|
+
chart ? chart.updateSeries(series, true) : init();
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const optionsChanged = () => {
|
|
112
|
+
if (chart) {
|
|
113
|
+
if (typeof options.chart.events != "undefined") {
|
|
114
|
+
options.chart.events = patchEvents(options.chart.events);
|
|
115
|
+
}
|
|
116
|
+
chart.updateOptions(options, true);
|
|
117
|
+
} else {
|
|
118
|
+
init();
|
|
119
|
+
}
|
|
120
|
+
chart ? chart.updateOptions(options, true) : init();
|
|
121
|
+
};
|
|
122
|
+
</script>
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
@param {object} [options={}] - Chart options, see ApexCharts options for donut charts, Default: `{}`
|
|
6
|
+
@param {array} [labels=[]] - Data labels, Default: `[]`
|
|
7
|
+
@param {array} [data=[]] - Chart data, Default: `[]`
|
|
8
|
+
@param {boolean} [sparklines=false] - Displays the chart as a sparkline chart.
|
|
9
|
+
These are charts with minimal UI and can be
|
|
10
|
+
squeezed into small spaces, Default: `false`
|
|
11
|
+
@param {string} [width="100%"] - Chart width, supports CSS size strings, Default: `"100%"`
|
|
12
|
+
@param {string} [height="auto"] - Chart height, supports CSS size strings, Default: `"auto"`
|
|
13
|
+
@param {array} [colors=null] - Chart colors, can be modified globally in framework settings
|
|
14
|
+
|
|
15
|
+
Send an array of colors to override the default colors, or do not send anything to use the default colors, Default: `null`
|
|
16
|
+
@param {string} [class=""] - CSS classes for container, Default: `""`
|
|
17
|
+
|
|
18
|
+
-->
|
|
19
|
+
<Chart
|
|
20
|
+
class={__class}
|
|
21
|
+
options={_options}
|
|
22
|
+
series={_data}
|
|
23
|
+
type="donut"
|
|
24
|
+
{height}
|
|
25
|
+
{width} />
|
|
26
|
+
|
|
27
|
+
<script>
|
|
28
|
+
import { Chart } from "@kws3/ui";
|
|
29
|
+
import { donutChartOptions, merge } from "./utils";
|
|
30
|
+
import { defaultChartColors } from "../settings";
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Chart options, see ApexCharts options for donut charts
|
|
34
|
+
*/
|
|
35
|
+
export let options = {},
|
|
36
|
+
/**
|
|
37
|
+
* Data labels
|
|
38
|
+
*/
|
|
39
|
+
labels = [],
|
|
40
|
+
/**
|
|
41
|
+
* Chart data
|
|
42
|
+
*/
|
|
43
|
+
data = [],
|
|
44
|
+
/**
|
|
45
|
+
* Displays the chart as a sparkline chart.
|
|
46
|
+
* These are charts with minimal UI and can be
|
|
47
|
+
* squeezed into small spaces
|
|
48
|
+
*/
|
|
49
|
+
sparklines = false,
|
|
50
|
+
/**
|
|
51
|
+
* Chart width, supports CSS size strings
|
|
52
|
+
*/
|
|
53
|
+
width = "100%",
|
|
54
|
+
/**
|
|
55
|
+
* Chart height, supports CSS size strings
|
|
56
|
+
*/
|
|
57
|
+
height = "auto",
|
|
58
|
+
/**
|
|
59
|
+
* Chart colors, can be modified globally in framework settings
|
|
60
|
+
*
|
|
61
|
+
* Send an array of colors to override the default colors, or do not send anything to use the default colors
|
|
62
|
+
* @type {array}
|
|
63
|
+
*/
|
|
64
|
+
colors = null;
|
|
65
|
+
/**
|
|
66
|
+
* CSS classes for container
|
|
67
|
+
*/
|
|
68
|
+
let klass = "";
|
|
69
|
+
export { klass as class };
|
|
70
|
+
|
|
71
|
+
$: __class =
|
|
72
|
+
"kws-donut-chart " + `${sparklines ? "kws-sparklines" : ""} ` + klass;
|
|
73
|
+
|
|
74
|
+
$: usedColors = colors
|
|
75
|
+
? colors
|
|
76
|
+
: $defaultChartColors
|
|
77
|
+
? $defaultChartColors
|
|
78
|
+
: [];
|
|
79
|
+
|
|
80
|
+
$: _data = data || Array(labels.length || 0).fill(0);
|
|
81
|
+
$: _options = merge(
|
|
82
|
+
donutChartOptions(labels, sparklines),
|
|
83
|
+
Object.assign({}, { colors: usedColors }, options)
|
|
84
|
+
);
|
|
85
|
+
</script>
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
@param {object} [options={}] - Chart options, see ApexCharts options for bar charts, Default: `{}`
|
|
6
|
+
@param {array} [labels=[]] - Data labels, Default: `[]`
|
|
7
|
+
@param {array} [sets=[]] - Data sets, Default: `[]`
|
|
8
|
+
@param {array} [data=[]] - Chart data, Default: `[]`
|
|
9
|
+
@param {boolean} [sparklines=false] - Displays the chart as a sparkline chart.
|
|
10
|
+
These are charts with minimal UI and can be
|
|
11
|
+
squeezed into small spaces, Default: `false`
|
|
12
|
+
@param {object} [y_axis_options={}] - Y Axis options, see ApexCharts options for Y Axis, Default: `{}`
|
|
13
|
+
@param {string} [width="100%"] - Chart width, supports CSS size strings, Default: `"100%"`
|
|
14
|
+
@param {string} [height="auto"] - Chart height, supports CSS size strings, Default: `"auto"`
|
|
15
|
+
@param {array} [colors=null] - Chart colors, can be modified globally in framework settings
|
|
16
|
+
|
|
17
|
+
Send an array of colors to override the default colors, or do not send anything to use the default colors, Default: `null`
|
|
18
|
+
@param {string} [class=""] - CSS classes for container, Default: `""`
|
|
19
|
+
|
|
20
|
+
-->
|
|
21
|
+
<Chart
|
|
22
|
+
class={__class}
|
|
23
|
+
options={_options}
|
|
24
|
+
series={_data}
|
|
25
|
+
type="line"
|
|
26
|
+
{height}
|
|
27
|
+
{width} />
|
|
28
|
+
|
|
29
|
+
<script>
|
|
30
|
+
import { Chart } from "@kws3/ui";
|
|
31
|
+
import { lineChartOptions, merge } from "./utils";
|
|
32
|
+
import { defaultChartColors } from "../settings";
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Chart options, see ApexCharts options for bar charts
|
|
36
|
+
*/
|
|
37
|
+
export let options = {},
|
|
38
|
+
/**
|
|
39
|
+
* Data labels
|
|
40
|
+
*/
|
|
41
|
+
labels = [],
|
|
42
|
+
/**
|
|
43
|
+
* Data sets
|
|
44
|
+
*/
|
|
45
|
+
sets = [],
|
|
46
|
+
/**
|
|
47
|
+
* Chart data
|
|
48
|
+
*/
|
|
49
|
+
data = [],
|
|
50
|
+
/**
|
|
51
|
+
* Displays the chart as a sparkline chart.
|
|
52
|
+
* These are charts with minimal UI and can be
|
|
53
|
+
* squeezed into small spaces
|
|
54
|
+
*/
|
|
55
|
+
sparklines = false,
|
|
56
|
+
/**
|
|
57
|
+
* Y Axis options, see ApexCharts options for Y Axis
|
|
58
|
+
*/
|
|
59
|
+
y_axis_options = {},
|
|
60
|
+
/**
|
|
61
|
+
* Chart width, supports CSS size strings
|
|
62
|
+
*/
|
|
63
|
+
width = "100%",
|
|
64
|
+
/**
|
|
65
|
+
* Chart height, supports CSS size strings
|
|
66
|
+
*/
|
|
67
|
+
height = "auto",
|
|
68
|
+
/**
|
|
69
|
+
* Chart colors, can be modified globally in framework settings
|
|
70
|
+
*
|
|
71
|
+
* Send an array of colors to override the default colors, or do not send anything to use the default colors
|
|
72
|
+
* @type {array}
|
|
73
|
+
*/
|
|
74
|
+
colors = null;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* CSS classes for container
|
|
78
|
+
*/
|
|
79
|
+
let klass = "";
|
|
80
|
+
export { klass as class };
|
|
81
|
+
|
|
82
|
+
$: __class =
|
|
83
|
+
"kws-line-chart " + `${sparklines ? "kws-sparklines" : ""} ` + klass;
|
|
84
|
+
|
|
85
|
+
let _data = [];
|
|
86
|
+
let yAxis = {};
|
|
87
|
+
|
|
88
|
+
$: usedColors = colors
|
|
89
|
+
? colors
|
|
90
|
+
: $defaultChartColors
|
|
91
|
+
? $defaultChartColors
|
|
92
|
+
: [];
|
|
93
|
+
|
|
94
|
+
$: data, sets, normaliseAll();
|
|
95
|
+
$: _options = merge(
|
|
96
|
+
lineChartOptions(labels, yAxis, sparklines),
|
|
97
|
+
Object.assign({}, { colors: usedColors }, options)
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
const normaliseAll = () => {
|
|
101
|
+
if (data.length !== sets.length) {
|
|
102
|
+
console.warn("Data and sets lengths do not match");
|
|
103
|
+
}
|
|
104
|
+
normaliseSets();
|
|
105
|
+
normaliseData();
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const normaliseSets = () => {
|
|
109
|
+
yAxis = merge(
|
|
110
|
+
{
|
|
111
|
+
floating: false,
|
|
112
|
+
opposite: false,
|
|
113
|
+
decimalsInFloat: 0,
|
|
114
|
+
axisBorder: {
|
|
115
|
+
show: true,
|
|
116
|
+
},
|
|
117
|
+
axisTicks: {
|
|
118
|
+
show: true,
|
|
119
|
+
},
|
|
120
|
+
labels: {
|
|
121
|
+
show: true,
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
y_axis_options
|
|
125
|
+
);
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const normaliseData = () => {
|
|
129
|
+
_data = [];
|
|
130
|
+
|
|
131
|
+
//ensuring data is an array of arrays
|
|
132
|
+
let sliced_data = (data || []).slice();
|
|
133
|
+
if (!Array.isArray(sliced_data[0])) {
|
|
134
|
+
sliced_data = [sliced_data];
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
sliced_data.forEach((set, idx) => {
|
|
138
|
+
_data.push({
|
|
139
|
+
name: sets[idx],
|
|
140
|
+
data: set,
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
</script>
|