mirror of
https://github.com/morrisjs/morris.js.git
synced 2024-11-10 21:36:34 +01:00
Some documentation tweaks.
This commit is contained in:
parent
c1deb0d5ca
commit
4c045c30dd
@ -4,6 +4,7 @@ $ = jQuery
|
||||
|
||||
# Very simple event-emitter class.
|
||||
#
|
||||
# @private
|
||||
class Morris.EventEmitter
|
||||
on: (name, handler) ->
|
||||
unless @handlers?
|
||||
@ -18,8 +19,9 @@ class Morris.EventEmitter
|
||||
handler(args...)
|
||||
|
||||
# Make long numbers prettier by inserting commas.
|
||||
# eg: commas(1234567) -> '1,234,567'
|
||||
#
|
||||
# @example
|
||||
# Morris.commas(1234567) -> '1,234,567'
|
||||
Morris.commas = (num) ->
|
||||
if num is null
|
||||
"n/a"
|
||||
@ -33,6 +35,8 @@ Morris.commas = (num) ->
|
||||
ret += strabsnum.slice(intnum.length)
|
||||
ret
|
||||
|
||||
# zero-pad numbers to two characters wide
|
||||
# Zero-pad numbers to two characters wide.
|
||||
#
|
||||
Morris.pad2 = (number) -> (if number < 10 then '0' else '') + number
|
||||
# @example
|
||||
# Morris.pad2(1) -> '01'
|
||||
Morris.pad2 = (number) -> (if number < 10 then '0' else '') + number
|
||||
|
@ -1,3 +1,13 @@
|
||||
# Donut charts.
|
||||
#
|
||||
# @example
|
||||
# Morris.Donut({
|
||||
# el: $('#donut-container'),
|
||||
# data: [
|
||||
# { label: 'yin', value: 50 },
|
||||
# { label: 'yang', value: 50 }
|
||||
# ]
|
||||
# });
|
||||
class Morris.Donut
|
||||
colors: [
|
||||
'#0B62A4'
|
||||
@ -12,6 +22,8 @@ class Morris.Donut
|
||||
'#042135'
|
||||
]
|
||||
|
||||
# Create and render a donut chart.
|
||||
#
|
||||
constructor: (options) ->
|
||||
if not (this instanceof Morris.Donut)
|
||||
return new Morris.Donut(options)
|
||||
@ -34,12 +46,17 @@ class Morris.Donut
|
||||
|
||||
@el.addClass 'graph-initialised'
|
||||
|
||||
# the raphael drawing instance
|
||||
@redraw()
|
||||
|
||||
# Clear and redraw the chart.
|
||||
#
|
||||
# If you need to re-size your charts, call this method after changing the
|
||||
# size of the container element.
|
||||
redraw: ->
|
||||
@el.clear()
|
||||
|
||||
@r = new Raphael(@el[0])
|
||||
|
||||
@draw()
|
||||
|
||||
draw: ->
|
||||
cx = @el.width() / 2
|
||||
cy = @el.height() / 2
|
||||
w = (Math.min(cx, cy) - 10) / 3
|
||||
@ -71,11 +88,13 @@ class Morris.Donut
|
||||
break
|
||||
idx += 1
|
||||
|
||||
# @private
|
||||
select: (segment) =>
|
||||
s.deselect() for s in @segments
|
||||
segment.select()
|
||||
@setLabels segment.data.label, Morris.commas(segment.data.value)
|
||||
|
||||
# @private
|
||||
setLabels: (label1, label2) ->
|
||||
inner = (Math.min(@el.width() / 2, @el.height() / 2) - 10) * 2 / 3
|
||||
maxWidth = 1.8 * inner
|
||||
@ -90,6 +109,10 @@ class Morris.Donut
|
||||
text2scale = Math.min(maxWidth / text2bbox.width, maxHeightBottom / text2bbox.height)
|
||||
@text2.attr(transform: "S#{text2scale},#{text2scale},#{text2bbox.x + text2bbox.width / 2},#{text2bbox.y}")
|
||||
|
||||
|
||||
# A segment within a donut chart.
|
||||
#
|
||||
# @private
|
||||
class Morris.DonutSegment extends Morris.EventEmitter
|
||||
constructor: (@cx, @cy, @inner, @outer, p0, p1, @color, @data) ->
|
||||
@sin_p0 = Math.sin(p0)
|
||||
@ -140,4 +163,4 @@ class Morris.DonutSegment extends Morris.EventEmitter
|
||||
if @selected
|
||||
@seg.animate(path: @path, 150, '<>')
|
||||
@arc.animate(opacity: 0, 150, '<>')
|
||||
@selected = false
|
||||
@selected = false
|
||||
|
@ -1,7 +1,6 @@
|
||||
class Morris.Line
|
||||
# Initialise the graph.
|
||||
#
|
||||
# @param {Object} options
|
||||
constructor: (options) ->
|
||||
if not (this instanceof Morris.Line)
|
||||
return new Morris.Line(options)
|
||||
@ -92,7 +91,7 @@ class Morris.Line
|
||||
xLabels: 'auto'
|
||||
xLabelFormat: null
|
||||
|
||||
# Pre-process data
|
||||
# Update the data series and redraw the chart.
|
||||
#
|
||||
setData: (data, redraw = true) ->
|
||||
# shallow copy & sort data
|
||||
@ -168,6 +167,7 @@ class Morris.Line
|
||||
|
||||
# Do any size-related calculations
|
||||
#
|
||||
# @private
|
||||
calc: ->
|
||||
w = @el.width()
|
||||
h = @el.height()
|
||||
@ -201,17 +201,21 @@ class Morris.Line
|
||||
|
||||
# quick translation helpers
|
||||
#
|
||||
# @private
|
||||
transX: (x) =>
|
||||
if @xvals.length is 1
|
||||
@left + @width / 2
|
||||
else
|
||||
@left + (x - @xmin) * @dx
|
||||
|
||||
# @private
|
||||
transY: (y) =>
|
||||
return @options.marginTop + @height - (y - @ymin) * @dy
|
||||
|
||||
# Clear and redraw the graph
|
||||
# Clear and redraw the chart.
|
||||
#
|
||||
# If you need to re-size your charts, call this method after changing the
|
||||
# size of the container element.
|
||||
redraw: ->
|
||||
@r.clear()
|
||||
@calc()
|
||||
@ -222,6 +226,7 @@ class Morris.Line
|
||||
|
||||
# draw the grid, and axes labels
|
||||
#
|
||||
# @private
|
||||
drawGrid: ->
|
||||
# draw y axis labels, horizontal lines
|
||||
firstY = @ymin
|
||||
@ -271,6 +276,7 @@ class Morris.Line
|
||||
|
||||
# draw the data series
|
||||
#
|
||||
# @private
|
||||
drawSeries: ->
|
||||
for i in [@seriesCoords.length-1..0]
|
||||
coords = $.map(@seriesCoords[i], (c) -> c)
|
||||
@ -293,6 +299,7 @@ class Morris.Line
|
||||
|
||||
# create a path for a data series
|
||||
#
|
||||
# @private
|
||||
createPath: (coords, top, left, bottom, right) ->
|
||||
path = ""
|
||||
if @options.smooth
|
||||
@ -317,6 +324,7 @@ class Morris.Line
|
||||
|
||||
# calculate a gradient at each point for a series of points
|
||||
#
|
||||
# @private
|
||||
gradients: (coords) ->
|
||||
$.map coords, (c, i) ->
|
||||
if i is 0
|
||||
@ -328,6 +336,7 @@ class Morris.Line
|
||||
|
||||
# draw the hover tooltip
|
||||
#
|
||||
# @private
|
||||
drawHover: ->
|
||||
# hover labels
|
||||
@hoverHeight = @options.hoverFontSize * 1.5 * (@series.length + 1)
|
||||
@ -351,6 +360,7 @@ class Morris.Line
|
||||
@yLabels.push(yLabel)
|
||||
@hoverSet.push(yLabel)
|
||||
|
||||
# @private
|
||||
updateHover: (index) =>
|
||||
@hoverSet.show()
|
||||
@xLabel.attr('text', @columnLabels[index])
|
||||
@ -375,9 +385,11 @@ class Morris.Line
|
||||
xloc = Math.max @left + maxLabelWidth / 2 + @options.hoverPaddingX, xloc
|
||||
@hoverSet.attr 'transform', "t#{xloc},#{yloc}"
|
||||
|
||||
# @private
|
||||
hideHover: ->
|
||||
@hoverSet.hide()
|
||||
|
||||
# @private
|
||||
hilight: (index) =>
|
||||
if @prevHilight isnt null and @prevHilight isnt index
|
||||
for i in [0..@seriesPoints.length-1]
|
||||
@ -392,6 +404,7 @@ class Morris.Line
|
||||
if index is null
|
||||
@hideHover()
|
||||
|
||||
# @private
|
||||
updateHilight: (x) =>
|
||||
x -= @el.offset().left
|
||||
for hoverIndex in [@hoverMargins.length..0]
|
||||
@ -399,17 +412,20 @@ class Morris.Line
|
||||
@hilight hoverIndex
|
||||
break
|
||||
|
||||
# @private
|
||||
measureText: (text, fontSize = 12) ->
|
||||
tt = @r.text(100, 100, text).attr('font-size', fontSize)
|
||||
ret = tt.getBBox()
|
||||
tt.remove()
|
||||
return ret
|
||||
|
||||
# @private
|
||||
yLabelFormat: (label) ->
|
||||
"#{@options.preUnits}#{Morris.commas(label)}#{@options.postUnits}"
|
||||
|
||||
|
||||
# parse a date into a javascript timestamp
|
||||
# Parse a date into a javascript timestamp
|
||||
#
|
||||
#
|
||||
Morris.parseDate = (date) ->
|
||||
if typeof date is 'number'
|
||||
@ -497,6 +513,7 @@ Morris.parseDate = (date) ->
|
||||
|
||||
# generate a series of label, timestamp pairs for x-axis labels
|
||||
#
|
||||
# @private
|
||||
Morris.labelSeries = (dmin, dmax, pxwidth, specName, xLabelFormat) ->
|
||||
ddensity = 200 * (dmax - dmin) / pxwidth # seconds per `margin` pixels
|
||||
d0 = new Date(dmin)
|
||||
@ -523,12 +540,14 @@ Morris.labelSeries = (dmin, dmax, pxwidth, specName, xLabelFormat) ->
|
||||
spec.incr(d)
|
||||
return ret
|
||||
|
||||
# @private
|
||||
minutesSpecHelper = (interval) ->
|
||||
span: interval * 60 * 1000
|
||||
start: (d) -> new Date(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours())
|
||||
fmt: (d) -> "#{Morris.pad2(d.getHours())}:#{Morris.pad2(d.getMinutes())}"
|
||||
incr: (d) -> d.setMinutes(d.getMinutes() + interval)
|
||||
|
||||
# @private
|
||||
secondsSpecHelper = (interval) ->
|
||||
span: interval * 1000
|
||||
start: (d) -> new Date(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes())
|
||||
@ -567,4 +586,4 @@ Morris.AUTO_LABEL_ORDER = [
|
||||
"year", "month", "day", "hour",
|
||||
"30min", "15min", "10min", "5min", "minute",
|
||||
"30sec", "15sec", "10sec", "5sec", "second"
|
||||
]
|
||||
]
|
||||
|
2
morris.min.js
vendored
2
morris.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user