waterfall-styling.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # Copyright 2021-2024 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. if __name__ == "__main__":
  18. # 9-hole course
  19. n_holes = 9
  20. # Data set
  21. # Each entry holds an array of values. One for each hole, plus one for th
  22. data = {
  23. # ["Hole1", "Hole2", ..., "Hole9"]
  24. "Hole": [f"Hole{h}" for h in range(1, n_holes + 1)] + ["Score"],
  25. # Par for each hole
  26. "Par": [3, 4, 4, 5, 3, 5, 4, 5, 3] + [None], # type: ignore
  27. # Score for each hole
  28. "Score": [4, 4, 5, 4, 4, 5, 4, 5, 4] + [None], # type: ignore
  29. # Represented as relative values except for the last one
  30. "M": n_holes * ["relative"] + ["total"],
  31. }
  32. # Compute difference (Score-Par)
  33. data["Diff"] = [data["Score"][i] - data["Par"][i] for i in range(0, n_holes)] + [None] # type: ignore[index]
  34. # Show positive values in red, and negative values in green
  35. options = {"decreasing": {"marker": {"color": "green"}}, "increasing": {"marker": {"color": "red"}}}
  36. page = """
  37. # Waterfall - Styling
  38. <|{data}|chart|type=waterfall|x=Hole|y=Diff|measure=M|options={options}|>
  39. """
  40. Gui(page).run()