@splunk/react-visualizations 23.5.0 → 24.1.0
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.
- package/.loki/reference/chrome_docker_SingleValueRadial_100_height_and_width.png +0 -0
- package/.loki/reference/chrome_docker_SingleValueRadial_Background_color_flamenco.png +0 -0
- package/.loki/reference/chrome_docker_SingleValueRadial_Background_color_is_white.png +0 -0
- package/.loki/reference/chrome_docker_SingleValueRadial_Number_Precision_2.png +0 -0
- package/.loki/reference/chrome_docker_SingleValueRadial_Radial_Background_Color_pink.png +0 -0
- package/.loki/reference/chrome_docker_SingleValueRadial_Radial_Stroke_Color_valencia.png +0 -0
- package/.loki/reference/chrome_docker_SingleValueRadial_Thousand_Separators_disabled.png +0 -0
- package/.loki/reference/chrome_docker_SingleValueRadial_Thousand_Separators_enabled_default.png +0 -0
- package/.loki/reference/chrome_docker_SingleValueRadial_Trend_Display_Mode_absolute_default.png +0 -0
- package/.loki/reference/chrome_docker_SingleValueRadial_Trend_Display_Mode_percent.png +0 -0
- package/.loki/reference/chrome_docker_SingleValueRadial_Trend_Indicator_Position_below.png +0 -0
- package/.loki/reference/chrome_docker_SingleValueRadial_Trend_Indicator_Position_outside.png +0 -0
- package/.loki/reference/chrome_docker_SingleValueRadial_Trend_Indicator_Position_pushed_below_value_does_not_feet_inside_of_radial.png +0 -0
- package/.loki/reference/chrome_docker_SingleValueRadial_Trend_Indicator_Position_standard_default.png +0 -0
- package/.loki/reference/chrome_docker_SingleValueRadial_Trend_Indicator_disabled.png +0 -0
- package/.loki/reference/chrome_docker_SingleValueRadial_Trend_Indicator_enabled_default.png +0 -0
- package/.loki/reference/chrome_docker_SingleValueRadial_Under_label_specified.png +0 -0
- package/.loki/reference/chrome_docker_SingleValueRadial_Unit_specified_Unit_Position_after_default.png +0 -0
- package/.loki/reference/chrome_docker_SingleValueRadial_Unit_specified_Unit_Position_before.png +0 -0
- package/.loki/reference/chrome_docker_SingleValueRadial_basic.png +0 -0
- package/.loki/reference/chrome_docker_SingleValueRadial_basic_dark_theme.png +0 -0
- package/.loki/reference/chrome_docker_SingleValueRadial_basic_default_theme.png +0 -0
- package/.loki/reference/chrome_docker_SingleValueRadial_basic_scp_theme.png +0 -0
- package/.loki/reference/chrome_docker_SingleValueRadial_fixed_height_300_width_300.png +0 -0
- package/.loki/reference/chrome_docker_SingleValueRadial_fixed_height_35_width_35.png +0 -0
- package/.loki/reference/chrome_docker_SingleValueRadial_no_props.png +0 -0
- package/GeoJsonChoropleth.js +107 -92
- package/GeoJsonChoropleth.js.map +1 -1
- package/SvgChoropleth.js +11 -9
- package/SvgChoropleth.js.map +1 -1
- package/package.json +12 -15
package/SvgChoropleth.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["webpack:///webpack/bootstrap","webpack:///external \"react\"","webpack:///external \"styled-components\"","webpack:///external \"@babel/runtime/helpers/createClass\"","webpack:///external \"@babel/runtime/helpers/classCallCheck\"","webpack:///external \"lodash\"","webpack:///external \"@babel/runtime/helpers/inherits\"","webpack:///external \"@babel/runtime/helpers/possibleConstructorReturn\"","webpack:///external \"@babel/runtime/helpers/getPrototypeOf\"","webpack:///./src/visualizations/SvgChoropleth/SvgChoropleth.tsx"],"names":[],"mappings":";;;;;;;QAAA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;;QAEA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;;;QAGA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA,0CAA0C,gCAAgC;QAC1E;QACA;;QAEA;QACA;QACA;QACA,wDAAwD,kBAAkB;QAC1E;QACA,iDAAiD,cAAc;QAC/D;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA,yCAAyC,iCAAiC;QAC1E,gHAAgH,mBAAmB,EAAE;QACrI;QACA;;QAEA;QACA;QACA;QACA,2BAA2B,0BAA0B,EAAE;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t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 29);\n","module.exports = require(\"react\");","module.exports = require(\"styled-components\");","module.exports = require(\"@babel/runtime/helpers/createClass\");","module.exports = require(\"@babel/runtime/helpers/classCallCheck\");","module.exports = require(\"lodash\");","module.exports = require(\"@babel/runtime/helpers/inherits\");","module.exports = require(\"@babel/runtime/helpers/possibleConstructorReturn\");","module.exports = require(\"@babel/runtime/helpers/getPrototypeOf\");","import * as React from 'react';\nimport { get, isEqual } from 'lodash';\nimport { ISvgFeatureCollection } from './src/utils/ISvgFeatureCollection';\nimport { DataPoint } from './src/utils/ICoordinateTransformation';\nimport styled from 'styled-components';\n\nexport const DATA_ATTRIBUTE = 'data-value';\n\nexport interface SvgChoroplethProps {\n featureCollection: ISvgFeatureCollection;\n data: { featureIDs: string[]; fill: string[]; values: any[] };\n fillColor: string;\n strokeColor: string;\n strokeHighlightColor?: string;\n backgroundColor?: string;\n selector: string;\n onFeatureHover: (params: { featureId: string; value: any; label?: string }) => void;\n onClick?: (sourceCoordinates: DataPoint, featureId: string) => void;\n}\n\nexport interface SvgChoroplethState {\n svgNode: React.ReactNode;\n}\n\nexport { GeoFeatureGroup } from './src/utils/GeoTypes';\n\ninterface StyledSvgChoroplethProps {\n readonly backgroundColor: string;\n}\n\nconst StyledSvgChoropleth = styled.div<StyledSvgChoroplethProps>`\n display: flex;\n flex-direction: column;\n position: relative;\n background-color: ${(props): string => props.backgroundColor};\n`;\n\nexport default class SvgChoropleth extends React.Component<SvgChoroplethProps, SvgChoroplethState> {\n containerRef: React.RefObject<HTMLDivElement> = React.createRef();\n //lastFeatureStroke: string;\n svgDom: SVGElement;\n highlightedCountry: SVGElement = null;\n\n constructor(props: SvgChoroplethProps) {\n super(props);\n const { featureCollection } = props;\n this.state = { svgNode: featureCollection.getSvgNode(this.registerSvg) };\n }\n\n shouldComponentUpdate(nextProps: Readonly<SvgChoroplethProps>, nextState: SvgChoroplethState): boolean {\n const shouldUpdate =\n !isEqual(nextState.svgNode, this.state.svgNode) || !isEqual(nextProps, this.props);\n return shouldUpdate;\n }\n\n componentDidUpdate(prevProps): void {\n if (this.props !== prevProps) {\n if (prevProps.featureCollection !== this.props.featureCollection) {\n this.setState({\n svgNode: this.props.featureCollection.getSvgNode(this.registerSvg),\n });\n } else {\n this.updateSvg(this.props);\n }\n }\n }\n\n /**\n * this method renders a copy of the polygon on top of all the others, with a highlighted boundary.\n * Technically we don't render in on top of ALL the others. There are three totally landlocked countries,\n * the first of which in our geojson file is Lesotho. These are also the last three countries in the geojson\n * file. So when we insert the highlight shape into the dom, we inert it *before* these three countries.\n * So the highlight for South Africa will not cover up Lesotho.\n * @param {SVGElement} el\n */\n highlightCountry(el: SVGElement): void {\n if (this.highlightedCountry) {\n return; // do not add more than one hovered element at a time\n }\n\n const firstLandlockedCountry = this.svgDom.querySelector(`#Lesotho`);\n const parent = el.parentNode;\n const clone: SVGElement = el.cloneNode(true) as SVGElement;\n const strokeColor = this.props.strokeHighlightColor || '#000';\n clone.style.stroke = strokeColor;\n this.highlightedCountry = clone;\n\n parent.insertBefore(clone, firstLandlockedCountry);\n }\n\n unHighlightCountry(): void {\n if (this.highlightedCountry) {\n this.svgDom.removeChild(this.highlightedCountry);\n }\n this.highlightedCountry = null;\n }\n\n getLocalCoords = (clientX: number, clientY: number): { x: number; y: number } => {\n const rect = this.containerRef.current.getBoundingClientRect();\n const physX = rect.left;\n const physY = rect.top;\n return { x: clientX - physX, y: clientY - physY };\n };\n\n handleMapClick = (event: React.MouseEvent<HTMLInputElement>): void => {\n const { clientX, clientY } = event;\n const pos = this.getLocalCoords(clientX, clientY);\n const { featureCollection, onClick } = this.props;\n const clickedCoords: DataPoint = featureCollection.transformation.transformBack(pos);\n const feature: SVGSVGElement = event.target as SVGSVGElement;\n const wholeFeature: SVGElement = feature.id ? feature : (feature.parentNode as SVGElement);\n if (onClick) {\n onClick(clickedCoords, wholeFeature.id);\n }\n };\n\n handleFeatureEnter = (ev: MouseEvent): void => {\n const feature: SVGSVGElement = ev.target as SVGSVGElement;\n\n if (!feature.id && !feature.ownerSVGElement) {\n return;\n }\n\n const wholeFeature: SVGElement = feature.id ? feature : (feature.parentNode as SVGElement);\n //remove the highlighted country IF we are entering a different country\n if (this.highlightedCountry && wholeFeature.id !== this.highlightedCountry.id) {\n this.unHighlightCountry();\n }\n this.highlightCountry(wholeFeature);\n\n if (this.props.onFeatureHover) {\n this.props.onFeatureHover({\n featureId: wholeFeature.id,\n label: wholeFeature.getAttribute('label_en'),\n value: wholeFeature.getAttribute(DATA_ATTRIBUTE),\n });\n }\n };\n\n handleFeatureLeave = (ev: MouseEvent): void => {\n const feature: SVGSVGElement = ev.target as SVGSVGElement;\n\n if (!feature.id && !feature.ownerSVGElement) {\n return;\n }\n\n // 'wholeFeature' means the SVG <g> (group) of multipolygon features\n const wholeFeature: SVGElement = feature.id ? feature : (feature.parentNode as SVGElement);\n //handling feature leaving should always only deal with the highlighted feature\n if (wholeFeature !== this.highlightedCountry) {\n return;\n }\n this.unHighlightCountry();\n //wholeFeature.style.stroke = this.lastFeatureStroke;\n\n if (this.props.onFeatureHover) {\n this.props.onFeatureHover({ featureId: null, value: null, label: null });\n }\n };\n\n registerSvg = (el: SVGSVGElement): void => {\n if (!el) return;\n\n this.svgDom = el;\n\n const { selector = '.feature', strokeColor, fillColor } = this.props;\n\n this.svgDom.onmouseover = this.handleFeatureEnter;\n this.svgDom.onmouseout = this.handleFeatureLeave;\n\n this.svgDom.querySelectorAll(selector).forEach((node: HTMLElement): void => {\n node.style.stroke = strokeColor;\n node.style.fill = fillColor;\n });\n\n this.updateSvg(this.props);\n };\n\n updateSvg(props: SvgChoroplethProps): void {\n if (!this.svgDom) {\n return;\n }\n\n const { selector = '.feature', fillColor, data } = props;\n\n if (!data) {\n return;\n }\n const dataHashMap = {};\n\n data.featureIDs.forEach((alias, index): void => {\n const featureId = this.getFeatureId(alias);\n dataHashMap[featureId] = { fill: data.fill[index], value: data.values[index] };\n });\n this.svgDom.querySelectorAll(selector).forEach((node: HTMLElement): void => {\n const nodeData = dataHashMap[node.id];\n node.style.fill = get(nodeData, 'fill') || fillColor;\n const value = get(nodeData, 'value');\n if (value) {\n node.setAttribute(DATA_ATTRIBUTE, value);\n } else {\n node.removeAttribute(DATA_ATTRIBUTE);\n }\n });\n }\n\n //allows a provided alias like 'US-CA' to get mapped to 'California' which is the element id for the SVG shape\n private getFeatureId(alias: string): string {\n return this.props.featureCollection.resolveAlias(alias);\n }\n\n render(): JSX.Element {\n const { backgroundColor = 'transparent' } = this.props;\n // note: for some reason, onclick event can't be triggered on dashboard. So change it to onMouseDown\n return (\n <StyledSvgChoropleth\n data-test=\"styled-svg-choropleth\"\n backgroundColor={backgroundColor}\n onMouseDown={this.handleMapClick}\n ref={this.containerRef}\n >\n {this.state.svgNode}\n </StyledSvgChoropleth>\n );\n }\n}\n"],"sourceRoot":""}
|
|
1
|
+
{"version":3,"sources":["webpack:///webpack/bootstrap","webpack:///external \"react\"","webpack:///external \"styled-components\"","webpack:///external \"@babel/runtime/helpers/createClass\"","webpack:///external \"@babel/runtime/helpers/classCallCheck\"","webpack:///external \"lodash\"","webpack:///external \"@babel/runtime/helpers/inherits\"","webpack:///external \"@babel/runtime/helpers/possibleConstructorReturn\"","webpack:///external \"@babel/runtime/helpers/getPrototypeOf\"","webpack:///./src/visualizations/SvgChoropleth/SvgChoropleth.tsx"],"names":[],"mappings":";;;;;;;QAAA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA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AAC,eAAL,CAAqB,sBAArB;AACH;AACJ,OATD;AAUH;;;WAED,kBAAM;AAAA,kCAC0C,KAAK,KAD/C,CACM,eADN;AAAA,UACM,eADN,sCACwB,aADxB,0BAEF;;AACA,aACI,oBAAC,mBAAD,EAAoB;AAAA,qBACN,uBADM;AAEhB,uBAAe,EAAE,eAFD;AAGhB,mBAAW,EAAE,KAAK,cAHF;AAIhB,WAAG,EAAE,KAAK;AAJM,OAApB,EAMK,KAAK,KAAL,CAAW,OANhB,CADJ;AAUH;;;;EA9LsC,KAAK,CAAC,S;;AAAjD,gC","file":"SvgChoropleth.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 29);\n","module.exports = require(\"react\");","module.exports = require(\"styled-components\");","module.exports = require(\"@babel/runtime/helpers/createClass\");","module.exports = require(\"@babel/runtime/helpers/classCallCheck\");","module.exports = require(\"lodash\");","module.exports = require(\"@babel/runtime/helpers/inherits\");","module.exports = require(\"@babel/runtime/helpers/possibleConstructorReturn\");","module.exports = require(\"@babel/runtime/helpers/getPrototypeOf\");","/* eslint-disable no-param-reassign */\nimport * as React from 'react';\nimport { get, isEqual } from 'lodash';\nimport styled from 'styled-components';\nimport { ISvgFeatureCollection } from './src/utils/ISvgFeatureCollection';\nimport { DataPoint } from './src/utils/ICoordinateTransformation';\n\nexport const DATA_ATTRIBUTE = 'data-value';\n\nexport interface SvgChoroplethProps {\n featureCollection: ISvgFeatureCollection;\n data: { featureIDs: string[]; fill: string[]; values: any[] };\n fillColor: string;\n strokeColor: string;\n strokeHighlightColor?: string;\n backgroundColor?: string;\n selector: string;\n onFeatureHover: (params: { featureId: string; value: any; label?: string }) => void;\n onClick?: (sourceCoordinates: DataPoint, featureId: string) => void;\n}\n\nexport interface SvgChoroplethState {\n svgNode: React.ReactNode;\n}\n\nexport { GeoFeatureGroup } from './src/utils/GeoTypes';\n\ninterface StyledSvgChoroplethProps {\n readonly backgroundColor: string;\n}\n\nconst StyledSvgChoropleth = styled.div<StyledSvgChoroplethProps>`\n display: flex;\n flex-direction: column;\n position: relative;\n background-color: ${(props): string => props.backgroundColor};\n`;\n\nexport default class SvgChoropleth extends React.Component<SvgChoroplethProps, SvgChoroplethState> {\n containerRef: React.RefObject<HTMLDivElement> = React.createRef();\n\n // lastFeatureStroke: string;\n svgDom: SVGElement;\n\n highlightedCountry: SVGElement = null;\n\n constructor(props: SvgChoroplethProps) {\n super(props);\n const { featureCollection } = props;\n this.state = { svgNode: featureCollection.getSvgNode(this.registerSvg) };\n }\n\n shouldComponentUpdate(nextProps: Readonly<SvgChoroplethProps>, nextState: SvgChoroplethState): boolean {\n const shouldUpdate =\n !isEqual(nextState.svgNode, this.state.svgNode) || !isEqual(nextProps, this.props);\n return shouldUpdate;\n }\n\n componentDidUpdate(prevProps): void {\n if (this.props !== prevProps) {\n if (prevProps.featureCollection !== this.props.featureCollection) {\n // eslint-disable-next-line react/no-did-update-set-state\n this.setState({\n svgNode: this.props.featureCollection.getSvgNode(this.registerSvg),\n });\n } else {\n this.updateSvg(this.props);\n }\n }\n }\n\n getLocalCoords = (clientX: number, clientY: number): { x: number; y: number } => {\n const rect = this.containerRef.current.getBoundingClientRect();\n const physX = rect.left;\n const physY = rect.top;\n return { x: clientX - physX, y: clientY - physY };\n };\n\n handleMapClick = (event: React.MouseEvent<HTMLInputElement>): void => {\n const { clientX, clientY } = event;\n const pos = this.getLocalCoords(clientX, clientY);\n const { featureCollection, onClick } = this.props;\n const clickedCoords: DataPoint = featureCollection.transformation.transformBack(pos);\n const feature: SVGSVGElement = event.target as SVGSVGElement;\n const wholeFeature: SVGElement = feature.id ? feature : (feature.parentNode as SVGElement);\n if (onClick) {\n onClick(clickedCoords, wholeFeature.id);\n }\n };\n\n handleFeatureEnter = (ev: MouseEvent): void => {\n const feature: SVGSVGElement = ev.target as SVGSVGElement;\n\n if (!feature.id && !feature.ownerSVGElement) {\n return;\n }\n\n const wholeFeature: SVGElement = feature.id ? feature : (feature.parentNode as SVGElement);\n // remove the highlighted country IF we are entering a different country\n if (this.highlightedCountry && wholeFeature.id !== this.highlightedCountry.id) {\n this.unHighlightCountry();\n }\n this.highlightCountry(wholeFeature);\n\n if (this.props.onFeatureHover) {\n this.props.onFeatureHover({\n featureId: wholeFeature.id,\n label: wholeFeature.getAttribute('label_en'),\n value: wholeFeature.getAttribute(DATA_ATTRIBUTE),\n });\n }\n };\n\n handleFeatureLeave = (ev: MouseEvent): void => {\n const feature: SVGSVGElement = ev.target as SVGSVGElement;\n\n if (!feature.id && !feature.ownerSVGElement) {\n return;\n }\n\n // 'wholeFeature' means the SVG <g> (group) of multipolygon features\n const wholeFeature: SVGElement = feature.id ? feature : (feature.parentNode as SVGElement);\n // handling feature leaving should always only deal with the highlighted feature\n if (wholeFeature !== this.highlightedCountry) {\n return;\n }\n this.unHighlightCountry();\n // wholeFeature.style.stroke = this.lastFeatureStroke;\n\n if (this.props.onFeatureHover) {\n this.props.onFeatureHover({ featureId: null, value: null, label: null });\n }\n };\n\n // allows a provided alias like 'US-CA' to get mapped to 'California' which is the element id for the SVG shape\n private getFeatureId(alias: string): string {\n return this.props.featureCollection.resolveAlias(alias);\n }\n\n registerSvg = (el: SVGSVGElement): void => {\n if (!el) return;\n\n this.svgDom = el;\n\n const { selector = '.feature', strokeColor, fillColor } = this.props;\n\n this.svgDom.onmouseover = this.handleFeatureEnter;\n this.svgDom.onmouseout = this.handleFeatureLeave;\n\n this.svgDom.querySelectorAll(selector).forEach((node: HTMLElement): void => {\n node.style.stroke = strokeColor;\n node.style.fill = fillColor;\n });\n\n this.updateSvg(this.props);\n };\n\n /**\n * this method renders a copy of the polygon on top of all the others, with a highlighted boundary.\n * Technically we don't render in on top of ALL the others. There are three totally landlocked countries,\n * the first of which in our geojson file is Lesotho. These are also the last three countries in the geojson\n * file. So when we insert the highlight shape into the dom, we inert it *before* these three countries.\n * So the highlight for South Africa will not cover up Lesotho.\n * @param {SVGElement} el\n */\n highlightCountry(el: SVGElement): void {\n if (this.highlightedCountry) {\n return; // do not add more than one hovered element at a time\n }\n\n const firstLandlockedCountry = this.svgDom.querySelector(`#Lesotho`);\n const parent = el.parentNode;\n const clone: SVGElement = el.cloneNode(true) as SVGElement;\n const strokeColor = this.props.strokeHighlightColor || '#000';\n clone.style.stroke = strokeColor;\n this.highlightedCountry = clone;\n\n parent.insertBefore(clone, firstLandlockedCountry);\n }\n\n unHighlightCountry(): void {\n if (this.highlightedCountry) {\n this.svgDom.removeChild(this.highlightedCountry);\n }\n this.highlightedCountry = null;\n }\n\n updateSvg(props: SvgChoroplethProps): void {\n if (!this.svgDom) {\n return;\n }\n\n const { selector = '.feature', fillColor, data } = props;\n\n if (!data) {\n return;\n }\n const dataHashMap = {};\n\n data.featureIDs.forEach((alias, index): void => {\n const featureId = this.getFeatureId(alias);\n dataHashMap[featureId] = { fill: data.fill[index], value: data.values[index] };\n });\n this.svgDom.querySelectorAll(selector).forEach((node: HTMLElement): void => {\n const nodeData = dataHashMap[node.id];\n node.style.fill = get(nodeData, 'fill') || fillColor;\n const value = get(nodeData, 'value');\n if (value) {\n node.setAttribute(DATA_ATTRIBUTE, value);\n } else {\n node.removeAttribute(DATA_ATTRIBUTE);\n }\n });\n }\n\n render(): JSX.Element {\n const { backgroundColor = 'transparent' } = this.props;\n // note: for some reason, onclick event can't be triggered on dashboard. So change it to onMouseDown\n return (\n <StyledSvgChoropleth\n data-test=\"styled-svg-choropleth\"\n backgroundColor={backgroundColor}\n onMouseDown={this.handleMapClick}\n ref={this.containerRef}\n >\n {this.state.svgNode}\n </StyledSvgChoropleth>\n );\n }\n}\n"],"sourceRoot":""}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@splunk/react-visualizations",
|
|
3
3
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
4
4
|
"author": "Splunk",
|
|
5
|
-
"version": "
|
|
5
|
+
"version": "24.1.0",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "NODE_ENV=production webpack --config ./webpack.config.js --bail",
|
|
8
8
|
"build-storybook": "build-storybook -c .storybook -s fonts -o .storybook-bundle",
|
|
@@ -13,14 +13,11 @@
|
|
|
13
13
|
"clean:test-reports": "rm -rf ./test-reports",
|
|
14
14
|
"dev": "NODE_ENV=development webpack --config ./webpack.config.js --watch",
|
|
15
15
|
"docs": "NODE_ENV=production webpack --config webpack.docs.config.js",
|
|
16
|
-
"docs:publish": "cicd-publish-docs build/docs --force",
|
|
16
|
+
"docs:publish": "echo \"skip publishing docs for the deprecated @splunk/react-visualizations package. If need to publish again, please change to `cicd-publish-docs build/docs --force`\"",
|
|
17
17
|
"docs:start": "webpack-dev-server --watch --config webpack.docs.config.js --open 'Google Chrome'",
|
|
18
|
-
"lint": "
|
|
18
|
+
"lint": "eslint src --ext \".js,.jsx,.es,.ts,.tsx\"",
|
|
19
19
|
"lint:ci": "eslint src --ext \".js,.jsx,.ts,.tsx\" -f junit -o test-reports/lint-results.xml",
|
|
20
|
-
"lint:fix": "yarn run lint
|
|
21
|
-
"lint:js": "eslint src --ext \".js,.jsx,.es\"",
|
|
22
|
-
"lint:ts": "eslint src --ext \".ts,.tsx\" --config ../../.tslintrc.js --no-eslintrc",
|
|
23
|
-
"publish:ci": "cicd-publish-package && cicd-publish-docs",
|
|
20
|
+
"lint:fix": "yarn run lint --fix",
|
|
24
21
|
"storybook": "start-storybook -p 6006 -c .storybook -s fonts",
|
|
25
22
|
"test": "yarn run test:unit && yarn run test:visual",
|
|
26
23
|
"test:ci": "yarn run test:unit:ci && yarn run test:visual:ci",
|
|
@@ -33,14 +30,13 @@
|
|
|
33
30
|
},
|
|
34
31
|
"dependencies": {
|
|
35
32
|
"@babel/runtime": "^7.13.0",
|
|
36
|
-
"@splunk/charting-bundle": "^
|
|
33
|
+
"@splunk/charting-bundle": "^24.1.0",
|
|
37
34
|
"@splunk/moment": "^0.6.0",
|
|
38
35
|
"@splunk/ui-utils": "^1.2.1",
|
|
39
|
-
"@splunk/visualization-color-palettes": "^
|
|
40
|
-
"@splunk/visualization-
|
|
41
|
-
"@splunk/
|
|
42
|
-
"@splunk/visualizations": "^
|
|
43
|
-
"@splunk/visualizations-shared": "^23.5.0",
|
|
36
|
+
"@splunk/visualization-color-palettes": "^24.1.0",
|
|
37
|
+
"@splunk/visualization-themes": "^24.1.0",
|
|
38
|
+
"@splunk/visualizations": "^24.1.0",
|
|
39
|
+
"@splunk/visualizations-shared": "^24.1.0",
|
|
44
40
|
"@turf/bbox-clip": "^6.0.3",
|
|
45
41
|
"@turf/helpers": "^6.1.4",
|
|
46
42
|
"chroma-js": "^2.0.0",
|
|
@@ -51,6 +47,7 @@
|
|
|
51
47
|
"xpath": "^0.0.32"
|
|
52
48
|
},
|
|
53
49
|
"peerDependencies": {
|
|
50
|
+
"@splunk/visualization-context": ">=24.0.0",
|
|
54
51
|
"react": "^16.11.0",
|
|
55
52
|
"react-dom": "^16.11.0",
|
|
56
53
|
"styled-components": "^5.1"
|
|
@@ -62,9 +59,9 @@
|
|
|
62
59
|
"@splunk/docs-gen": "^0.11.1",
|
|
63
60
|
"@splunk/jsdoc-loader": "^3.0.0",
|
|
64
61
|
"@splunk/react-docs": "^0.11.0",
|
|
65
|
-
"@splunk/react-ui": "^4.
|
|
62
|
+
"@splunk/react-ui": "^4.4.1",
|
|
66
63
|
"@splunk/themes": "^0.8.0",
|
|
67
|
-
"@splunk/visualization-build-tools": "^
|
|
64
|
+
"@splunk/visualization-build-tools": "^24.1.0",
|
|
68
65
|
"@splunk/webpack-configs": "^4.0.0",
|
|
69
66
|
"@storybook/addon-actions": "^6.1.20",
|
|
70
67
|
"@storybook/addons": "^6.1.20",
|