Mercurial > octave
comparison scripts/plot/appearance/legend.m @ 30622:18a9b3c7b63b
legend.m: Implement "itemhitfcn" property
* gendpropdoc.m: Document new property
* legend.m (execute_item_hit): New callback function.
(create_item): Change "buttondownfcn" of legend item objects to run
execute_item_hit.
author | Pantxo Diribarne <pantxo.diribarne@gmail.com> |
---|---|
date | Sun, 09 Jan 2022 16:57:26 +0100 |
parents | 796f54d4ddbf |
children | 1aa0456ecb18 |
comparison
equal
deleted
inserted
replaced
30621:7fa86ceb8077 | 30622:18a9b3c7b63b |
---|---|
306 ht = __go_text__ (opts.axes_handles(1), "tag", "__legend_watcher__", | 306 ht = __go_text__ (opts.axes_handles(1), "tag", "__legend_watcher__", |
307 "visible", "off", "handlevisibility", "off", | 307 "visible", "off", "handlevisibility", "off", |
308 "deletefcn", {@reset_cb, hl}); | 308 "deletefcn", {@reset_cb, hl}); |
309 | 309 |
310 ## Listeners to foreign objects properties are stored for later | 310 ## Listeners to foreign objects properties are stored for later |
311 ## deletion in "delfunction" | 311 ## deletion in "reset_cb" |
312 hax = opts.axes_handles(1); | 312 hax = opts.axes_handles(1); |
313 hf = ancestor (hax, "figure"); | 313 hf = ancestor (hax, "figure"); |
314 | 314 |
315 add_safe_listener (hl, hf, "colormap", ... | 315 add_safe_listener (hl, hf, "colormap", ... |
316 @(~, ~) set (hl, "colormap", get (hax, "colormap"))); | 316 @(~, ~) set (hl, "colormap", get (hax, "colormap"))); |
348 | 348 |
349 addlistener (hl, "string", @update_string_cb); | 349 addlistener (hl, "string", @update_string_cb); |
350 | 350 |
351 addlistener (hl, "textcolor", ... | 351 addlistener (hl, "textcolor", ... |
352 @(h, ~) set (findobj (h, "type", "text"), ... | 352 @(h, ~) set (findobj (h, "type", "text"), ... |
353 "color", get (hl, "textcolor"))); | 353 "color", get (hl, "textcolor"))); |
354 | 354 |
355 addlistener (hl, "visible", @update_visible_cb); | 355 addlistener (hl, "visible", @update_visible_cb); |
356 | 356 |
357 else | 357 else |
358 | 358 |
1074 switch (typ) | 1074 switch (typ) |
1075 case {"line", "__errplot__", "__quiver__", "__stem__"} | 1075 case {"line", "__errplot__", "__quiver__", "__stem__"} |
1076 | 1076 |
1077 ## Main line | 1077 ## Main line |
1078 vals = get (hplt(1), lprops); | 1078 vals = get (hplt(1), lprops); |
1079 hicon = __go_line__ (hl, [lprops; vals]{:}); | 1079 hicon = __go_line__ (hl, [lprops; vals]{:}, ... |
1080 "pickableparts", "all", ... | |
1081 "buttondownfcn", ... | |
1082 {@execute_itemhit, hl, hplt, "icon"}); | |
1083 | |
1080 addproperty ("markerxdata", hicon, "double", 0); | 1084 addproperty ("markerxdata", hicon, "double", 0); |
1081 addproperty ("markerydata", hicon, "double", 0); | 1085 addproperty ("markerydata", hicon, "double", 0); |
1082 | 1086 |
1083 ## Additional line for the marker | 1087 ## Additional line for the marker |
1084 vals = get (hplt(end), mprops); | 1088 vals = get (hplt(end), mprops); |
1085 hmarker = __go_line__ (hl, "handlevisibility", "off", ... | 1089 hmarker = __go_line__ (hl, "handlevisibility", "off", ... |
1086 "xdata", 0, "ydata", 0, [mprops; vals]{:}); | 1090 "xdata", 0, "ydata", 0, [mprops; vals]{:}, ... |
1091 "pickableparts", "all", ... | |
1092 "buttondownfcn", ... | |
1093 {@execute_itemhit, hl, hplt, "icon"}); | |
1087 update_marker_cb (hmarker); | 1094 update_marker_cb (hmarker); |
1088 | 1095 |
1089 ## Listeners | 1096 ## Listeners |
1090 safe_property_link (hplt(1), hicon, lprops); | 1097 safe_property_link (hplt(1), hicon, lprops); |
1091 safe_property_link (hplt(end), hmarker, mprops); | 1098 safe_property_link (hplt(end), hmarker, mprops); |
1125 ## sizedata and cdata may be N-by-1 vectors or N-by-3 (RGB) martrices. | 1132 ## sizedata and cdata may be N-by-1 vectors or N-by-3 (RGB) martrices. |
1126 ## Take the average for the icon. | 1133 ## Take the average for the icon. |
1127 vals {end-1} = mean (vals {end-1}, 1); | 1134 vals {end-1} = mean (vals {end-1}, 1); |
1128 vals {end} = mean (vals {end}, 1); | 1135 vals {end} = mean (vals {end}, 1); |
1129 | 1136 |
1130 hicon = __go_scatter__ (hl, [all_sprops; vals]{:}); | 1137 hicon = __go_scatter__ (hl, [all_sprops; vals]{:}, ... |
1138 "pickableparts", "all", ... | |
1139 "buttondownfcn", ... | |
1140 {@execute_itemhit, hl, hplt, "icon"}); | |
1131 | 1141 |
1132 ## Simple Listeners | 1142 ## Simple Listeners |
1133 safe_property_link (hplt(1), hicon, sprops); | 1143 safe_property_link (hplt(1), hicon, sprops); |
1134 | 1144 |
1135 ## Listener to sizedata | 1145 ## Listener to sizedata |
1149 case "__contour__" | 1159 case "__contour__" |
1150 | 1160 |
1151 ## Main patch | 1161 ## Main patch |
1152 | 1162 |
1153 vals = get (hplt(1), pprops); | 1163 vals = get (hplt(1), pprops); |
1154 hicon = __go_patch__ (hl, [pprops; vals]{:}); | 1164 hicon = __go_patch__ (hl, [pprops; vals]{:}, ... |
1165 "pickableparts", "all", ... | |
1166 "buttondownfcn", ... | |
1167 {@execute_itemhit, hl, hplt, "icon"}); | |
1155 | 1168 |
1156 addproperty ("innerxdata", hicon, "any", 0); | 1169 addproperty ("innerxdata", hicon, "any", 0); |
1157 addproperty ("innerydata", hicon, "any", 0); | 1170 addproperty ("innerydata", hicon, "any", 0); |
1158 | 1171 |
1159 ## Additional patch for the inner contour | 1172 ## Additional patch for the inner contour |
1160 vals = get (hplt(end), pprops); | 1173 vals = get (hplt(end), pprops); |
1161 htmp = __go_patch__ (hl, "handlevisibility", "off", ... | 1174 htmp = __go_patch__ (hl, "handlevisibility", "off", ... |
1162 "xdata", 0, "ydata", 0, [pprops; vals]{:}); | 1175 "xdata", 0, "ydata", 0, [pprops; vals]{:}, ... |
1176 "pickableparts", "all", ... | |
1177 "buttondownfcn", ... | |
1178 {@execute_itemhit, hl, hplt, "icon"}); | |
1163 | 1179 |
1164 ## Listeners | 1180 ## Listeners |
1165 safe_property_link (hplt(1), hicon, pprops); | 1181 safe_property_link (hplt(1), hicon, pprops); |
1166 safe_property_link (hplt(end), htmp, pprops); | 1182 safe_property_link (hplt(end), htmp, pprops); |
1167 addlistener (hicon, "ydata", ... | 1183 addlistener (hicon, "ydata", ... |
1175 | 1191 |
1176 setappdata (hicon, "__creator__", typ); | 1192 setappdata (hicon, "__creator__", typ); |
1177 | 1193 |
1178 endswitch | 1194 endswitch |
1179 | 1195 |
1180 htxt = __go_text__ (hl, txtpval{:}, "string", str); | 1196 htxt = __go_text__ (hl, txtpval{:}, "string", str, ... |
1197 "pickableparts", "all", ... | |
1198 "buttondownfcn", {@execute_itemhit, hl, hplt, "label"}); | |
1199 | |
1200 set (htxt, "buttondownfcn", {@execute_itemhit, hl, hplt, "label"}); | |
1181 | 1201 |
1182 addproperty ("peer_object", htxt, "double", base_hplt); | 1202 addproperty ("peer_object", htxt, "double", base_hplt); |
1183 addproperty ("peer_object", hicon, "double", base_hplt); | 1203 addproperty ("peer_object", hicon, "double", base_hplt); |
1204 | |
1205 endfunction | |
1206 | |
1207 function execute_itemhit (h, ~, hl, hplt, region) | |
1208 | |
1209 fcn = get (hl, "itemhitfcn"); | |
1210 | |
1211 if (! isempty (fcn)) | |
1212 evt = struct ("Peer", hplt, "Region", region, ... | |
1213 "SelectionType", get (gcbf (), "selectiontype"), ... | |
1214 "Source", hl, "EventName", "ItemHit"); | |
1215 fcn (hl, evt) | |
1216 endif | |
1184 | 1217 |
1185 endfunction | 1218 endfunction |
1186 | 1219 |
1187 function safe_property_link (h1, h2, props) | 1220 function safe_property_link (h1, h2, props) |
1188 | 1221 |