summaryrefslogtreecommitdiffstats
path: root/debian/missing-sources/epoch/src/model.coffee
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 15:26:01 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 15:26:01 +0000
commitef03469fec14f1f0358b690934fc173d744f4e7d (patch)
tree8be439d7b2f1d7c8283b745919b9e66481a950e7 /debian/missing-sources/epoch/src/model.coffee
parentAdding upstream version 5.6.0. (diff)
downloadknot-resolver-debian/5.6.0-1.tar.xz
knot-resolver-debian/5.6.0-1.zip
Adding debian version 5.6.0-1.debian/5.6.0-1debian
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'debian/missing-sources/epoch/src/model.coffee')
-rw-r--r--debian/missing-sources/epoch/src/model.coffee55
1 files changed, 55 insertions, 0 deletions
diff --git a/debian/missing-sources/epoch/src/model.coffee b/debian/missing-sources/epoch/src/model.coffee
new file mode 100644
index 0000000..76f6acd
--- /dev/null
+++ b/debian/missing-sources/epoch/src/model.coffee
@@ -0,0 +1,55 @@
+# Data model for epoch charts. By instantiating a model and passing it to each
+# of the charts on a page the application programmer can update data once and
+# have each of the charts respond accordingly.
+#
+# In addition to setting basic / historical data via the setData method, the
+# model also supports the push method, which when used will cause real-time
+# plots to automatically update and animate.
+class Epoch.Model extends Epoch.Events
+ defaults =
+ dataFormat: null
+
+ # Creates a new Model.
+ # @option options dataFormat The default data fromat for the model.
+ # @option data Initial data for the model.
+ constructor: (options={}) ->
+ super()
+ options = Epoch.Util.defaults options, defaults
+ @dataFormat = options.dataFormat
+ @data = options.data
+ @loading = false
+
+ # Sets the model's data.
+ # @param data Data to set for the model.
+ # @event data:updated Instructs listening charts that new data is available.
+ setData: (data) ->
+ @data = data
+ @trigger 'data:updated'
+
+ # Pushes a new entry into the model.
+ # @param entry Entry to push.
+ # @event data:push Instructs listening charts that a new data entry is available.
+ push: (entry) ->
+ @entry = entry
+ @trigger 'data:push'
+
+ # Determines if the model has data.
+ # @return true if the model has data, false otherwise.
+ hasData: ->
+ @data?
+
+ # Retrieves and formats adata for the specific chart type and data format.
+ # @param [String] type Type of the chart for which to fetch the data.
+ # @param [String, Object] dataFormat (optional) Used to override the model's default data format.
+ # @return The model's data formatted based the parameters.
+ getData: (type, dataFormat) ->
+ dataFormat ?= @dataFormat
+ Epoch.Data.formatData @data, type, dataFormat
+
+ # Retrieves the latest data entry that was pushed into the model.
+ # @param [String] type Type of the chart for which to fetch the data.
+ # @param [String, Object] dataFormat (optional) Used to override the model's default data format.
+ # @return The model's next data entry formatted based the parameters.
+ getNext: (type, dataFormat) ->
+ dataFormat ?= @dataFormat
+ Epoch.Data.formatEntry @entry, type, dataFormat