Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit aa0d7ee

Browse files
author
Monte Goulding
committed
Add markerStyles and showLines properties to line graph widget
1 parent aae3b33 commit aa0d7ee

File tree

3 files changed

+171
-11
lines changed

3 files changed

+171
-11
lines changed

extensions/widgets/graph/graph.lcb

Lines changed: 153 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use com.livecode.library.widgetutils
4040

4141
-- adding metadata to ensure the extension displays correctly in LiveCode
4242
metadata author is "LiveCode"
43-
metadata version is "1.0.2"
43+
metadata version is "1.1.0"
4444
metadata title is "Line Graph"
4545
metadata preferredSize is "300,175"
4646
metadata svgicon is "M50.6,27.2h-2.2v-3.3l0.8-0.5l-0.2-0.3h2.9v-1h-3.5v-5h3.5v-1h-3.5v-5h3.5v-1h-3.5v-5h3.5v-1h-3.5V1.8h-1v2.4h-10V1.8h-1v2.4h-10V1.8h-1v2.4h-10V1.8h-1v2.4H5V2.5C5,1.1,3.9,0,2.5,0S0,1.1,0,2.5v29.7h50.6c1.4,0,2.5-1.1,2.5-2.5C53.1,28.4,52,27.2,50.6,27.2z M47.4,27.2h-10v-4.1h8l1.2,1.9l0.8-0.5V27.2z M15.4,15.2l1.4,0.9h-1.4V15.2z M14.4,17.1v5h-4.2l3.6-5H14.4z M15.4,17.1h2.9l7.1,4.6v0.4h-10V17.1z M26.4,17.1h0.1l-0.1,0.2V17.1z M25.4,18.1l-1.6-1h1.6V18.1z M26.4,22l4-4.9h6v5h-10V22z M37.4,17.1h4.2l3.2,5h-7.4V17.1z M37.4,16.1v-5h0.4l3.2,5H37.4z M36.4,10.1h-0.1l0.1-0.2V10.1z M36.4,11.1v5h-5.1l4.2-5H36.4z M27.4,16.1h-1v-5h5.1L27.4,16.1z M25.4,16.1h-3.1l-6.9-4.5v-0.5h10V16.1z M14.4,11.3l-3.5,4.9H5v-5h9.4V11.3z M10.1,17.1l-3.6,5H5v-5H10.1z M5.7,23.1l-0.7,1v-1H5.7z M9.5,23.1h4.9v4.1H6.5L9.5,23.1z M15.4,23.1h10v4.1h-10V23.1z M26.4,23.1h10v4.1h-10V23.1z M47.4,20.7l-2.3-3.6h2.3V20.7z M47.4,16.1h-2.9l-3.2-5h6.1V16.1z M47.4,10.1h-6.7l-3.2-5h9.9V10.1z M36.4,5.1v0.1l-4,4.9h-6v-5H36.4z M25.4,5.1v5h-10v-5H25.4z M14.4,5.1v5H5v-5H14.4z"
@@ -67,8 +67,8 @@ The <graphData> is the data to be displayed by the graph widget.
6767

6868
Each line of the <graphData> should be a a comma delimited list. The
6969
first item of each line is the label for that point on the x-axis.
70-
The second and following items are the values corresponding to that
71-
label for one of the graph's lines.
70+
The second and following items are the values for each series of data
71+
to plot.
7272
*/
7373
property graphData get getData set setData
7474
metadata graphData.editor is "com.livecode.pi.text"
@@ -144,6 +144,61 @@ property graphYLines get mGridVShow set setYLinesVisibility
144144
metadata graphYLines.default is "true"
145145
metadata graphYLines.label is "Vertical grid lines"
146146

147+
/**
148+
Summary: Whether chart lines are displayed
149+
150+
Syntax:
151+
set the showLines of <widget> to { true | false }
152+
get the showLines of <widget>
153+
154+
Value (boolean): True if lines should be shown; false otherwise
155+
156+
Description:
157+
If true, the graph widget will draw graph lines on the graph.
158+
159+
Related: markerStyles (property)
160+
161+
*/
162+
property showLines get mLinesShow set SetLineVisibility
163+
metadata showLines.default is "true"
164+
metadata showLines.label is "Show graph lines"
165+
metadata showLines.section is "Basic"
166+
167+
/**
168+
Summary: Set the marker style for each data series
169+
170+
Syntax:
171+
set the markerStyles of <widget> to { <string> | empty }
172+
get the markerStyles of <widget>
173+
174+
Summary: The marker styles for drawing vertices on the graph
175+
176+
Value(String): A line-delimited list of the marker styles for each line
177+
on the graph
178+
179+
Description:
180+
The <markerStyles> are the marker styles of each line in the graph
181+
widget.
182+
183+
If set to empty then no markers will be shown and
184+
showLines will be set to true. Available marker styles may be one of:
185+
186+
- "filled circle"
187+
- "filled square"
188+
- "filled diamond"
189+
- "circle"
190+
- "square"
191+
- "diamond"
192+
193+
By default the markerStyles will repeat in the above order.
194+
195+
Related: showLines (property)
196+
*/
197+
property markerStyles get GetMarkerStyles set SetMarkerStyles
198+
metadata markerStyles.default is "filled circle\nfilled square\nfilled diamond"
199+
metadata markerStyles.editor is "com.livecode.pi.text"
200+
metadata markerStyles.label is "Marker styles"
201+
147202
/**
148203
Summary: The coordinates of a highlighted point on the graph
149204

@@ -196,6 +251,9 @@ private variable mLegendShow as Boolean
196251
private variable mLabelXShow as Boolean
197252
private variable mLabelYShow as Boolean
198253
private variable mVerticesShow as Boolean
254+
private variable mLinesShow as Boolean
255+
256+
private variable mMarkerStyles as List
199257

200258
private variable mYMax as Number
201259
private variable mYMin as Number
@@ -244,8 +302,11 @@ public handler OnCreate() returns nothing
244302
put true into mLegendShow
245303
put true into mLabelXShow
246304
put true into mLabelYShow
305+
put true into mLinesShow
247306
put true into mVerticesShow
248307

308+
put [] into mMarkerStyles
309+
249310
put my height into mHeight
250311
put my width into mWidth
251312

@@ -293,6 +354,9 @@ public handler OnSave(out rProperties as Array)
293354
put mGridVShow into rProperties["graphYLines"]
294355
put GetHilitedCoordinates() into rProperties["hilitedCoordinates"]
295356
put mHilitedCoordinatesColor into rProperties["hilitedCoordinatesColor"]
357+
put mVerticesShow into rProperties["showMarkers"]
358+
put mMarkerStyles into rProperties["markerStyles"]
359+
put mLinesShow into rProperties["showLines"]
296360
end handler
297361

298362
-- Process saved data array and re-set properties accordingly
@@ -315,6 +379,16 @@ public handler OnLoad(in pProperties as Array)
315379
if "hilitedCoordinatesColor" is among the keys of pProperties then
316380
SetHilitedCoordinatesColor(pProperties["hilitedCoordinatesColor"])
317381
end if
382+
if "showLines" is among the keys of pProperties then
383+
SetLineVisibility(pProperties["showLines"])
384+
end if
385+
if "showMarkers" is among the keys of pProperties then
386+
put pProperties["showMarkers"] into mVerticesShow
387+
end if
388+
if "markerStyles" is among the keys of pProperties then
389+
put pProperties["markerStyles"] into mMarkerStyles
390+
end if
391+
EnsureMarkerStyles()
318392
end handler
319393

320394
----------
@@ -374,6 +448,7 @@ public handler setData(in pData as String) returns nothing
374448
put tNewData into mData
375449
put [] into mHilitedCoordinates
376450
put true into mRecalculateAll
451+
EnsureMarkerStyles()
377452
redraw all
378453
end handler
379454
----------
@@ -410,6 +485,50 @@ public handler setYLinesVisibility(in pShowYGridLines as Boolean) returns nothin
410485
redraw all
411486
end handler
412487

488+
public handler SetLineVisibility(in pShowLines as Boolean) returns nothing
489+
put pShowLines into mLinesShow
490+
if not pShowLines then
491+
put true into mVerticesShow
492+
EnsureMarkerStyles()
493+
end if
494+
redraw all
495+
end handler
496+
497+
public handler GetMarkerStyles() returns String
498+
if mMarkerStyles is [] then
499+
return ""
500+
end if
501+
502+
variable tMarkerStyles as String
503+
combine mMarkerStyles with newline into tMarkerStyles
504+
return tMarkerStyles
505+
end handler
506+
507+
public handler SetMarkerStyles(in pMarkerStyles as String) returns nothing
508+
if pMarkerStyles is "" then
509+
put true into mLinesShow
510+
put [] into mMarkerStyles
511+
put false into mVerticesShow
512+
else
513+
split pMarkerStyles by newline into mMarkerStyles
514+
put true into mVerticesShow
515+
EnsureMarkerStyles()
516+
end if
517+
redraw all
518+
end handler
519+
520+
public handler EnsureMarkerStyles() returns nothing
521+
if mVerticesShow and the number of elements in mMarkerStyles < the number of elements in mData - 1 then
522+
variable tStyles as List
523+
put ["filled circle", "filled square", "filled diamond", "circle", "square", "diamond"] into tStyles
524+
525+
variable tCount as Integer
526+
repeat with tCount from the number of elements in mMarkerStyles + 1 up to the number of elements in mData - 1
527+
push tStyles[tCount mod 6 + 1] onto back of mMarkerStyles
528+
end repeat
529+
end if
530+
end handler
531+
413532
public handler GetHilitedCoordinates() returns String
414533
if mHilitedCoordinates is [] then
415534
return ""
@@ -944,20 +1063,43 @@ private handler drawGraph() returns nothing
9441063
put the bottom of mGridRect - the height of mGridRect * tHeightRatio into tPointY
9451064
put point [tPointX, tPointY] into tPoint
9461065

947-
if tPointIndex is 1 then
948-
move to tPoint on tPath
949-
else
950-
line to tPoint on tPath
1066+
if mLinesShow is true then
1067+
if tPointIndex is 1 then
1068+
move to tPoint on tPath
1069+
else
1070+
line to tPoint on tPath
1071+
end if
9511072
end if
9521073

9531074
// Draw vertices
9541075
if mVerticesShow is true then
955-
add circle path centered at tPoint with radius 3 to tPathVertices
956-
end if
1076+
variable tMarkerPath as Path
1077+
if mMarkerStyles[tGraphLine - 1] contains "circle" then
1078+
put circle path centered at point [0,0] with radius 3 into tMarkerPath
1079+
else
1080+
put rectangle path of rectangle [-3,-3,3,3] into tMarkerPath
1081+
end if
1082+
1083+
if mMarkerStyles[tGraphLine - 1] contains "diamond" then
1084+
rotate tMarkerPath by 45
1085+
end if
1086+
1087+
translate tMarkerPath by [tPointX, tPointY]
1088+
add tMarkerPath to tPathVertices
1089+
end if
9571090
end if
9581091
end repeat
959-
stroke tPath on this canvas
960-
fill tPathVertices on this canvas
1092+
if mLinesShow is true then
1093+
stroke tPath on this canvas
1094+
end if
1095+
1096+
if mVerticesShow is true and mMarkerStyles[tGraphLine - 1] is not "" then
1097+
if mMarkerStyles[tGraphLine - 1] contains "filled" then
1098+
fill tPathVertices on this canvas
1099+
else
1100+
stroke tPathVertices on this canvas
1101+
end if
1102+
end if
9611103
end repeat
9621104

9631105
// Draw Axis lines
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Marker styles
2+
3+
The markerStyles of the line graph can now be set to a return delimited
4+
list of:
5+
6+
- circle
7+
- filled circle
8+
- square
9+
- filled square
10+
- diamond
11+
- filled diamond
12+
13+
Setting the markerStyles to empty will cause the lines of the chart to
14+
draw without markers and set the showLines of the chart to true.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Show and hide the graph lines
2+
3+
Setting the showLines of the graph to false will draw the point markers
4+
but not the connecting lines turning the graph into a scatter plot.

0 commit comments

Comments
 (0)