plexora 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (248) hide show
  1. plexora/__init__.py +129 -0
  2. plexora/__main__.py +15 -0
  3. plexora/_url.py +105 -0
  4. plexora/api/__init__.py +55 -0
  5. plexora/api/dataset.py +398 -0
  6. plexora/api/http.py +19 -0
  7. plexora/api/plugin.py +541 -0
  8. plexora/api/store.py +221 -0
  9. plexora/cli.py +777 -0
  10. plexora/client/dist/354_bundle.js +2 -0
  11. plexora/client/dist/354_bundle.js.LICENSE.txt +20 -0
  12. plexora/client/dist/418_bundle.js +2 -0
  13. plexora/client/dist/418_bundle.js.LICENSE.txt +1 -0
  14. plexora/client/dist/693b935cb1f907814be9c6199a68c217.svg +19 -0
  15. plexora/client/dist/713c134ff47cd328a5b711526f151082.svg +18 -0
  16. plexora/client/dist/770_bundle.js +1 -0
  17. plexora/client/dist/ff743f408972e0e96ca9153ed5ae4c83.svg +23 -0
  18. plexora/client/dist/vendor_bundle.js +2 -0
  19. plexora/client/dist/vendor_bundle.js.LICENSE.txt +308 -0
  20. plexora/client/external/openseadragon-bin-2.4.0/LICENSE.txt +28 -0
  21. plexora/client/external/openseadragon-bin-2.4.0/canvas-overlay-hd.js +140 -0
  22. plexora/client/external/openseadragon-bin-2.4.0/changelog.txt +501 -0
  23. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/.gitattributes +17 -0
  24. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/LICENSE.txt +116 -0
  25. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/Photoshop/Toolbar.png +0 -0
  26. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/Photoshop/fullpage.psd +0 -0
  27. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/Photoshop/home.psd +0 -0
  28. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/Photoshop/next.psd +0 -0
  29. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/Photoshop/previous.psd +0 -0
  30. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/Photoshop/rotateleft.psd +0 -0
  31. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/Photoshop/rotateright.psd +0 -0
  32. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/Photoshop/zoom.psd +0 -0
  33. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/README.md +9 -0
  34. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/fullpage_grouphover.png +0 -0
  35. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/fullpage_hover.png +0 -0
  36. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/fullpage_pressed.png +0 -0
  37. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/fullpage_rest.png +0 -0
  38. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/home_grouphover.png +0 -0
  39. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/home_hover.png +0 -0
  40. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/home_pressed.png +0 -0
  41. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/home_rest.png +0 -0
  42. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/next_grouphover.png +0 -0
  43. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/next_hover.png +0 -0
  44. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/next_pressed.png +0 -0
  45. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/next_rest.png +0 -0
  46. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/previous_grouphover.png +0 -0
  47. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/previous_hover.png +0 -0
  48. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/previous_pressed.png +0 -0
  49. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/previous_rest.png +0 -0
  50. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/rotateleft_grouphover.png +0 -0
  51. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/rotateleft_hover.png +0 -0
  52. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/rotateleft_pressed.png +0 -0
  53. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/rotateleft_rest.png +0 -0
  54. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/rotateright_grouphover.png +0 -0
  55. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/rotateright_hover.png +0 -0
  56. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/rotateright_pressed.png +0 -0
  57. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/rotateright_rest.png +0 -0
  58. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/zoomin_grouphover.png +0 -0
  59. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/zoomin_hover.png +0 -0
  60. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/zoomin_pressed.png +0 -0
  61. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/zoomin_rest.png +0 -0
  62. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/zoomout_grouphover.png +0 -0
  63. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/zoomout_hover.png +0 -0
  64. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/zoomout_pressed.png +0 -0
  65. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-flat-toolbar-icons-master/images/zoomout_rest.png +0 -0
  66. plexora/client/external/openseadragon-bin-2.4.0/openseadragon-scalebar.js +562 -0
  67. plexora/client/src/css/import.css +474 -0
  68. plexora/client/src/css/main.css +903 -0
  69. plexora/client/src/css/openProject.css +363 -0
  70. plexora/client/src/css/quickView.css +166 -0
  71. plexora/client/src/css/tokens.css +51 -0
  72. plexora/client/src/css/viewer.css +1655 -0
  73. plexora/client/src/img/apple-touch-icon.png +0 -0
  74. plexora/client/src/img/favicon.ico +0 -0
  75. plexora/client/src/img/logo.ai +8892 -33
  76. plexora/client/src/img/logo.svg +1 -0
  77. plexora/client/src/img/logo_with_text.ai +9011 -34
  78. plexora/client/src/img/logo_with_text.svg +1 -0
  79. plexora/client/src/js/main.js +704 -0
  80. plexora/client/src/js/pluginRegistry.js +108 -0
  81. plexora/client/src/js/services/appStatus.js +286 -0
  82. plexora/client/src/js/services/browsePicker.js +73 -0
  83. plexora/client/src/js/services/dataLayer.js +400 -0
  84. plexora/client/src/js/services/datasetContext.js +143 -0
  85. plexora/client/src/js/services/glRenderer.js +143 -0
  86. plexora/client/src/js/services/importFormValidation.js +257 -0
  87. plexora/client/src/js/services/numericData.js +100 -0
  88. plexora/client/src/js/services/passVariablesToFrontend.js +20 -0
  89. plexora/client/src/js/services/simpleEventHandler.js +25 -0
  90. plexora/client/src/js/vendor.js +29 -0
  91. plexora/client/src/js/views/channelList.js +663 -0
  92. plexora/client/src/js/views/colorSwatchPicker.js +202 -0
  93. plexora/client/src/js/views/columnClassifier.js +146 -0
  94. plexora/client/src/js/views/coordinateField.js +133 -0
  95. plexora/client/src/js/views/dataSourceField.js +276 -0
  96. plexora/client/src/js/views/imageViewer.js +3306 -0
  97. plexora/client/src/js/views/miniMap.js +787 -0
  98. plexora/client/src/js/views/navbarControls.js +178 -0
  99. plexora/client/src/js/views/openProjectPage.js +239 -0
  100. plexora/client/src/js/views/projectEdit.js +335 -0
  101. plexora/client/src/js/views/quickViewLanding.js +136 -0
  102. plexora/client/src/js/views/rainbow.js +326 -0
  103. plexora/client/src/js/views/requirementsModal.js +572 -0
  104. plexora/client/src/js/views/rgbImageViewer.js +115 -0
  105. plexora/client/src/js/views/searchableSelect.js +411 -0
  106. plexora/client/src/js/views/segmentationProgress.js +122 -0
  107. plexora/client/src/js/views/toolLoader.js +747 -0
  108. plexora/client/src/js/views/viewerControls.js +689 -0
  109. plexora/client/src/js/views/viewerManager.js +434 -0
  110. plexora/client/src/js/views/viewerSidebar.js +1117 -0
  111. plexora/client/src/js/workers/tileDecoder.js +130 -0
  112. plexora/client/src/shaders/frag.glsl +528 -0
  113. plexora/client/src/shaders/vert.glsl +12 -0
  114. plexora/client/templates/base.html +212 -0
  115. plexora/client/templates/index.html +238 -0
  116. plexora/client/templates/open_project.html +96 -0
  117. plexora/client/templates/project_columns.html +86 -0
  118. plexora/client/templates/project_edit.html +196 -0
  119. plexora/client/templates/upload.html +118 -0
  120. plexora/connect.py +528 -0
  121. plexora/datasource.py +782 -0
  122. plexora/jupyter.py +406 -0
  123. plexora/notebook_env.py +232 -0
  124. plexora/paths.py +486 -0
  125. plexora/plugins/__init__.py +12 -0
  126. plexora/plugins/cell_explorer/__init__.py +100 -0
  127. plexora/plugins/cell_explorer/server/__init__.py +11 -0
  128. plexora/plugins/cell_explorer/server/routes.py +167 -0
  129. plexora/plugins/cell_explorer/server/state.py +281 -0
  130. plexora/plugins/cell_explorer/server/values.py +145 -0
  131. plexora/plugins/cell_explorer/server/variables.py +367 -0
  132. plexora/plugins/cell_explorer/static/cellExplorerApi.js +158 -0
  133. plexora/plugins/cell_explorer/static/cellExplorerColors.js +316 -0
  134. plexora/plugins/cell_explorer/static/cellExplorerContinuous.js +403 -0
  135. plexora/plugins/cell_explorer/static/cellExplorerFigureBridge.js +133 -0
  136. plexora/plugins/cell_explorer/static/cellExplorerLegend.js +188 -0
  137. plexora/plugins/cell_explorer/static/cellExplorerRoiBridge.js +822 -0
  138. plexora/plugins/cell_explorer/static/cellExplorerSidebarController.js +826 -0
  139. plexora/plugins/cell_explorer/static/cellExplorerState.js +372 -0
  140. plexora/plugins/cell_explorer/static/cell_explorer.css +752 -0
  141. plexora/plugins/cell_explorer/templates/cell_explorer/panel.html +137 -0
  142. plexora/plugins/figure_builder/__init__.py +125 -0
  143. plexora/plugins/figure_builder/server/__init__.py +7 -0
  144. plexora/plugins/figure_builder/server/compose.py +365 -0
  145. plexora/plugins/figure_builder/server/export.py +784 -0
  146. plexora/plugins/figure_builder/server/export_jobs.py +148 -0
  147. plexora/plugins/figure_builder/server/operations.py +556 -0
  148. plexora/plugins/figure_builder/server/pixels.py +142 -0
  149. plexora/plugins/figure_builder/server/provenance.py +174 -0
  150. plexora/plugins/figure_builder/server/render.py +278 -0
  151. plexora/plugins/figure_builder/server/repository.py +701 -0
  152. plexora/plugins/figure_builder/server/routes.py +594 -0
  153. plexora/plugins/figure_builder/server/schema.py +1023 -0
  154. plexora/plugins/figure_builder/server/sources.py +120 -0
  155. plexora/plugins/figure_builder/server/textmetrics.py +155 -0
  156. plexora/plugins/figure_builder/static/figureActions.js +363 -0
  157. plexora/plugins/figure_builder/static/figureBuilderApi.js +255 -0
  158. plexora/plugins/figure_builder/static/figureCanvas.js +2362 -0
  159. plexora/plugins/figure_builder/static/figureCaptureBoxes.js +369 -0
  160. plexora/plugins/figure_builder/static/figureCaptureDock.js +466 -0
  161. plexora/plugins/figure_builder/static/figureCaptureTool.js +1034 -0
  162. plexora/plugins/figure_builder/static/figureConfirm.js +136 -0
  163. plexora/plugins/figure_builder/static/figureContextBar.js +1193 -0
  164. plexora/plugins/figure_builder/static/figureContextMenu.js +253 -0
  165. plexora/plugins/figure_builder/static/figureDocumentState.js +275 -0
  166. plexora/plugins/figure_builder/static/figureExportUi.js +174 -0
  167. plexora/plugins/figure_builder/static/figureLibrary.js +247 -0
  168. plexora/plugins/figure_builder/static/figureQuickEdit.js +628 -0
  169. plexora/plugins/figure_builder/static/figureRichText.js +634 -0
  170. plexora/plugins/figure_builder/static/figureSceneSnapshot.js +361 -0
  171. plexora/plugins/figure_builder/static/figureSchema.js +218 -0
  172. plexora/plugins/figure_builder/static/figureSidebarController.js +1159 -0
  173. plexora/plugins/figure_builder/static/figureTextEditor.js +503 -0
  174. plexora/plugins/figure_builder/static/figureTextPanel.js +491 -0
  175. plexora/plugins/figure_builder/static/figureViewOptions.js +273 -0
  176. plexora/plugins/figure_builder/static/figureWorkspace.js +2030 -0
  177. plexora/plugins/figure_builder/static/figure_builder.css +3292 -0
  178. plexora/plugins/figure_builder/templates/figure_builder/library.html +74 -0
  179. plexora/plugins/figure_builder/templates/figure_builder/workspace.html +27 -0
  180. plexora/plugins/figure_builder/templates/figure_builder/workspace_body.html +458 -0
  181. plexora/plugins/gating/__init__.py +76 -0
  182. plexora/plugins/gating/server/__init__.py +0 -0
  183. plexora/plugins/gating/server/anndata_gates.py +367 -0
  184. plexora/plugins/gating/server/database.py +16 -0
  185. plexora/plugins/gating/server/model.py +320 -0
  186. plexora/plugins/gating/server/routes.py +235 -0
  187. plexora/plugins/gating/static/csvGatingList.js +947 -0
  188. plexora/plugins/gating/static/gating.css +289 -0
  189. plexora/plugins/gating/static/gatingApi.js +221 -0
  190. plexora/plugins/gating/static/gatingSidebarController.js +513 -0
  191. plexora/plugins/gating/templates/gating/legacy.html +26 -0
  192. plexora/plugins/gating/templates/gating/panel.html +69 -0
  193. plexora/plugins/roi/__init__.py +95 -0
  194. plexora/plugins/roi/server/__init__.py +8 -0
  195. plexora/plugins/roi/server/adapters.py +655 -0
  196. plexora/plugins/roi/server/geojson.py +267 -0
  197. plexora/plugins/roi/server/geometry.py +181 -0
  198. plexora/plugins/roi/server/mapping.py +169 -0
  199. plexora/plugins/roi/server/operations.py +293 -0
  200. plexora/plugins/roi/server/repository.py +215 -0
  201. plexora/plugins/roi/server/routes.py +409 -0
  202. plexora/plugins/roi/server/schema.py +323 -0
  203. plexora/plugins/roi/static/roi.css +583 -0
  204. plexora/plugins/roi/static/roiApi.js +177 -0
  205. plexora/plugins/roi/static/roiFigureBridge.js +107 -0
  206. plexora/plugins/roi/static/roiGeometry.js +350 -0
  207. plexora/plugins/roi/static/roiRenderer.js +278 -0
  208. plexora/plugins/roi/static/roiSidebarController.js +1038 -0
  209. plexora/plugins/roi/static/roiState.js +518 -0
  210. plexora/plugins/roi/static/roiTools.js +993 -0
  211. plexora/plugins/roi/templates/roi/panel.html +240 -0
  212. plexora/proxy.py +57 -0
  213. plexora/server/models/adapters/__init__.py +94 -0
  214. plexora/server/models/adapters/anndata_adapter.py +388 -0
  215. plexora/server/models/adapters/base.py +93 -0
  216. plexora/server/models/adapters/classify.py +192 -0
  217. plexora/server/models/adapters/csv_adapter.py +105 -0
  218. plexora/server/models/adapters/inspection.py +265 -0
  219. plexora/server/models/adapters/spatialdata_adapter.py +248 -0
  220. plexora/server/models/centroid_tiles.py +305 -0
  221. plexora/server/models/data_model.py +1659 -0
  222. plexora/server/models/database_model.py +169 -0
  223. plexora/server/models/project.py +1270 -0
  224. plexora/server/plugins.py +199 -0
  225. plexora/server/routes/browse_routes.py +41 -0
  226. plexora/server/routes/data_routes.py +294 -0
  227. plexora/server/routes/import_routes.py +603 -0
  228. plexora/server/routes/page_routes.py +139 -0
  229. plexora/server/routes/project_routes.py +438 -0
  230. plexora/server/routes/quick_view_routes.py +62 -0
  231. plexora/server/routes/system_routes.py +39 -0
  232. plexora/server/routes/tool_routes.py +418 -0
  233. plexora/server/utils/addHEColumns.py +11 -0
  234. plexora/server/utils/fast_png.py +97 -0
  235. plexora/server/utils/fullConversion.py +50 -0
  236. plexora/server/utils/native_dialog.py +168 -0
  237. plexora/server/utils/pre_normalization.py +47 -0
  238. plexora/server/utils/segmentation_pyramid.py +598 -0
  239. plexora/server/utils/smallestenclosingcircle.py +126 -0
  240. plexora/server/utils/tiffsurgeon.py +372 -0
  241. plexora/server_cli.py +48 -0
  242. plexora/test.py +0 -0
  243. plexora-0.0.1.dist-info/METADATA +341 -0
  244. plexora-0.0.1.dist-info/RECORD +248 -0
  245. plexora-0.0.1.dist-info/WHEEL +5 -0
  246. plexora-0.0.1.dist-info/entry_points.txt +12 -0
  247. plexora-0.0.1.dist-info/licenses/LICENSE +207 -0
  248. plexora-0.0.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,9 @@
1
+ # OpenSeadragon Flat Toolbar Icons
2
+ Simple, flat design toolbar icons for OpenSeadragon
3
+ [https://github.com/openseadragon/openseadragon](https://github.com/openseadragon/openseadragon)
4
+
5
+ Demo:
6
+ [http://droneservices.getyournet.ch/beispiele-luftaufnahmen-mit-drohne](http://droneservices.getyournet.ch/beispiele-luftaufnahmen-mit-drohne)
7
+
8
+ ![alt tag](https://cloud.githubusercontent.com/assets/5383762/9150698/70f23bfe-3de8-11e5-961e-5239fa67e94e.png)
9
+
@@ -0,0 +1,562 @@
1
+ /*
2
+ * This software was developed at the National Institute of Standards and
3
+ * Technology by employees of the Federal Government in the course of
4
+ * their official duties. Pursuant to title 17 Section 105 of the United
5
+ * States Code this software is not subject to copyright protection and is
6
+ * in the public domain. This software is an experimental system. NIST assumes
7
+ * no responsibility whatsoever for its use by other parties, and makes no
8
+ * guarantees, expressed or implied, about its quality, reliability, or
9
+ * any other characteristic. We would appreciate acknowledgement if the
10
+ * software is used.
11
+ */
12
+
13
+ /**
14
+ *
15
+ * @author Antoine Vandecreme <antoine.vandecreme@nist.gov>
16
+ */
17
+ (function($) {
18
+
19
+ if (!$.version || $.version.major < 2) {
20
+ throw new Error('This version of OpenSeadragonScalebar requires ' +
21
+ 'OpenSeadragon version 2.0.0+');
22
+ }
23
+
24
+ $.Viewer.prototype.scalebar = function(options) {
25
+ if (!this.scalebarInstance) {
26
+ options = options || {};
27
+ options.viewer = this;
28
+ this.scalebarInstance = new $.Scalebar(options);
29
+ } else {
30
+ this.scalebarInstance.refresh(options);
31
+ }
32
+ };
33
+
34
+ $.ScalebarType = {
35
+ NONE: 0,
36
+ MICROSCOPY: 1,
37
+ MAP: 2
38
+ };
39
+
40
+ $.ScalebarLocation = {
41
+ NONE: 0,
42
+ TOP_LEFT: 1,
43
+ TOP_RIGHT: 2,
44
+ BOTTOM_RIGHT: 3,
45
+ BOTTOM_LEFT: 4
46
+ };
47
+
48
+ /**
49
+ *
50
+ * @class Scalebar
51
+ * @param {Object} options
52
+ * @param {OpenSeadragon.Viewer} options.viewer The viewer to attach this
53
+ * Scalebar to.
54
+ * @param {OpenSeadragon.ScalebarType} options.type The scale bar type.
55
+ * Default: microscopy
56
+ * @param {Integer} options.pixelsPerMeter The pixels per meter of the
57
+ * zoomable image at the original image size. If null, the scale bar is not
58
+ * displayed. default: null
59
+ * @param {Integer} options.referenceItemIdx Specify the item from
60
+ * viewer.world to which options.pixelsPerMeter is refering.
61
+ * default: 0
62
+ * @param (String} options.minWidth The minimal width of the scale bar as a
63
+ * CSS string (ex: 100px, 1em, 1% etc...) default: 150px
64
+ * @param {OpenSeadragon.ScalebarLocation} options.location The location
65
+ * of the scale bar inside the viewer. default: bottom left
66
+ * @param {Integer} options.xOffset Offset location of the scale bar along x.
67
+ * default: 5
68
+ * @param {Integer} options.yOffset Offset location of the scale bar along y.
69
+ * default: 5
70
+ * @param {Boolean} options.stayInsideImage When set to true, keep the
71
+ * scale bar inside the image when zooming out. default: true
72
+ * @param {String} options.color The color of the scale bar using a color
73
+ * name or the hexadecimal format (ex: black or #000000) default: black
74
+ * @param {String} options.fontColor The font color. default: black
75
+ * @param {String} options.backgroundColor The background color. default: none
76
+ * @param {String} options.fontSize The font size. default: not set
77
+ * @param {String} options.fontFamily The font-family. default: not set
78
+ * @param {String} options.barThickness The thickness of the scale bar in px.
79
+ * default: 2
80
+ * @param {function} options.sizeAndTextRenderer A function which will be
81
+ * called to determine the size of the scale bar and it's text content.
82
+ * The function must have 2 parameters: the PPM at the current zoom level
83
+ * and the minimum size of the scale bar. It must return an object containing
84
+ * 2 attributes: size and text containing the size of the scale bar and the text.
85
+ * default: $.ScalebarSizeAndTextRenderer.METRIC_LENGTH
86
+ */
87
+ $.Scalebar = function(options) {
88
+ options = options || {};
89
+ if (!options.viewer) {
90
+ throw new Error("A viewer must be specified.");
91
+ }
92
+ this.viewer = options.viewer;
93
+
94
+ this.divElt = document.createElement("div");
95
+ this.viewer.container.appendChild(this.divElt);
96
+ this.divElt.style.position = "relative";
97
+ this.divElt.style.margin = "0";
98
+ this.divElt.style.pointerEvents = "none";
99
+
100
+ this.setMinWidth(options.minWidth || "150px");
101
+
102
+ this.setDrawScalebarFunction(options.type || $.ScalebarType.MICROSCOPY);
103
+ this.color = options.color || "black";
104
+ this.fontColor = options.fontColor || "black";
105
+ this.backgroundColor = options.backgroundColor || "none";
106
+ this.fontSize = options.fontSize || "";
107
+ this.fontFamily = options.fontFamily || "";
108
+ this.barThickness = options.barThickness || 2;
109
+ this.pixelsPerMeter = options.pixelsPerMeter || null;
110
+ this.referenceItemIdx = options.referenceItemIdx || 0;
111
+ this.location = options.location || $.ScalebarLocation.BOTTOM_LEFT;
112
+ this.xOffset = options.xOffset || 5;
113
+ this.yOffset = options.yOffset || 5;
114
+ this.stayInsideImage = isDefined(options.stayInsideImage) ?
115
+ options.stayInsideImage : true;
116
+ this.sizeAndTextRenderer = options.sizeAndTextRenderer ||
117
+ $.ScalebarSizeAndTextRenderer.METRIC_LENGTH;
118
+
119
+ var self = this;
120
+ this.viewer.addHandler("open", function() {
121
+ self.refresh();
122
+ });
123
+ this.viewer.addHandler("animation", function() {
124
+ self.refresh();
125
+ });
126
+ this.viewer.addHandler("resize", function() {
127
+ self.refresh();
128
+ });
129
+ };
130
+
131
+ $.Scalebar.prototype = {
132
+ updateOptions: function(options) {
133
+ if (!options) {
134
+ return;
135
+ }
136
+ if (isDefined(options.type)) {
137
+ this.setDrawScalebarFunction(options.type);
138
+ }
139
+ if (isDefined(options.minWidth)) {
140
+ this.setMinWidth(options.minWidth);
141
+ }
142
+ if (isDefined(options.color)) {
143
+ this.color = options.color;
144
+ }
145
+ if (isDefined(options.fontColor)) {
146
+ this.fontColor = options.fontColor;
147
+ }
148
+ if (isDefined(options.backgroundColor)) {
149
+ this.backgroundColor = options.backgroundColor;
150
+ }
151
+ if (isDefined(options.fontSize)) {
152
+ this.fontSize = options.fontSize;
153
+ }
154
+ if (isDefined(options.fontFamily)) {
155
+ this.fontFamily = options.fontFamily;
156
+ }
157
+ if (isDefined(options.barThickness)) {
158
+ this.barThickness = options.barThickness;
159
+ }
160
+ if (isDefined(options.pixelsPerMeter)) {
161
+ this.pixelsPerMeter = options.pixelsPerMeter;
162
+ }
163
+ if (isDefined(options.referenceItemIdx)) {
164
+ this.referenceItemIdx = options.referenceItemIdx;
165
+ }
166
+ if (isDefined(options.location)) {
167
+ this.location = options.location;
168
+ }
169
+ if (isDefined(options.xOffset)) {
170
+ this.xOffset = options.xOffset;
171
+ }
172
+ if (isDefined(options.yOffset)) {
173
+ this.yOffset = options.yOffset;
174
+ }
175
+ if (isDefined(options.stayInsideImage)) {
176
+ this.stayInsideImage = options.stayInsideImage;
177
+ }
178
+ if (isDefined(options.sizeAndTextRenderer)) {
179
+ this.sizeAndTextRenderer = options.sizeAndTextRenderer;
180
+ }
181
+ },
182
+ setDrawScalebarFunction: function(type) {
183
+ if (!type) {
184
+ this.drawScalebar = null;
185
+ }
186
+ else if (type === $.ScalebarType.MAP) {
187
+ this.drawScalebar = this.drawMapScalebar;
188
+ } else {
189
+ this.drawScalebar = this.drawMicroscopyScalebar;
190
+ }
191
+ },
192
+ setMinWidth: function(minWidth) {
193
+ this.divElt.style.width = minWidth;
194
+ // Make sure to display the element before getting is width
195
+ this.divElt.style.display = "";
196
+ this.minWidth = this.divElt.offsetWidth;
197
+ },
198
+ /**
199
+ * Refresh the scalebar with the options submitted.
200
+ * @param {Object} options
201
+ * @param {OpenSeadragon.ScalebarType} options.type The scale bar type.
202
+ * Default: microscopy
203
+ * @param {Integer} options.pixelsPerMeter The pixels per meter of the
204
+ * zoomable image at the original image size. If null, the scale bar is not
205
+ * displayed. default: null
206
+ * @param {Integer} options.referenceItemIdx Specify the item from
207
+ * viewer.world to which options.pixelsPerMeter is refering.
208
+ * default: 0
209
+ * @param (String} options.minWidth The minimal width of the scale bar as a
210
+ * CSS string (ex: 100px, 1em, 1% etc...) default: 150px
211
+ * @param {OpenSeadragon.ScalebarLocation} options.location The location
212
+ * of the scale bar inside the viewer. default: bottom left
213
+ * @param {Integer} options.xOffset Offset location of the scale bar along x.
214
+ * default: 5
215
+ * @param {Integer} options.yOffset Offset location of the scale bar along y.
216
+ * default: 5
217
+ * @param {Boolean} options.stayInsideImage When set to true, keep the
218
+ * scale bar inside the image when zooming out. default: true
219
+ * @param {String} options.color The color of the scale bar using a color
220
+ * name or the hexadecimal format (ex: black or #000000) default: black
221
+ * @param {String} options.fontColor The font color. default: black
222
+ * @param {String} options.backgroundColor The background color. default: none
223
+ * @param {String} options.fontSize The font size. default: not set
224
+ * @param {String} options.barThickness The thickness of the scale bar in px.
225
+ * default: 2
226
+ * @param {function} options.sizeAndTextRenderer A function which will be
227
+ * called to determine the size of the scale bar and it's text content.
228
+ * The function must have 2 parameters: the PPM at the current zoom level
229
+ * and the minimum size of the scale bar. It must return an object containing
230
+ * 2 attributes: size and text containing the size of the scale bar and the text.
231
+ * default: $.ScalebarSizeAndTextRenderer.METRIC_LENGTH
232
+ */
233
+ refresh: function(options) {
234
+ this.updateOptions(options);
235
+
236
+ if (!this.viewer.isOpen() ||
237
+ !this.drawScalebar ||
238
+ !this.pixelsPerMeter ||
239
+ !this.location) {
240
+ this.divElt.style.display = "none";
241
+ return;
242
+ }
243
+ this.divElt.style.display = "";
244
+
245
+ var viewport = this.viewer.viewport;
246
+ var tiledImage = this.viewer.world.getItemAt(this.referenceItemIdx);
247
+ var zoom = tiledImageViewportToImageZoom(tiledImage,
248
+ viewport.getZoom(true));
249
+ var currentPPM = zoom * this.pixelsPerMeter;
250
+ var props = this.sizeAndTextRenderer(currentPPM, this.minWidth);
251
+
252
+ this.drawScalebar(props.size, props.text);
253
+ var location = this.getScalebarLocation();
254
+ this.divElt.style.left = location.x + "px";
255
+ this.divElt.style.top = location.y + "px";
256
+ },
257
+ drawMicroscopyScalebar: function(size, text) {
258
+ this.divElt.style.fontSize = this.fontSize;
259
+ this.divElt.style.fontFamily = this.fontFamily;
260
+ this.divElt.style.textAlign = "center";
261
+ this.divElt.style.color = this.fontColor;
262
+ this.divElt.style.border = "none";
263
+ this.divElt.style.borderBottom = this.barThickness + "px solid " + this.color;
264
+ this.divElt.style.backgroundColor = this.backgroundColor;
265
+ this.divElt.innerHTML = text;
266
+ this.divElt.style.width = size + "px";
267
+ },
268
+ drawMapScalebar: function(size, text) {
269
+ this.divElt.style.fontSize = this.fontSize;
270
+ this.divElt.style.fontFamily = this.fontFamily;
271
+ this.divElt.style.textAlign = "center";
272
+ this.divElt.style.color = this.fontColor;
273
+ this.divElt.style.border = this.barThickness + "px solid " + this.color;
274
+ this.divElt.style.borderTop = "none";
275
+ this.divElt.style.backgroundColor = this.backgroundColor;
276
+ this.divElt.innerHTML = text;
277
+ this.divElt.style.width = size + "px";
278
+ },
279
+ /**
280
+ * Compute the location of the scale bar.
281
+ * @returns {OpenSeadragon.Point}
282
+ */
283
+ getScalebarLocation: function() {
284
+ if (this.location === $.ScalebarLocation.TOP_LEFT) {
285
+ var x = 0;
286
+ var y = 0;
287
+ if (this.stayInsideImage) {
288
+ var pixel = this.viewer.viewport.pixelFromPoint(
289
+ new $.Point(0, 0), true);
290
+ if (!this.viewer.wrapHorizontal) {
291
+ x = Math.max(pixel.x, 0);
292
+ }
293
+ if (!this.viewer.wrapVertical) {
294
+ y = Math.max(pixel.y, 0);
295
+ }
296
+ }
297
+ return new $.Point(x + this.xOffset, y + this.yOffset);
298
+ }
299
+ if (this.location === $.ScalebarLocation.TOP_RIGHT) {
300
+ var barWidth = this.divElt.offsetWidth;
301
+ var container = this.viewer.container;
302
+ var x = container.offsetWidth - barWidth;
303
+ var y = 0;
304
+ if (this.stayInsideImage) {
305
+ var pixel = this.viewer.viewport.pixelFromPoint(
306
+ new $.Point(1, 0), true);
307
+ if (!this.viewer.wrapHorizontal) {
308
+ x = Math.min(x, pixel.x - barWidth);
309
+ }
310
+ if (!this.viewer.wrapVertical) {
311
+ y = Math.max(y, pixel.y);
312
+ }
313
+ }
314
+ return new $.Point(x - this.xOffset, y + this.yOffset);
315
+ }
316
+ if (this.location === $.ScalebarLocation.BOTTOM_RIGHT) {
317
+ var barWidth = this.divElt.offsetWidth;
318
+ var barHeight = this.divElt.offsetHeight;
319
+ var container = this.viewer.container;
320
+ var x = (4/5)*(container.offsetWidth - barWidth);
321
+ var y = container.offsetHeight - (17/10)*barHeight;
322
+ if (this.stayInsideImage) {
323
+ var pixel = this.viewer.viewport.pixelFromPoint(
324
+ new $.Point(1, 1 / this.viewer.source.aspectRatio),
325
+ true);
326
+ if (!this.viewer.wrapHorizontal) {
327
+ x = Math.min(x, pixel.x - barWidth);
328
+ }
329
+ if (!this.viewer.wrapVertical) {
330
+ y = Math.min(y, pixel.y - barHeight);
331
+ }
332
+ }
333
+ return new $.Point(x - this.xOffset, y - this.yOffset);
334
+ }
335
+ if (this.location === $.ScalebarLocation.BOTTOM_LEFT) {
336
+ var barHeight = this.divElt.offsetHeight;
337
+ var container = this.viewer.container;
338
+ var x = 0;
339
+ var y = container.offsetHeight - barHeight;
340
+ if (this.stayInsideImage) {
341
+ var pixel = this.viewer.viewport.pixelFromPoint(
342
+ new $.Point(0, 1 / this.viewer.source.aspectRatio),
343
+ true);
344
+ if (!this.viewer.wrapHorizontal) {
345
+ x = Math.max(x, pixel.x);
346
+ }
347
+ if (!this.viewer.wrapVertical) {
348
+ y = Math.min(y, pixel.y - barHeight);
349
+ }
350
+ }
351
+ return new $.Point(x + this.xOffset, y - this.yOffset);
352
+ }
353
+ },
354
+ /**
355
+ * Get the rendered scalebar in a canvas.
356
+ * @returns {Element} A canvas containing the scalebar representation
357
+ */
358
+ getAsCanvas: function() {
359
+ var canvas = document.createElement("canvas");
360
+ canvas.width = this.divElt.offsetWidth;
361
+ canvas.height = this.divElt.offsetHeight;
362
+ var context = canvas.getContext("2d");
363
+ context.fillStyle = this.backgroundColor;
364
+ context.fillRect(0, 0, canvas.width, canvas.height);
365
+ context.fillStyle = this.color;
366
+ context.fillRect(0, canvas.height - this.barThickness,
367
+ canvas.width, canvas.height);
368
+ if (this.drawScalebar === this.drawMapScalebar) {
369
+ context.fillRect(0, 0, this.barThickness, canvas.height);
370
+ context.fillRect(canvas.width - this.barThickness, 0,
371
+ this.barThickness, canvas.height);
372
+ }
373
+ context.font = window.getComputedStyle(this.divElt).font;
374
+ context.textAlign = "center";
375
+ context.textBaseline = "middle";
376
+ context.fillStyle = this.fontColor;
377
+ var hCenter = canvas.width / 2;
378
+ var vCenter = canvas.height / 2;
379
+ context.fillText(this.divElt.textContent, hCenter, vCenter);
380
+ return canvas;
381
+ },
382
+ /**
383
+ * Get a copy of the current OpenSeadragon canvas with the scalebar.
384
+ * @returns {Element} A canvas containing a copy of the current OpenSeadragon canvas with the scalebar
385
+ */
386
+ getImageWithScalebarAsCanvas: function() {
387
+ var imgCanvas = this.viewer.drawer.canvas;
388
+ var newCanvas = document.createElement("canvas");
389
+ newCanvas.width = imgCanvas.width;
390
+ newCanvas.height = imgCanvas.height;
391
+ var newCtx = newCanvas.getContext("2d");
392
+ newCtx.drawImage(imgCanvas, 0, 0);
393
+ var scalebarCanvas = this.getAsCanvas();
394
+ var location = this.getScalebarLocation();
395
+ newCtx.drawImage(scalebarCanvas, location.x, location.y);
396
+ return newCanvas;
397
+ }
398
+ };
399
+
400
+ $.ScalebarSizeAndTextRenderer = {
401
+ /**
402
+ * Metric length. From nano meters to kilometers.
403
+ */
404
+ METRIC_LENGTH: function(ppm, minSize) {
405
+ return getScalebarSizeAndTextForMetric(ppm, minSize, "m");
406
+ },
407
+ /**
408
+ * Imperial length. Choosing the best unit from thou, inch, foot and mile.
409
+ */
410
+ IMPERIAL_LENGTH: function(ppm, minSize) {
411
+ var maxSize = minSize * 2;
412
+ var ppi = ppm * 0.0254;
413
+ if (maxSize < ppi * 12) {
414
+ if (maxSize < ppi) {
415
+ var ppt = ppi / 1000;
416
+ return getScalebarSizeAndText(ppt, minSize, "th");
417
+ }
418
+ return getScalebarSizeAndText(ppi, minSize, "in");
419
+ }
420
+ var ppf = ppi * 12;
421
+ if (maxSize < ppf * 2000) {
422
+ return getScalebarSizeAndText(ppf, minSize, "ft");
423
+ }
424
+ var ppmi = ppf * 5280;
425
+ return getScalebarSizeAndText(ppmi, minSize, "mi");
426
+ },
427
+ /**
428
+ * Astronomy units. Choosing the best unit from arcsec, arcminute, and degree
429
+ */
430
+ ASTRONOMY: function(ppa, minSize) {
431
+ var maxSize = minSize * 2;
432
+ if (maxSize < ppa * 60) {
433
+ return getScalebarSizeAndText(ppa, minSize, "\"", false, '');
434
+ }
435
+ var ppminutes = ppa * 60;
436
+ if (maxSize < ppminutes * 60) {
437
+ return getScalebarSizeAndText(ppminutes, minSize, "\'", false, '');
438
+ }
439
+ var ppd = ppminutes * 60;
440
+ return getScalebarSizeAndText(ppd, minSize, "&#176", false, '');
441
+ },
442
+ /**
443
+ * Standard time. Choosing the best unit from second (and metric divisions),
444
+ * minute, hour, day and year.
445
+ */
446
+ STANDARD_TIME: function(pps, minSize) {
447
+ var maxSize = minSize * 2;
448
+ if (maxSize < pps * 60) {
449
+ return getScalebarSizeAndTextForMetric(pps, minSize, "s", false);
450
+ }
451
+ var ppminutes = pps * 60;
452
+ if (maxSize < ppminutes * 60) {
453
+ return getScalebarSizeAndText(ppminutes, minSize, "minute", true);
454
+ }
455
+ var pph = ppminutes * 60;
456
+ if (maxSize < pph * 24) {
457
+ return getScalebarSizeAndText(pph, minSize, "hour", true);
458
+ }
459
+ var ppd = pph * 24;
460
+ if (maxSize < ppd * 365.25) {
461
+ return getScalebarSizeAndText(ppd, minSize, "day", true);
462
+ }
463
+ var ppy = ppd * 365.25;
464
+ return getScalebarSizeAndText(ppy, minSize, "year", true);
465
+ },
466
+ /**
467
+ * Generic metric unit. One can use this function to create a new metric
468
+ * scale. For example, here is an implementation of energy levels:
469
+ * function(ppeV, minSize) {
470
+ * return OpenSeadragon.ScalebarSizeAndTextRenderer.METRIC_GENERIC(
471
+ * ppeV, minSize, "eV");
472
+ * }
473
+ */
474
+ METRIC_GENERIC: getScalebarSizeAndTextForMetric
475
+ };
476
+
477
+ // Missing TiledImage.viewportToImageZoom function in OSD 2.0.0
478
+ function tiledImageViewportToImageZoom(tiledImage, viewportZoom) {
479
+ var ratio = tiledImage._scaleSpring.current.value *
480
+ tiledImage.viewport._containerInnerSize.x /
481
+ tiledImage.source.dimensions.x;
482
+ return ratio * viewportZoom;
483
+ }
484
+
485
+ function getScalebarSizeAndText(ppm, minSize, unitSuffix, handlePlural, spacer) {
486
+ spacer = spacer === undefined ? ' ' : spacer;
487
+ var value = normalize(ppm, minSize);
488
+ var factor = roundSignificand(value / ppm * minSize, 3);
489
+ var size = value * minSize;
490
+ var plural = handlePlural && factor > 1 ? "s" : "";
491
+ return {
492
+ size: size,
493
+ text: factor + spacer + unitSuffix + plural
494
+ };
495
+ }
496
+
497
+ function getScalebarSizeAndTextForMetric(ppm, minSize, unitSuffix) {
498
+ var value = normalize(ppm, minSize);
499
+ var factor = roundSignificand(value / ppm * minSize, 3);
500
+ var size = value * minSize;
501
+ var valueWithUnit = getWithUnit(factor, unitSuffix);
502
+ return {
503
+ size: size,
504
+ text: valueWithUnit
505
+ };
506
+ }
507
+
508
+ function normalize(value, minSize) {
509
+ var significand = getSignificand(value);
510
+ var minSizeSign = getSignificand(minSize);
511
+ var result = getSignificand(significand / minSizeSign);
512
+ if (result >= 5) {
513
+ result /= 5;
514
+ }
515
+ if (result >= 4) {
516
+ result /= 4;
517
+ }
518
+ if (result >= 2) {
519
+ result /= 2;
520
+ }
521
+ return result;
522
+ }
523
+
524
+ function getSignificand(x) {
525
+ return x * Math.pow(10, Math.ceil(-log10(x)));
526
+ }
527
+
528
+ function roundSignificand(x, decimalPlaces) {
529
+ var exponent = -Math.ceil(-log10(x));
530
+ var power = decimalPlaces - exponent;
531
+ var significand = x * Math.pow(10, power);
532
+ // To avoid rounding problems, always work with integers
533
+ if (power < 0) {
534
+ return Math.round(significand) * Math.pow(10, -power);
535
+ }
536
+ return Math.round(significand) / Math.pow(10, power);
537
+ }
538
+
539
+ function log10(x) {
540
+ return Math.log(x) / Math.log(10);
541
+ }
542
+
543
+ function getWithUnit(value, unitSuffix) {
544
+ if (value < 0.000001) {
545
+ return value * 1000000000 + " n" + unitSuffix;
546
+ }
547
+ if (value < 0.001) {
548
+ return value * 1000000 + " μ" + unitSuffix;
549
+ }
550
+ if (value < 1) {
551
+ return value * 1000 + " m" + unitSuffix;
552
+ }
553
+ if (value >= 1000) {
554
+ return value / 1000 + " k" + unitSuffix;
555
+ }
556
+ return value + " " + unitSuffix;
557
+ }
558
+
559
+ function isDefined(variable) {
560
+ return typeof (variable) !== "undefined";
561
+ }
562
+ }(OpenSeadragon));