Initialized and filled a 2D array with all the text objects I need to draw later
This commit is contained in:
parent
cc8a2ffee5
commit
9a016011ad
@ -16,8 +16,8 @@ class @WhiteboardPollModel extends WhiteboardToolModel
|
|||||||
# @param {string} colour the colour of the object
|
# @param {string} colour the colour of the object
|
||||||
# @param {number} thickness the thickness of the object's line(s)
|
# @param {number} thickness the thickness of the object's line(s)
|
||||||
# @param {string} backgroundColor the background color of the poll element
|
# @param {string} backgroundColor the background color of the poll element
|
||||||
# @param {number} vPadding the vertical padding of the poll element ??????????
|
# @param {number} vPadding the vertical padding of the poll element
|
||||||
# @param {number} hPadding the horizontal padding of the poll element ??????????
|
# @param {number} hPadding the horizontal padding of the poll element
|
||||||
make: (startingData) =>
|
make: (startingData) =>
|
||||||
#data needed to create the first base rectangle filled with white color
|
#data needed to create the first base rectangle filled with white color
|
||||||
x1 = startingData.points[0]
|
x1 = startingData.points[0]
|
||||||
@ -29,8 +29,23 @@ class @WhiteboardPollModel extends WhiteboardToolModel
|
|||||||
backgroundColor = "#ffffff"
|
backgroundColor = "#ffffff"
|
||||||
vPadding = 10
|
vPadding = 10
|
||||||
hPadding = 5
|
hPadding = 5
|
||||||
calcFontSize = 20
|
calcFontSize = 30
|
||||||
textArray = [][]
|
votesTotal = 0
|
||||||
|
textArray = []
|
||||||
|
|
||||||
|
#creating an array of text objects for the labels, percentages and number inside line bars
|
||||||
|
if startingData.result? and startingData.result.length > 1
|
||||||
|
#counting the total number of votes
|
||||||
|
for i in [0..startingData.result.length-1]
|
||||||
|
votesTotal += startingData.result[i].num_votes
|
||||||
|
textArray[i] = []
|
||||||
|
#filling the array with proper text objects to display
|
||||||
|
for i in [0..startingData.result.length-1]
|
||||||
|
textArray[i].push(startingData.result[i].key, startingData.result[i].num_votes+"")
|
||||||
|
if votesTotal is 0
|
||||||
|
textArray[i].push("0%")
|
||||||
|
else
|
||||||
|
textArray[i].push(startingData.result[i].num_votes/votesTotal*100+"%")
|
||||||
|
|
||||||
#if coordinates are reversed - change them back
|
#if coordinates are reversed - change them back
|
||||||
if x2 < x1
|
if x2 < x1
|
||||||
@ -47,7 +62,7 @@ class @WhiteboardPollModel extends WhiteboardToolModel
|
|||||||
y = y1 * @gh + @yOffset
|
y = y1 * @gh + @yOffset
|
||||||
width = (x2 * @gw + @xOffset) - x
|
width = (x2 * @gw + @xOffset) - x
|
||||||
height = (y2 * @gh + @yOffset) - y
|
height = (y2 * @gh + @yOffset) - y
|
||||||
#console.log width
|
|
||||||
#creating a base rectangle
|
#creating a base rectangle
|
||||||
@obj = @paper.rect(x, y, width, height, 1)
|
@obj = @paper.rect(x, y, width, height, 1)
|
||||||
@obj.attr "stroke", formatColor(color)
|
@obj.attr "stroke", formatColor(color)
|
||||||
@ -57,27 +72,15 @@ class @WhiteboardPollModel extends WhiteboardToolModel
|
|||||||
shape: "poll_result"
|
shape: "poll_result"
|
||||||
data: [x1, y1, x2, y2, @obj.attrs["stroke"], @obj.attrs["stroke-width"], @obj.attrs["fill"]]
|
data: [x1, y1, x2, y2, @obj.attrs["stroke"], @obj.attrs["stroke-width"], @obj.attrs["fill"]]
|
||||||
|
|
||||||
|
test = [@obj]
|
||||||
|
|
||||||
|
test
|
||||||
|
|
||||||
|
|
||||||
#updated coordinates for inner padding to appear
|
# Update the poll dimensions
|
||||||
x *= 1.01
|
|
||||||
y *= 1.01
|
|
||||||
width = ((x2 * @gw + @xOffset) - x)* 0.98
|
|
||||||
height = ((y2 * @gh + @yOffset) - y)* 0.98
|
|
||||||
|
|
||||||
@obj1 = @paper.rect(x, y, width, height, 20)
|
|
||||||
@obj1.attr "stroke", formatColor(color)
|
|
||||||
@obj1.attr "fill", "#ffffff"
|
|
||||||
@obj1.attr "stroke-width", zoomStroke(formatThickness(thickness))
|
|
||||||
|
|
||||||
test = [@obj, @obj1]
|
|
||||||
|
|
||||||
|
|
||||||
# Update the rectangle dimensions
|
|
||||||
# @param {number} x1 the x value of the top left corner
|
# @param {number} x1 the x value of the top left corner
|
||||||
# @param {number} y1 the y value of the top left corner
|
# @param {number} y1 the y value of the top left corner
|
||||||
# @param {number} x2 the x value of the bottom right corner
|
# @param {number} x2 the x value of the bottom right corner
|
||||||
# @param {number} y2 the y value of the bottom right corner
|
# @param {number} y2 the y value of the bottom right corner
|
||||||
# @param {boolean} square (draw a square or not)
|
# @param {boolean} square (draw a square or not)
|
||||||
update: (startingData) ->
|
update: (startingData) ->
|
||||||
|
|
Loading…
Reference in New Issue
Block a user