File: LineChartControl.qml

package info (click to toggle)
kf6-kquickcharts 6.20.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 852 kB
  • sloc: cpp: 5,663; makefile: 11; sh: 5
file content (246 lines) | stat: -rw-r--r-- 7,815 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/*
 * This file is part of KQuickCharts
 * SPDX-FileCopyrightText: 2019 Arjen Hiemstra <ahiemstra@heimr.nl>
 *
 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
 */

import QtQuick
import QtQuick.Controls

import org.kde.quickcharts as Charts
import org.kde.quickcharts.controls

/*!
  \qmltype LineChartControl
  \inqmlmodule org.kde.quickcharts.controls
  \brief A line chart with legend, grid and axis labels.
 */
Control {

    /*!
      \qmlproperty list<ChartDataSource> LineChartControl::valueSources
     */
    property alias valueSources: lineChart.valueSources

    /*!
      \qmlproperty list<variant> LineChartControl::names
     */
    property alias names: nameSource.array

    /*!
      \qmlproperty color LineChartControl::color
     */
    property alias color: colorSource.baseColor

    /*!
      \qmlproperty real LineChartControl::lineWidth
     */
    property alias lineWidth: lineChart.lineWidth

    /*!
      \qmlproperty real LineChartControl::fillOpacity
     */
    property alias fillOpacity: lineChart.fillOpacity

    /*!
      \qmlproperty bool LineChartControl::stacked
     */
    property alias stacked: lineChart.stacked

    /*!
      \qmlproperty LineChart LineChartControl::chart
     */
    property alias chart: lineChart

    /*!
      \qmlproperty Legend LineChartControl::legend
     */
    property alias legend: legend

    /*!
      \qmlproperty AxisLabels LineChartControl::xLabels
     */
    property alias xLabels: xAxisLabels

    /*!
      \qmlproperty AxisLabels LineChartControl::yLabels
     */
    property alias yLabels: yAxisLabels

    /*!
      \qmlproperty bool LineChartControl::verticalLinesVisible
     */
    property alias verticalLinesVisible: verticalLines.visible

    /*!
      \qmlproperty bool LineChartControl::horizontalLinesVisible
     */
    property alias horizontalLinesVisible: horizontalLines.visible

    /*!
      \qmlproperty real LineChartControl::xRange.from
      \qmlproperty real LineChartControl::xRange.to
      \qmlproperty bool LineChartControl::xRange.automatic
      \qmlproperty real LineChartControl::xRange.distance
      \qmlproperty real LineChartControl::xRange.minimum
      \qmlproperty real LineChartControl::xRange.increment

      \brief The range of values on the X axis.

      from: The start of this range. The default is 0.

      to: The end of this range. The default is 100.

      automatic: Whether to determine the range based on values of a chart. If true (the default), from and to are ignored and instead calculated from the minimum and maximum values of a chart's valueSources.

      distance: The distance between from and to.

      minimum: The minimum size of the range. This is mostly relevant when automatic is true. Setting this value will ensure that the range will never be smaller than this value. The default is std::numeric_limits<qreal>::min, which means minimum is disabled.

      increment: The amount with which the range increases. The total range will be limited to a multiple of this value. This is mostly useful when automatic is true. The default is 0.0, which means do not limit the range increment.
     */
    property alias xRange: lineChart.xRange

    /*!
      \qmlproperty real LineChartControl::yRange.from
      \qmlproperty real LineChartControl::yRange.to
      \qmlproperty bool LineChartControl::yRange.automatic
      \qmlproperty real LineChartControl::yRange.distance
      \qmlproperty real LineChartControl::yRange.minimum
      \qmlproperty real LineChartControl::yRange.increment

      \brief The range of values on the Y axis.

      from: The start of this range. The default is 0.

      to: The end of this range. The default is 100.

      automatic: Whether to determine the range based on values of a chart. If true (the default), from and to are ignored and instead calculated from the minimum and maximum values of a chart's valueSources.

      distance: The distance between from and to.

      minimum: The minimum size of the range. This is mostly relevant when automatic is true. Setting this value will ensure that the range will never be smaller than this value. The default is std::numeric_limits<qreal>::min, which means minimum is disabled.

      increment: The amount with which the range increases. The total range will be limited to a multiple of this value. This is mostly useful when automatic is true. The default is 0.0, which means do not limit the range increment.
     */
    property alias yRange: lineChart.yRange

    /*!
      \qmlproperty ChartAxisSource LineChartControl::xAxisSource
     */
    property alias xAxisSource: xAxisLabels.source

    /*!
      \qmlproperty ChartAxisSource LineChartControl::yAxisSource
     */
    property alias yAxisSource: yAxisLabels.source

    /*!
      \qmlproperty Component LineChartControl::pointDelegate
     */
    property alias pointDelegate: lineChart.pointDelegate

    /*!
      \qmlproperty bool LineChartControl::highlightEnabled
     */
    property alias highlightEnabled: legend.highlightEnabled

    background: Rectangle { color: Theme.backgroundColor }

    contentItem: Item {
        anchors.fill: parent;

        GridLines {
            id: horizontalLines

            anchors.fill: lineChart

            chart: lineChart

            major.frequency: 2
            major.lineWidth: 2
            major.color: Qt.rgba(0.8, 0.8, 0.8, 1.0)

            minor.frequency: 1
            minor.lineWidth: 1
            minor.color: Qt.rgba(0.8, 0.8, 0.8, 1.0)
        }

        GridLines {
            id: verticalLines

            anchors.fill: lineChart

            chart: lineChart

            direction: GridLines.Vertical;

            major.count: 1
            major.lineWidth: 2
            major.color: Qt.rgba(0.8, 0.8, 0.8, 1.0)

            minor.count: 3
            minor.lineWidth: 1
            minor.color: Qt.rgba(0.8, 0.8, 0.8, 1.0)
        }

        AxisLabels {
            id: yAxisLabels

            anchors {
                left: parent.left
                top: parent.top
                bottom: xAxisLabels.top
            }

            direction: AxisLabels.VerticalBottomTop
            delegate: Label { text: AxisLabels.label }
            source: Charts.ChartAxisSource { chart: lineChart; axis: Charts.ChartAxisSource.YAxis; itemCount: 5 }
        }

        AxisLabels {
            id: xAxisLabels

            anchors {
                left: yAxisLabels.visible ? yAxisLabels.right : parent.left
                right: parent.right
                bottom: legend.top
            }

            delegate: Label { text: AxisLabels.label }
            source: Charts.ChartAxisSource { chart: lineChart; axis: Charts.ChartAxisSource.XAxis; itemCount: 5 }
        }

        Legend {
            id: legend

            anchors {
                left: yAxisLabels.visible ? yAxisLabels.right : parent.left
                right: parent.right
                bottom: parent.bottom
                bottomMargin: Theme.smallSpacing
            }

            chart: lineChart
        }

        Charts.LineChart {
            id: lineChart
            anchors {
                top: parent.top
                left: yAxisLabels.visible ? yAxisLabels.right : parent.left
                right: parent.right
                bottom: xAxisLabels.visible ? xAxisLabels.top : legend.top
            }

            xRange.automatic: true
            yRange.automatic: true

            colorSource: Charts.ColorGradientSource { id: colorSource; baseColor: Theme.highlightColor; itemCount: lineChart.valueSources.length }
            nameSource: Charts.ArraySource { id: nameSource; array: ["1", "2", "3", "4", "5"] }

            highlight: legend.highlightedIndex
        }
    }
}