Qt Quick based coffee brewing control chart.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

BrewingControlChart.qml 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. import CustomComponents 1.0
  2. import QtQuick 1.0
  3. Item {
  4. id: chartOuter
  5. property real xmin: 0.14
  6. property real xmax: 0.26
  7. property real ymin: 0.008
  8. property real ymax: 0.016
  9. property real xrange: xmax - xmin
  10. property real yrange: ymax - ymin
  11. function plotPoint(px, py, pcolor) {
  12. chart.plotPoint(px, py, pcolor);
  13. }
  14. function setFit(x1, y1, x2, y2) {
  15. chart.setFit(x1, y1, x2, y2)
  16. }
  17. function setFitVisible(visible) {
  18. fitline.visible = visible
  19. }
  20. function setFitColor(color) {
  21. fitline.color = color
  22. }
  23. function clear() {
  24. points.clear();
  25. }
  26. Item {
  27. id: chart
  28. height: parent.height
  29. width: parent.width
  30. function plotPoint(px, py, pcolor) {
  31. points.append({"px": px, "py": py, "pcolor": pcolor});
  32. }
  33. function mapToX(px) {
  34. return (chart.width / xrange) * (px - xmin)
  35. }
  36. function mapToY(py) {
  37. return chart.height - ((chart.height / yrange) * (py - ymin))
  38. }
  39. function setFit(x1, y1, x2, y2) {
  40. fitline.x1 = mapToX(x1);
  41. fitline.x2 = mapToX(x2);
  42. fitline.y1 = mapToY(y1);
  43. fitline.y2 = mapToY(y2);
  44. }
  45. Line {
  46. id: fitline
  47. x1: 0
  48. x2: 0
  49. y1: 0
  50. y2: 0
  51. color: "red"
  52. visible: false
  53. }
  54. ListModel {
  55. id: xGridLines
  56. }
  57. ListModel {
  58. id: yGridLines
  59. }
  60. ListModel {
  61. id: points
  62. }
  63. ListModel {
  64. id: yLabels
  65. }
  66. ListModel {
  67. id: xLabels
  68. }
  69. Repeater {
  70. model: xGridLines
  71. Line {
  72. x1: (chart.width / xrange) * (value - xmin)
  73. x2: x1
  74. y1: 0
  75. y2: chart.height
  76. penWidth: pwidth
  77. color: "black"
  78. }
  79. }
  80. Repeater {
  81. model: yGridLines
  82. Line {
  83. x1: 0
  84. x2: chart.width
  85. y1: chart.height - ((chart.height / yrange) * (value - ymin))
  86. y2: y1
  87. penWidth: pwidth
  88. color: "black"
  89. }
  90. }
  91. Repeater {
  92. model: points
  93. Item {
  94. Rectangle {
  95. x: ((chart.width / xrange) * (px - xmin)) - (width / 2)
  96. y: chart.height - ((chart.height / yrange) * (py - ymin)) - (height / 2)
  97. width: 5
  98. height: 5
  99. color: pcolor
  100. smooth: true
  101. }
  102. }
  103. }
  104. }
  105. Repeater {
  106. id: yTickLabels
  107. model: yLabels
  108. anchors.right: chart.left
  109. anchors.rightMargin: 10
  110. y: chart.y
  111. Item {
  112. Text {
  113. text: (value * 100).toFixed(2) + "%"
  114. y: chart.mapToY(value) - (height/2)
  115. x: -width
  116. }
  117. }
  118. }
  119. Item {
  120. anchors.right: yTickLabels.left
  121. anchors.rightMargin: 40
  122. y: chart.y + (chart.height/2) - (strengthLabel.height/2)
  123. Text {
  124. id: strengthLabel
  125. text: "STRENGTH - Solubles Concentration (%TDS)"
  126. rotation: -90
  127. x: -(width/2)
  128. }
  129. }
  130. Repeater {
  131. id: xTickLabels
  132. anchors.top: chart.bottom
  133. anchors.topMargin: 10
  134. model: xLabels
  135. x: chart.x
  136. Item {
  137. Text {
  138. text: (value * 100).toFixed(0) + "%"
  139. x: chart.mapToX(value) - (width/2)
  140. y: xTickLabels.y
  141. }
  142. }
  143. }
  144. Text {
  145. text: "EXTRACTION - Solubles Yield"
  146. x: chart.x + (chart.width/2) - (width/2)
  147. anchors.top: xTickLabels.bottom
  148. anchors.topMargin: 20
  149. }
  150. Component.onCompleted: {
  151. for(var i = 0.14; i < 0.261; i += 0.01) {
  152. xGridLines.append({"value": i, "pwidth": i.toFixed(2) == 0.18 || i.toFixed(2) == 0.22 ? 2 : 1});
  153. xLabels.append({"value": i});
  154. }
  155. for(var i = 0.008; i < 0.0161; i += 0.0005) {
  156. yGridLines.append({"value": i, "pwidth": i.toFixed(4) == 0.0115 || i.toFixed(4) == 0.0135 ? 2 : 1});
  157. yLabels.append({"value": i});
  158. }
  159. }
  160. }