@kws3/ui 1.5.1 → 1.5.5
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/DonutChart.svelte +12 -2
- package/charts/LineChart.svelte +144 -0
- package/charts/MixedChart.svelte +33 -17
- package/charts/PieChart.svelte +12 -2
- package/charts/RadialChart.svelte +117 -0
- package/charts/utils.js +55 -8
- package/index.js +4 -0
- package/package.json +2 -2
- package/styles/Chart.scss +9 -3
|
@@ -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>
|
package/charts/DonutChart.svelte
CHANGED
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
@param {object} [options={}] - Chart options, see ApexCharts options for donut charts, Default: `{}`
|
|
6
6
|
@param {array} [labels=[]] - Data labels, Default: `[]`
|
|
7
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`
|
|
8
11
|
@param {string} [width="100%"] - Chart width, supports CSS size strings, Default: `"100%"`
|
|
9
12
|
@param {string} [height="auto"] - Chart height, supports CSS size strings, Default: `"auto"`
|
|
10
13
|
@param {array} [colors=null] - Chart colors, can be modified globally in framework settings
|
|
@@ -38,6 +41,12 @@ Send an array of colors to override the default colors, or do not send anything
|
|
|
38
41
|
* Chart data
|
|
39
42
|
*/
|
|
40
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,
|
|
41
50
|
/**
|
|
42
51
|
* Chart width, supports CSS size strings
|
|
43
52
|
*/
|
|
@@ -59,7 +68,8 @@ Send an array of colors to override the default colors, or do not send anything
|
|
|
59
68
|
let klass = "";
|
|
60
69
|
export { klass as class };
|
|
61
70
|
|
|
62
|
-
$: __class =
|
|
71
|
+
$: __class =
|
|
72
|
+
"kws-donut-chart " + `${sparklines ? "kws-sparklines" : ""} ` + klass;
|
|
63
73
|
|
|
64
74
|
$: usedColors = colors
|
|
65
75
|
? colors
|
|
@@ -69,7 +79,7 @@ Send an array of colors to override the default colors, or do not send anything
|
|
|
69
79
|
|
|
70
80
|
$: _data = data || Array(labels.length || 0).fill(0);
|
|
71
81
|
$: _options = merge(
|
|
72
|
-
donutChartOptions(labels),
|
|
82
|
+
donutChartOptions(labels, sparklines),
|
|
73
83
|
Object.assign({}, { colors: usedColors }, options)
|
|
74
84
|
);
|
|
75
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>
|
package/charts/MixedChart.svelte
CHANGED
|
@@ -6,7 +6,11 @@
|
|
|
6
6
|
@param {array} [labels=[]] - Data labels, Default: `[]`
|
|
7
7
|
@param {array} [sets=[]] - Data sets, Default: `[]`
|
|
8
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`
|
|
9
12
|
@param {boolean} [multiaxis=false] - Whether the chart has multiple axes, Default: `false`
|
|
13
|
+
@param {object} [y_axis_options={}] - Y Axis options, see ApexCharts options for Y Axis, Default: `{}`
|
|
10
14
|
@param {string} [width="100%"] - Chart width, supports CSS size strings, Default: `"100%"`
|
|
11
15
|
@param {string} [height="auto"] - Chart height, supports CSS size strings, Default: `"auto"`
|
|
12
16
|
@param {array} [colors=null] - Chart colors, can be modified globally in framework settings
|
|
@@ -44,10 +48,20 @@ Send an array of colors to override the default colors, or do not send anything
|
|
|
44
48
|
* Chart data
|
|
45
49
|
*/
|
|
46
50
|
data = [],
|
|
51
|
+
/**
|
|
52
|
+
* Displays the chart as a sparkline chart.
|
|
53
|
+
* These are charts with minimal UI and can be
|
|
54
|
+
* squeezed into small spaces
|
|
55
|
+
*/
|
|
56
|
+
sparklines = false,
|
|
47
57
|
/**
|
|
48
58
|
* Whether the chart has multiple axes
|
|
49
59
|
*/
|
|
50
60
|
multiaxis = false,
|
|
61
|
+
/**
|
|
62
|
+
* Y Axis options, see ApexCharts options for Y Axis
|
|
63
|
+
*/
|
|
64
|
+
y_axis_options = {},
|
|
51
65
|
/**
|
|
52
66
|
* Chart width, supports CSS size strings
|
|
53
67
|
*/
|
|
@@ -70,13 +84,12 @@ Send an array of colors to override the default colors, or do not send anything
|
|
|
70
84
|
let klass = "";
|
|
71
85
|
export { klass as class };
|
|
72
86
|
|
|
73
|
-
$: __class =
|
|
87
|
+
$: __class =
|
|
88
|
+
"kws-mixed-chart " + `${sparklines ? "kws-sparklines" : ""} ` + klass;
|
|
74
89
|
|
|
75
90
|
let _data = [];
|
|
76
91
|
let yAxis = [];
|
|
77
92
|
|
|
78
|
-
let sparklines = false;
|
|
79
|
-
|
|
80
93
|
$: usedColors = colors
|
|
81
94
|
? colors
|
|
82
95
|
: $defaultChartColors
|
|
@@ -91,7 +104,7 @@ Send an array of colors to override the default colors, or do not send anything
|
|
|
91
104
|
|
|
92
105
|
const normaliseAll = () => {
|
|
93
106
|
if (data.length !== sets.length) {
|
|
94
|
-
|
|
107
|
+
console.warn("Data and sets lengths do not match");
|
|
95
108
|
}
|
|
96
109
|
normaliseSets();
|
|
97
110
|
normaliseData();
|
|
@@ -107,20 +120,23 @@ Send an array of colors to override the default colors, or do not send anything
|
|
|
107
120
|
|
|
108
121
|
_sets.forEach((set, idx) => {
|
|
109
122
|
let __set = {};
|
|
110
|
-
let obj =
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
123
|
+
let obj = merge(
|
|
124
|
+
{
|
|
125
|
+
floating: false,
|
|
126
|
+
opposite: false,
|
|
127
|
+
decimalsInFloat: 0,
|
|
128
|
+
axisBorder: {
|
|
129
|
+
show: true,
|
|
130
|
+
},
|
|
131
|
+
axisTicks: {
|
|
132
|
+
show: true,
|
|
133
|
+
},
|
|
134
|
+
labels: {
|
|
135
|
+
show: true,
|
|
136
|
+
},
|
|
122
137
|
},
|
|
123
|
-
|
|
138
|
+
y_axis_options
|
|
139
|
+
);
|
|
124
140
|
if (typeof set === "string") {
|
|
125
141
|
__set = Object.assign(obj, {
|
|
126
142
|
name: set,
|
package/charts/PieChart.svelte
CHANGED
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
@param {object} [options={}] - Chart options, see ApexCharts options for pie charts, Default: `{}`
|
|
6
6
|
@param {array} [labels=[]] - Data labels, Default: `[]`
|
|
7
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`
|
|
8
11
|
@param {string} [width="100%"] - Chart width, supports CSS size strings, Default: `"100%"`
|
|
9
12
|
@param {string} [height="auto"] - Chart height, supports CSS size strings, Default: `"auto"`
|
|
10
13
|
@param {array} [colors=null] - Chart colors, can be modified globally in framework settings
|
|
@@ -38,6 +41,12 @@ Send an array of colors to override the default colors, or do not send anything
|
|
|
38
41
|
* Chart data
|
|
39
42
|
*/
|
|
40
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,
|
|
41
50
|
/**
|
|
42
51
|
* Chart width, supports CSS size strings
|
|
43
52
|
*/
|
|
@@ -60,7 +69,8 @@ Send an array of colors to override the default colors, or do not send anything
|
|
|
60
69
|
let klass = "";
|
|
61
70
|
export { klass as class };
|
|
62
71
|
|
|
63
|
-
$: __class =
|
|
72
|
+
$: __class =
|
|
73
|
+
"kws-pie-chart " + `${sparklines ? "kws-sparklines" : ""} ` + klass;
|
|
64
74
|
|
|
65
75
|
$: usedColors = colors
|
|
66
76
|
? colors
|
|
@@ -70,7 +80,7 @@ Send an array of colors to override the default colors, or do not send anything
|
|
|
70
80
|
|
|
71
81
|
$: _data = data || Array(labels.length || 0).fill(0);
|
|
72
82
|
$: _options = merge(
|
|
73
|
-
pieChartOptions(labels),
|
|
83
|
+
pieChartOptions(labels, sparklines),
|
|
74
84
|
Object.assign({}, { colors: usedColors }, options)
|
|
75
85
|
);
|
|
76
86
|
</script>
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
@param {object} [options={}] - Chart options, see ApexCharts options for radial charts, Default: `{}`
|
|
6
|
+
@param {array} [labels=[]] - Data labels, Default: `[]`
|
|
7
|
+
@param {array} [data=[]] - Chart data, Default: `[]`
|
|
8
|
+
@param {number} [start_angle=0] - Starting angle in degrees, Default: `0`
|
|
9
|
+
@param {number} [end_angle=360] - Ending angle in degrees, Default: `360`
|
|
10
|
+
@param {boolean} [sparklines=false] - Displays the chart as a sparkline chart.
|
|
11
|
+
These are charts with minimal UI and can be
|
|
12
|
+
squeezed into small spaces, Default: `false`
|
|
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="radialBar"
|
|
26
|
+
{height}
|
|
27
|
+
{width} />
|
|
28
|
+
|
|
29
|
+
<script>
|
|
30
|
+
import { Chart } from "@kws3/ui";
|
|
31
|
+
import { radialChartOptions, merge } from "./utils";
|
|
32
|
+
import { defaultChartColors } from "../settings";
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Chart options, see ApexCharts options for radial charts
|
|
36
|
+
*/
|
|
37
|
+
export let options = {},
|
|
38
|
+
/**
|
|
39
|
+
* Data labels
|
|
40
|
+
*/
|
|
41
|
+
labels = [],
|
|
42
|
+
/**
|
|
43
|
+
* Chart data
|
|
44
|
+
*/
|
|
45
|
+
data = [],
|
|
46
|
+
/**
|
|
47
|
+
* Starting angle in degrees
|
|
48
|
+
*/
|
|
49
|
+
start_angle = 0,
|
|
50
|
+
/**
|
|
51
|
+
* Ending angle in degrees
|
|
52
|
+
*/
|
|
53
|
+
end_angle = 360,
|
|
54
|
+
/**
|
|
55
|
+
* Displays the chart as a sparkline chart.
|
|
56
|
+
* These are charts with minimal UI and can be
|
|
57
|
+
* squeezed into small spaces
|
|
58
|
+
*/
|
|
59
|
+
sparklines = false,
|
|
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
|
+
let _data = [],
|
|
83
|
+
_labels = [];
|
|
84
|
+
|
|
85
|
+
$: __class =
|
|
86
|
+
"kws-radial-chart " + `${sparklines ? "kws-sparklines" : ""} ` + klass;
|
|
87
|
+
|
|
88
|
+
$: usedColors = colors
|
|
89
|
+
? colors
|
|
90
|
+
: $defaultChartColors
|
|
91
|
+
? $defaultChartColors
|
|
92
|
+
: [];
|
|
93
|
+
|
|
94
|
+
$: data, normaliseData();
|
|
95
|
+
$: labels, normaliseLabels();
|
|
96
|
+
$: _options = merge(
|
|
97
|
+
radialChartOptions(_labels, start_angle, end_angle, sparklines),
|
|
98
|
+
Object.assign({}, { colors: usedColors }, options)
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
const normaliseData = () => {
|
|
102
|
+
_data = data;
|
|
103
|
+
if (!data) {
|
|
104
|
+
_data = Array(labels.length || 0).fill(0);
|
|
105
|
+
}
|
|
106
|
+
if (!Array.isArray(data)) {
|
|
107
|
+
_data = [data];
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const normaliseLabels = () => {
|
|
112
|
+
_labels = labels;
|
|
113
|
+
if (!Array.isArray(labels)) {
|
|
114
|
+
_labels = [labels];
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
</script>
|
package/charts/utils.js
CHANGED
|
@@ -11,7 +11,7 @@ const themeColors = [
|
|
|
11
11
|
|
|
12
12
|
export const merge = ApexCharts.merge;
|
|
13
13
|
|
|
14
|
-
export function pieChartOptions(labels) {
|
|
14
|
+
export function pieChartOptions(labels, is_sparkline) {
|
|
15
15
|
return {
|
|
16
16
|
chart: {
|
|
17
17
|
type: "pie",
|
|
@@ -21,6 +21,9 @@ export function pieChartOptions(labels) {
|
|
|
21
21
|
toolbar: {
|
|
22
22
|
show: false,
|
|
23
23
|
},
|
|
24
|
+
sparkline: {
|
|
25
|
+
enabled: is_sparkline ? true : false,
|
|
26
|
+
},
|
|
24
27
|
},
|
|
25
28
|
colors: themeColors,
|
|
26
29
|
fill: {
|
|
@@ -64,12 +67,24 @@ export function pieChartOptions(labels) {
|
|
|
64
67
|
};
|
|
65
68
|
}
|
|
66
69
|
|
|
67
|
-
export function donutChartOptions(labels) {
|
|
68
|
-
var obj = pieChartOptions(labels);
|
|
70
|
+
export function donutChartOptions(labels, is_sparkline) {
|
|
71
|
+
var obj = pieChartOptions(labels, is_sparkline);
|
|
69
72
|
obj.chart.type = "donut";
|
|
70
73
|
return obj;
|
|
71
74
|
}
|
|
72
75
|
|
|
76
|
+
export function radialChartOptions(labels, startAngle, endAngle, is_sparkline) {
|
|
77
|
+
var obj = pieChartOptions(labels, is_sparkline);
|
|
78
|
+
obj.chart.type = "radialBar";
|
|
79
|
+
obj.plotOptions = {
|
|
80
|
+
radialBar: {
|
|
81
|
+
startAngle,
|
|
82
|
+
endAngle,
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
return obj;
|
|
86
|
+
}
|
|
87
|
+
|
|
73
88
|
export function mixedChartOptions(xAxis, yAxis, is_sparkline) {
|
|
74
89
|
return {
|
|
75
90
|
chart: {
|
|
@@ -103,8 +118,12 @@ export function mixedChartOptions(xAxis, yAxis, is_sparkline) {
|
|
|
103
118
|
enabled: false,
|
|
104
119
|
},
|
|
105
120
|
markers: {
|
|
106
|
-
size:
|
|
121
|
+
size: 3,
|
|
107
122
|
shape: "circle",
|
|
123
|
+
strokeWidth: 1,
|
|
124
|
+
hover: {
|
|
125
|
+
sizeOffset: 3,
|
|
126
|
+
},
|
|
108
127
|
},
|
|
109
128
|
plotOptions: {
|
|
110
129
|
bar: {
|
|
@@ -112,8 +131,8 @@ export function mixedChartOptions(xAxis, yAxis, is_sparkline) {
|
|
|
112
131
|
},
|
|
113
132
|
},
|
|
114
133
|
tooltip: {
|
|
115
|
-
shared: true,
|
|
116
|
-
intersect: false,
|
|
134
|
+
shared: is_sparkline ? false : true,
|
|
135
|
+
intersect: is_sparkline ? true : false,
|
|
117
136
|
x: {
|
|
118
137
|
show: is_sparkline ? true : false,
|
|
119
138
|
},
|
|
@@ -124,7 +143,7 @@ export function mixedChartOptions(xAxis, yAxis, is_sparkline) {
|
|
|
124
143
|
},
|
|
125
144
|
],
|
|
126
145
|
fixed: {
|
|
127
|
-
enabled: true,
|
|
146
|
+
enabled: is_sparkline ? false : true,
|
|
128
147
|
position: "topLeft",
|
|
129
148
|
offsetY: 10,
|
|
130
149
|
offsetX: 25,
|
|
@@ -148,7 +167,7 @@ export function mixedChartOptions(xAxis, yAxis, is_sparkline) {
|
|
|
148
167
|
legend: {
|
|
149
168
|
position: "top",
|
|
150
169
|
horizontalAlign: "right",
|
|
151
|
-
fontSize: "
|
|
170
|
+
fontSize: "12px",
|
|
152
171
|
labels: {
|
|
153
172
|
useSeriesColors: true,
|
|
154
173
|
},
|
|
@@ -164,3 +183,31 @@ export function mixedChartOptions(xAxis, yAxis, is_sparkline) {
|
|
|
164
183
|
},
|
|
165
184
|
};
|
|
166
185
|
}
|
|
186
|
+
|
|
187
|
+
export function barChartOptions(
|
|
188
|
+
xAxis,
|
|
189
|
+
yAxis,
|
|
190
|
+
is_sparkline,
|
|
191
|
+
is_horizontal,
|
|
192
|
+
is_stacked,
|
|
193
|
+
is_stacked_full
|
|
194
|
+
) {
|
|
195
|
+
let opts = mixedChartOptions(xAxis, yAxis, is_sparkline);
|
|
196
|
+
opts.chart.type = "bar";
|
|
197
|
+
opts.chart.stacked = is_stacked ? true : false;
|
|
198
|
+
opts.chart.stackType = is_stacked_full ? "100%" : false;
|
|
199
|
+
opts.plotOptions.bar.horizontal = is_horizontal ? true : false;
|
|
200
|
+
return opts;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export function lineChartOptions(xAxis, yAxis, is_sparkline) {
|
|
204
|
+
let opts = mixedChartOptions(xAxis, yAxis, is_sparkline);
|
|
205
|
+
opts.chart.type = "line";
|
|
206
|
+
return opts;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export function areaChartOptions(xAxis, yAxis, is_sparkline) {
|
|
210
|
+
let opts = mixedChartOptions(xAxis, yAxis, is_sparkline);
|
|
211
|
+
opts.chart.type = "area";
|
|
212
|
+
return opts;
|
|
213
|
+
}
|
package/index.js
CHANGED
|
@@ -61,3 +61,7 @@ export { default as Chart } from "./charts/Chart.svelte";
|
|
|
61
61
|
export { default as DonutChart } from "./charts/DonutChart.svelte";
|
|
62
62
|
export { default as PieChart } from "./charts/PieChart.svelte";
|
|
63
63
|
export { default as MixedChart } from "./charts/MixedChart.svelte";
|
|
64
|
+
export { default as BarChart } from "./charts/BarChart.svelte";
|
|
65
|
+
export { default as LineChart } from "./charts/LineChart.svelte";
|
|
66
|
+
export { default as AreaChart } from "./charts/AreaChart.svelte";
|
|
67
|
+
export { default as RadialChart } from "./charts/RadialChart.svelte";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kws3/ui",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.5",
|
|
4
4
|
"description": "UI components for use with Svelte v3 applications.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"text-mask-core": "^5.1.2",
|
|
29
29
|
"tippy.js": "^6.3.1"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "49d3b7b20b12fea5110db28ec4be8ed8562d4e36"
|
|
32
32
|
}
|
package/styles/Chart.scss
CHANGED
|
@@ -22,11 +22,17 @@ $kws-chart-tooltip-foreground-color: $scheme-invert-ter !default;
|
|
|
22
22
|
margin-right: 5px;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
.apexcharts-
|
|
26
|
-
font-
|
|
25
|
+
.apexcharts-tooltip-title {
|
|
26
|
+
font-weight: bold;
|
|
27
|
+
margin-bottom: 0;
|
|
28
|
+
padding: 0 6px;
|
|
29
|
+
text-align: center;
|
|
27
30
|
}
|
|
28
31
|
|
|
29
|
-
&.kws-mixed-chart
|
|
32
|
+
&.kws-mixed-chart:not(.kws-sparklines),
|
|
33
|
+
&.kws-bar-chart:not(.kws-sparklines),
|
|
34
|
+
&.kws-line-chart:not(.kws-sparklines),
|
|
35
|
+
&.kws-area-chart:not(.kws-sparklines) {
|
|
30
36
|
.apexcharts-tooltip {
|
|
31
37
|
flex-direction: row;
|
|
32
38
|
box-shadow: none;
|