waterfall_styling.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # Copyright 2021-2025 Avaiga Private Limited
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
  4. # the License. You may obtain a copy of the License at
  5. #
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. #
  8. # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
  9. # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
  10. # specific language governing permissions and limitations under the License.
  11. # -----------------------------------------------------------------------------------------
  12. # To execute this script, make sure that the taipy-gui package is installed in your
  13. # Python environment and run:
  14. # python <script>
  15. # -----------------------------------------------------------------------------------------
  16. from taipy.gui import Gui
  17. # 9-hole course
  18. n_holes = 9
  19. # Data set
  20. # Each entry holds an array of values. One for each hole, plus one for th
  21. data = {
  22. # ["Hole1", "Hole2", ..., "Hole9"]
  23. "Hole": [f"Hole{h}" for h in range(1, n_holes + 1)] + ["Score"],
  24. # Par for each hole
  25. "Par": [3, 4, 4, 5, 3, 5, 4, 5, 3] + [None], # type: ignore
  26. # Score for each hole
  27. "Score": [4, 4, 5, 4, 4, 5, 4, 5, 4] + [None], # type: ignore
  28. # Represented as relative values except for the last one
  29. "M": n_holes * ["relative"] + ["total"],
  30. }
  31. # Compute difference (Score-Par)
  32. data["Diff"] = [data["Score"][i] - data["Par"][i] for i in range(0, n_holes)] + [None] # type: ignore[index]
  33. # Show positive values in red, and negative values in green
  34. options = {"decreasing": {"marker": {"color": "green"}}, "increasing": {"marker": {"color": "red"}}}
  35. page = """
  36. <|{data}|chart|type=waterfall|x=Hole|y=Diff|measure=M|options={options}|>
  37. """
  38. if __name__ == "__main__":
  39. Gui(page).run(title="Chart - Waterfall - Styling")