From 334b8bb8da9cf125eb85c1c87d18486c78a4ccb2 Mon Sep 17 00:00:00 2001 From: Severiano Badajoz Date: Thu, 13 Jun 2019 15:40:57 -0700 Subject: [PATCH] draw labels marking the centroids of category value clusters (#809) * Connect mouse over events to reducer actions * Change Styling on hover * Rename reducer actions to be more descriptive * Reorder reducer in cascade * Create centroid calculation util * Whitespace * Typo fix, use correct action * Create centroid calc util * Create centroid svg setup * Refactor existing svg layer to toolSVG * Change calcCentroid signature and centroidXY to match mapPointToScreen * Add id and styling * Run prettier * Set z-index to 999 * Draw the label * Introduce the centroid SVG, refactor code to allow both SVG layers * Add text label and compute radius based on population * Implement optional chaining * Update font family * Optimize calcMeanCentroid() * Create and utilize calcMedianCentroid() * Remove mass circle from label * Remove styling change on hover * Remove reducer action logs * Prettier * Swap out binds for arrow functions * Style text * switch from selectAll() to select() * Reflect centroid container's purpose in id * Remove mass from the output * Swap to obj * Add finite check * Don't draw centroid if no finite values * Fix finite check * Remove log * Toggle label coloring based on colorBy state * Pass cursor events through centroid svg --- client/src/components/categorical/value.js | 32 +++++-- client/src/components/graph/graph.js | 87 ++++++++++++++----- .../src/components/graph/setupCentroidSVG.js | 34 ++++++++ .../src/components/graph/setupSVGandBrush.js | 8 +- client/src/reducers/centroidLabel.js | 44 ++++++++++ client/src/reducers/index.js | 56 ++++++------ client/src/reducers/undoableConfig.js | 5 +- client/src/util/centroid.js | 58 +++++++++++++ 8 files changed, 265 insertions(+), 59 deletions(-) create mode 100644 client/src/components/graph/setupCentroidSVG.js create mode 100644 client/src/reducers/centroidLabel.js create mode 100644 client/src/util/centroid.js diff --git a/client/src/components/categorical/value.js b/client/src/components/categorical/value.js index 15c45d49..705412c9 100644 --- a/client/src/components/categorical/value.js +++ b/client/src/components/categorical/value.js @@ -13,23 +13,41 @@ import * as globals from "../../globals"; world: state.world })) class CategoryValue extends React.Component { - toggleOff() { + toggleOff = () => { const { dispatch, metadataField, categoryIndex } = this.props; dispatch({ type: "categorical metadata filter deselect", metadataField, categoryIndex }); - } + }; - toggleOn() { + toggleOn = () => { const { dispatch, metadataField, categoryIndex } = this.props; dispatch({ type: "categorical metadata filter select", metadataField, categoryIndex }); - } + }; + + handleMouseEnter = () => { + const { dispatch, metadataField, categoryIndex } = this.props; + dispatch({ + type: "category value mouse hover start", + metadataField, + categoryIndex + }); + }; + + handleMouseExit = () => { + const { dispatch, metadataField, categoryIndex } = this.props; + dispatch({ + type: "category value mouse hover end", + metadataField, + categoryIndex + }); + }; render() { const { @@ -79,6 +97,8 @@ class CategoryValue extends React.Component { justifyContent: "space-between" }} data-testclass="categorical-row" + onMouseEnter={this.handleMouseEnter} + onMouseLeave={this.handleMouseExit} >