This repository has been archived on 2025-11-02. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
dashboard/widgets/timeline/timeline.coffee
2022-09-20 00:27:25 +01:00

26 lines
1.2 KiB
CoffeeScript

class Dashing.Timeline extends Dashing.Widget
ready: ->
@renderTimeline(@get('events'))
onData: (data) ->
# Handle incoming data
# You can access the html node of this widget with `@node` E8F770 616161
# Example: $(@node).fadeOut().fadeIn() will make the node flash each time data comes in.
if data.events
@renderTimeline(data.events)
renderTimeline: (events) ->
# Margins: zero if not set or the same as the opposite margin
# (you likely want this to keep the chart centered within the widget)
left = @get('leftMargin') || 0
right = @get('rightMargin') || left
top = @get('topMargin') || 10
bottom = @get('bottomMargin') || top
container = $(@node).parent()
# Gross hacks. Let's fix this.
width = (Dashing.widget_base_dimensions[0] * container.data("sizex")) + Dashing.widget_margins[0] * 2 * (container.data("sizex") - 1) - left - right
height = (Dashing.widget_base_dimensions[1] * container.data("sizey")) - ($(@node).find("h1").outerHeight() + 12) - top - bottom
id = "." + @get('id')
TimeKnots.draw(id, events, {horizontalLayout: false, color: "#222222", height: height, width: width, showLabels: true, labelFormat:"%H:%M"});