Debian Codegraph @

examples/charts/qmlchartsgallery/qml/customlegend/ChartViewSelector.qml

raw
1 // Copyright (C) 2023 The Qt Company Ltd.
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4 import QtQuick
5 import QtCharts
6
7 Item {
8 id: chartViewSelector
9
10 signal seriesAdded(string seriesName, color seriesColor)
11
12 function highlightSeries(seriesName) {
13 if (seriesName === "") {
14 if (state !== "")
15 state = "";
16
17 for (var i = 0; i < chartViewStacked.count; i++)
18 chartViewStacked.series(i).opacity = 1.0;
19 } else {
20 var targetOpacity = 0.1;
21 for (var j = 0; j < chartViewStacked.count; j++) {
22 if (chartViewStacked.series(j).name !== seriesName)
23 chartViewStacked.series(j).opacity = 0.25;
24 else if (state === "highlight")
25 chartViewSelected.selectedSeries = chartViewStacked.series(j);
26 }
27 }
28 }
29
30 function selectSeries(seriesName) {
31 for (var i = 0; i < chartViewStacked.count; i++) {
32 if (chartViewStacked.series(i).name === seriesName) {
33 chartViewSelected.selectedSeries = chartViewStacked.series(i);
34 if (chartViewSelector.state === "")
35 chartViewSelector.state = "highlighted";
36 else
37 chartViewSelector.state = "";
38 }
39 }
40 }
41
42 ChartViewStacked {
43 id: chartViewStacked
44 anchors.left: parent.left
45 anchors.leftMargin: 0
46 width: parent.width
47 height: parent.height
48 onSeriesAdded: series => chartViewSelector.seriesAdded(series.name, series.color);
49 }
50
51 ChartViewHighlighted {
52 id: chartViewSelected
53 anchors.left: chartViewStacked.right
54 width: parent.width
55 height: parent.height
56
57 opacity: 0.0
58 onClicked: {
59 chartViewSelector.state = "";
60 }
61 }
62
63 states: State {
64 name: "highlighted"
65 PropertyChanges {
66 target: chartViewSelected
67 opacity: 1.0
68 }
69 PropertyChanges {
70 target: chartViewStacked
71 anchors.leftMargin: -chartViewStacked.width
72 opacity: 0.0
73 }
74 }
75
76 transitions: Transition {
77 PropertyAnimation {
78 properties: "width, height, opacity, anchors.leftMargin"
79 duration: 400
80 }
81 }
82 }