From 70a95df7114513c17e7ae2cb9f069d575ca03729 Mon Sep 17 00:00:00 2001 From: Brandon Clayton <bclayton@usgs.gov> Date: Mon, 16 Sep 2024 11:39:11 -0600 Subject: [PATCH] allow drag and rotate --- src/disagg/DisaggGraphView.js | 35 +++++++++++++++++++++++++++++++ styles/_DisaggGraphView.scss | 2 ++ types/disagg/DisaggGraphView.d.ts | 9 ++++++++ 3 files changed, 46 insertions(+) diff --git a/src/disagg/DisaggGraphView.js b/src/disagg/DisaggGraphView.js index aaf82ce..a10f783 100644 --- a/src/disagg/DisaggGraphView.js +++ b/src/disagg/DisaggGraphView.js @@ -132,6 +132,29 @@ var DisaggGraphView = function (options) { _this.d33d.renderLegend = _this.renderLegend; _this.render(); + + var dragging = false; + var origin = { + x: 0, + y: 0, + }; + + d3.select(_this.d33d.el) + .on('mousedown', event => { + origin.x = event.clientX; + origin.y = event.clientY; + dragging = true; + }) + .on('mousemove', event => { + if (dragging) { + var dx = event.clientX - origin.x; + var dz = event.clientY - origin.y; + _this.setOrigin(280 - dx, -150, 180 + dz) + } + }) + .on('mouseup', () => { + dragging = false + }) }; /** @@ -707,6 +730,18 @@ var DisaggGraphView = function (options) { el.attr('transform', 'translate(' + -bbox.width + ' 0)'); }; + /** + * Set the views origin. + * @param {number} x + * @param {number} y + * @param {number} z + */ + _this.setOrigin = function (x, y, z) { + _this.d33d.model.set({ + 'origin': [x, y, z] + }); + } + _initialize(options); options = null; return _this; diff --git a/styles/_DisaggGraphView.scss b/styles/_DisaggGraphView.scss index caf6ea3..f53799f 100644 --- a/styles/_DisaggGraphView.scss +++ b/styles/_DisaggGraphView.scss @@ -1,4 +1,6 @@ .DisaggGraphView { + user-select: none; + .tooltip-content { .title { font-size: 12px; diff --git a/types/disagg/DisaggGraphView.d.ts b/types/disagg/DisaggGraphView.d.ts index 1dba501..7a3ded8 100644 --- a/types/disagg/DisaggGraphView.d.ts +++ b/types/disagg/DisaggGraphView.d.ts @@ -106,4 +106,13 @@ export class DisaggGraphView extends SelectedCollectionView<DisaggGraphViewOptio * element where legend should be rendered. */ renderLegend(info: Info): void; + + /** + * Set the view origin. + * + * @param x The X origin + * @param y The Y origin + * @param z The Z origin + */ + setOrigin(x: number, y: number, z: number): void; } -- GitLab