ChartLegend.coffee 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. class ChartLegend extends Class
  2. constructor: ->
  3. @items_left = []
  4. @items_right = []
  5. renderItem: (item) =>
  6. @i += 1
  7. item.dot ?= "\u25CF"
  8. value = item.getValue()
  9. hidden = not value
  10. if item.post
  11. value += " #{item.post}"
  12. if item.type == "ratio"
  13. h("div.legend-item", {classes: {hidden: hidden}}, [
  14. h("div.title", item.title),
  15. h("div.value", [
  16. h("span", {updateAnimation: Animation.show, delay: @i * 0.1}, Math.round(value * 10) / 10),
  17. h("div.dots-container", [
  18. h("span.dots.dots-fg", {style: "width: #{Math.min(value, 5) * 11.5}px; color: #{item.color}"}, item.dot.repeat(5)),
  19. h("span.dots.dots-bg", item.dot.repeat(5))
  20. ])
  21. ])
  22. ])
  23. else
  24. h("div.legend-item", {classes: {hidden: hidden}}, [
  25. h("div.title", [h("span.dot", {style: "color: #{item.color}"}, "#{item.dot} "), item.title]),
  26. h("div.value", {updateAnimation: Animation.show, delay: @i * 0.1}, value)
  27. ])
  28. render: ->
  29. @i = 0
  30. h("div.ChartLegend",
  31. h("div.legend-items.align-left", @items_left.map(@renderItem))
  32. h("div.legend-items.align-right", @items_right.map(@renderItem))
  33. )
  34. window.ChartLegend = ChartLegend