@unovis/ts 1.3.0-alpha.2 → 1.3.0-beta.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/components/area/config.d.ts +6 -10
- package/components/area/config.js +3 -12
- package/components/area/config.js.map +1 -1
- package/components/area/index.d.ts +5 -6
- package/components/area/index.js +10 -9
- package/components/area/index.js.map +1 -1
- package/components/axis/config.d.ts +3 -27
- package/components/axis/config.js +3 -30
- package/components/axis/config.js.map +1 -1
- package/components/axis/index.d.ts +4 -3
- package/components/axis/index.js +7 -4
- package/components/axis/index.js.map +1 -1
- package/components/brush/config.d.ts +2 -12
- package/components/brush/config.js +11 -20
- package/components/brush/config.js.map +1 -1
- package/components/brush/index.d.ts +4 -3
- package/components/brush/index.js +4 -3
- package/components/brush/index.js.map +1 -1
- package/components/bullet-legend/config.d.ts +5 -11
- package/components/bullet-legend/config.js +12 -13
- package/components/bullet-legend/config.js.map +1 -1
- package/components/bullet-legend/index.d.ts +4 -3
- package/components/bullet-legend/index.js +11 -18
- package/components/bullet-legend/index.js.map +1 -1
- package/components/bullet-legend/modules/shape.d.ts +6 -0
- package/components/bullet-legend/modules/shape.js +58 -0
- package/components/bullet-legend/modules/shape.js.map +1 -0
- package/components/bullet-legend/style.js +6 -9
- package/components/bullet-legend/style.js.map +1 -1
- package/components/bullet-legend/types.d.ts +5 -0
- package/components/bullet-legend/types.js +7 -0
- package/components/bullet-legend/types.js.map +1 -1
- package/components/chord-diagram/config.d.ts +7 -23
- package/components/chord-diagram/config.js +3 -22
- package/components/chord-diagram/config.js.map +1 -1
- package/components/chord-diagram/index.d.ts +4 -3
- package/components/chord-diagram/index.js +7 -6
- package/components/chord-diagram/index.js.map +1 -1
- package/components/chord-diagram/modules/label.d.ts +3 -3
- package/components/chord-diagram/modules/label.js +1 -1
- package/components/chord-diagram/modules/label.js.map +1 -1
- package/components/chord-diagram/modules/link.d.ts +2 -2
- package/components/chord-diagram/modules/link.js.map +1 -1
- package/components/chord-diagram/modules/node.d.ts +2 -2
- package/components/chord-diagram/modules/node.js.map +1 -1
- package/components/chord-diagram/types.d.ts +3 -2
- package/components/chord-diagram/types.js.map +1 -1
- package/components/crosshair/config.d.ts +6 -14
- package/components/crosshair/config.js +3 -16
- package/components/crosshair/config.js.map +1 -1
- package/components/crosshair/index.d.ts +4 -3
- package/components/crosshair/index.js +4 -3
- package/components/crosshair/index.js.map +1 -1
- package/components/donut/config.d.ts +2 -19
- package/components/donut/config.js +5 -24
- package/components/donut/config.js.map +1 -1
- package/components/donut/index.d.ts +4 -3
- package/components/donut/index.js +5 -4
- package/components/donut/index.js.map +1 -1
- package/components/donut/modules/arc.d.ts +3 -3
- package/components/donut/modules/arc.js.map +1 -1
- package/components/flow-legend/config.d.ts +1 -11
- package/components/flow-legend/config.js +11 -16
- package/components/flow-legend/config.js.map +1 -1
- package/components/flow-legend/index.d.ts +4 -3
- package/components/flow-legend/index.js +5 -2
- package/components/flow-legend/index.js.map +1 -1
- package/components/free-brush/config.d.ts +2 -12
- package/components/free-brush/config.js +11 -20
- package/components/free-brush/config.js.map +1 -1
- package/components/free-brush/index.d.ts +4 -3
- package/components/free-brush/index.js +6 -5
- package/components/free-brush/index.js.map +1 -1
- package/components/graph/config.d.ts +3 -75
- package/components/graph/config.js +12 -78
- package/components/graph/config.js.map +1 -1
- package/components/graph/index.d.ts +8 -7
- package/components/graph/index.js +4 -3
- package/components/graph/index.js.map +1 -1
- package/components/graph/modules/layout.d.ts +7 -7
- package/components/graph/modules/layout.js.map +1 -1
- package/components/graph/modules/link/helper.d.ts +5 -5
- package/components/graph/modules/link/helper.js.map +1 -1
- package/components/graph/modules/link/index.d.ts +6 -6
- package/components/graph/modules/link/index.js.map +1 -1
- package/components/graph/modules/node/index.d.ts +6 -6
- package/components/graph/modules/node/index.js +2 -2
- package/components/graph/modules/node/index.js.map +1 -1
- package/components/graph/modules/panel/helper.d.ts +4 -4
- package/components/graph/modules/panel/helper.js.map +1 -1
- package/components/graph/modules/panel/index.d.ts +3 -3
- package/components/graph/modules/panel/index.js.map +1 -1
- package/components/grouped-bar/config.d.ts +5 -13
- package/components/grouped-bar/config.js +5 -16
- package/components/grouped-bar/config.js.map +1 -1
- package/components/grouped-bar/index.d.ts +4 -3
- package/components/grouped-bar/index.js +4 -3
- package/components/grouped-bar/index.js.map +1 -1
- package/components/leaflet-flow-map/config.d.ts +2 -16
- package/components/leaflet-flow-map/config.js +3 -21
- package/components/leaflet-flow-map/config.js.map +1 -1
- package/components/leaflet-flow-map/index.d.ts +4 -3
- package/components/leaflet-flow-map/index.js +3 -2
- package/components/leaflet-flow-map/index.js.map +1 -1
- package/components/leaflet-map/config.d.ts +4 -59
- package/components/leaflet-map/config.js +23 -67
- package/components/leaflet-map/config.js.map +1 -1
- package/components/leaflet-map/index.d.ts +4 -3
- package/components/leaflet-map/index.js +4 -3
- package/components/leaflet-map/index.js.map +1 -1
- package/components/leaflet-map/modules/map.d.ts +3 -3
- package/components/leaflet-map/modules/map.js.map +1 -1
- package/components/leaflet-map/modules/utils.d.ts +4 -4
- package/components/leaflet-map/modules/utils.js +6 -2
- package/components/leaflet-map/modules/utils.js.map +1 -1
- package/components/leaflet-map/renderer/mapboxgl-layer.d.ts +2 -2
- package/components/leaflet-map/renderer/mapboxgl-layer.js.map +1 -1
- package/components/line/config.d.ts +6 -11
- package/components/line/config.js +3 -13
- package/components/line/config.js.map +1 -1
- package/components/line/index.d.ts +4 -3
- package/components/line/index.js +5 -4
- package/components/line/index.js.map +1 -1
- package/components/nested-donut/config.d.ts +2 -21
- package/components/nested-donut/config.js +3 -24
- package/components/nested-donut/config.js.map +1 -1
- package/components/nested-donut/index.d.ts +4 -3
- package/components/nested-donut/index.js +15 -12
- package/components/nested-donut/index.js.map +1 -1
- package/components/nested-donut/modules/arc.d.ts +3 -3
- package/components/nested-donut/modules/arc.js +2 -1
- package/components/nested-donut/modules/arc.js.map +1 -1
- package/components/nested-donut/modules/label.d.ts +2 -2
- package/components/nested-donut/modules/label.js +9 -6
- package/components/nested-donut/modules/label.js.map +1 -1
- package/components/nested-donut/types.d.ts +1 -0
- package/components/nested-donut/types.js.map +1 -1
- package/components/sankey/config.d.ts +2 -47
- package/components/sankey/config.js +10 -57
- package/components/sankey/config.js.map +1 -1
- package/components/sankey/index.d.ts +4 -3
- package/components/sankey/index.js +3 -2
- package/components/sankey/index.js.map +1 -1
- package/components/sankey/modules/label.d.ts +7 -7
- package/components/sankey/modules/label.js.map +1 -1
- package/components/sankey/modules/link.d.ts +2 -2
- package/components/sankey/modules/link.js.map +1 -1
- package/components/sankey/modules/node.d.ts +7 -7
- package/components/sankey/modules/node.js +1 -1
- package/components/sankey/modules/node.js.map +1 -1
- package/components/scatter/config.d.ts +4 -16
- package/components/scatter/config.js +5 -19
- package/components/scatter/config.js.map +1 -1
- package/components/scatter/index.d.ts +4 -3
- package/components/scatter/index.js +5 -5
- package/components/scatter/index.js.map +1 -1
- package/components/scatter/modules/point.d.ts +2 -2
- package/components/scatter/modules/point.js.map +1 -1
- package/components/scatter/modules/utils.d.ts +2 -2
- package/components/scatter/modules/utils.js.map +1 -1
- package/components/stacked-bar/config.d.ts +5 -13
- package/components/stacked-bar/config.js +5 -16
- package/components/stacked-bar/config.js.map +1 -1
- package/components/stacked-bar/index.d.ts +4 -3
- package/components/stacked-bar/index.js +4 -3
- package/components/stacked-bar/index.js.map +1 -1
- package/components/timeline/config.d.ts +5 -16
- package/components/timeline/config.js +9 -21
- package/components/timeline/config.js.map +1 -1
- package/components/timeline/index.d.ts +4 -3
- package/components/timeline/index.js +4 -3
- package/components/timeline/index.js.map +1 -1
- package/components/tooltip/config.d.ts +1 -15
- package/components/tooltip/config.js +12 -16
- package/components/tooltip/config.js.map +1 -1
- package/components/tooltip/index.d.ts +4 -3
- package/components/tooltip/index.js +5 -3
- package/components/tooltip/index.js.map +1 -1
- package/components/topojson-map/config.d.ts +4 -36
- package/components/topojson-map/config.js +3 -38
- package/components/topojson-map/config.js.map +1 -1
- package/components/topojson-map/index.d.ts +4 -3
- package/components/topojson-map/index.js +4 -4
- package/components/topojson-map/index.js.map +1 -1
- package/components/vis-controls/config.d.ts +1 -5
- package/components/vis-controls/config.js +6 -9
- package/components/vis-controls/config.js.map +1 -1
- package/components/vis-controls/index.d.ts +3 -2
- package/components/vis-controls/index.js +5 -2
- package/components/vis-controls/index.js.map +1 -1
- package/components/xy-labels/config.d.ts +4 -16
- package/components/xy-labels/config.js +5 -20
- package/components/xy-labels/config.js.map +1 -1
- package/components/xy-labels/index.d.ts +4 -3
- package/components/xy-labels/index.js +3 -2
- package/components/xy-labels/index.js.map +1 -1
- package/components/xy-labels/modules/label.d.ts +3 -3
- package/components/xy-labels/modules/label.js +1 -1
- package/components/xy-labels/modules/label.js.map +1 -1
- package/containers/single-container/config.d.ts +2 -4
- package/containers/single-container/config.js +3 -8
- package/containers/single-container/config.js.map +1 -1
- package/containers/single-container/index.d.ts +4 -3
- package/containers/single-container/index.js +2 -2
- package/containers/single-container/index.js.map +1 -1
- package/containers/xy-container/config.d.ts +2 -22
- package/containers/xy-container/config.js +3 -26
- package/containers/xy-container/config.js.map +1 -1
- package/containers/xy-container/index.d.ts +3 -2
- package/containers/xy-container/index.js +2 -2
- package/containers/xy-container/index.js.map +1 -1
- package/core/component/config.d.ts +1 -6
- package/core/component/config.js +6 -12
- package/core/component/config.js.map +1 -1
- package/core/component/index.d.ts +7 -5
- package/core/component/index.js +8 -7
- package/core/component/index.js.map +1 -1
- package/core/container/config.d.ts +1 -21
- package/core/container/config.js +21 -25
- package/core/container/config.js.map +1 -1
- package/core/container/index.d.ts +5 -4
- package/core/container/index.js +4 -3
- package/core/container/index.js.map +1 -1
- package/core/xy-component/config.d.ts +2 -10
- package/core/xy-component/config.js +7 -16
- package/core/xy-component/config.js.map +1 -1
- package/core/xy-component/index.d.ts +5 -4
- package/core/xy-component/index.js +2 -0
- package/core/xy-component/index.js.map +1 -1
- package/data-models/map-graph.d.ts +1 -1
- package/data-models/map-graph.js +1 -1
- package/data-models/map-graph.js.map +1 -1
- package/index.js +1 -0
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/types/accessor.d.ts +1 -1
- package/types.js +1 -1
- package/utils/color.d.ts +7 -3
- package/utils/color.js +18 -2
- package/utils/color.js.map +1 -1
- package/utils/data.d.ts +1 -1
- package/utils/data.js.map +1 -1
- package/core/config/index.d.ts +0 -3
- package/core/config/index.js +0 -16
- package/core/config/index.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../../../src/components/leaflet-map/modules/utils.ts"],"sourcesContent":["import type L from 'leaflet'\nimport { min, max } from 'd3-array'\nimport Supercluster, { ClusterFeature, PointFeature } from 'supercluster'\n\n// Utils\nimport { clamp, getString, getNumber } from 'utils/data'\nimport { getColor } from 'utils/color'\nimport { polygon, circlePath } from 'utils/path'\nimport { getHTMLTransform } from 'utils/html'\n\n// Types\nimport { NumericAccessor, StringAccessor } from 'types/accessor'\nimport { GenericDataRecord } from 'types/data'\n\n// Local Types\nimport {\n LeafletMapPoint,\n LeafletMapPointShape,\n LeafletMapPieDatum,\n LeafletMapPointStyles,\n PointExpandedClusterProperties,\n LeafletMapPointDatum,\n LeafletMapClusterDatum,\n} from '../types'\n\n// Config\nimport { LeafletMapConfig } from '../config'\n\nexport function bBoxMerge (\n bBoxArray: ({x1: number; x2: number; y1: number; y2: number})[]):\n { x: number; y: number; width: number; height: number } {\n let box = { x1: 0, x2: 0, y1: 0, y2: 0 }\n bBoxArray.forEach(coords => {\n if (!box) {\n box = { ...coords }\n } else {\n if (box.x1 > coords.x1) box.x1 = coords.x1\n if (box.y1 > coords.y1) box.y1 = coords.y1\n if (box.x2 < coords.x2) box.x2 = coords.x2\n if (box.y2 < coords.y2) box.y2 = coords.y2\n }\n })\n\n return {\n x: box.x1,\n y: box.y1,\n width: box.x2 - box.x1,\n height: box.y2 - box.y1,\n }\n}\n\nexport const getNextZoomLevelOnClusterClick = (level: number): number => clamp(1 + level * 1.5, level, 12)\n\nexport function projectPoint<D extends GenericDataRecord> (\n geoJSONPoint: LeafletMapPoint<D> | ClusterFeature<LeafletMapClusterDatum<D>> | PointFeature<LeafletMapPointDatum<D>>,\n leafletMap: L.Map\n): { x: number; y: number } {\n const lat = geoJSONPoint.geometry.coordinates[1]\n const lon = geoJSONPoint.geometry.coordinates[0]\n const projected = leafletMap.latLngToLayerPoint([lat, lon])\n return projected\n}\n\nexport function getPointRadius<D extends GenericDataRecord> (\n geoPoint: ClusterFeature<LeafletMapClusterDatum<D>> | PointFeature<LeafletMapPointDatum<D>> | PointFeature<PointExpandedClusterProperties<D>>,\n pointRadius: NumericAccessor<D>,\n zoomLevel: number\n): number {\n const isDynamic = !pointRadius\n const radius = isDynamic ? 1 + 2 * Math.pow(zoomLevel, 0.80) : getNumber((geoPoint.properties as LeafletMapPointDatum<D>), pointRadius)\n\n const isCluster = (geoPoint as ClusterFeature<D>).properties.cluster\n return (isCluster && isDynamic)\n ? clamp(Math.pow((geoPoint as ClusterFeature<D>).properties.point_count, 0.35) * radius, radius * 1.1, radius * 3)\n : radius\n}\n\nexport function getPointPos<D extends GenericDataRecord> (point: LeafletMapPoint<D> | ClusterFeature<LeafletMapClusterDatum<D>> | PointFeature<LeafletMapPointDatum<D>>, leafletMap: L.Map): { x: number; y: number } {\n const properties = point.properties as LeafletMapPointDatum<D>\n const isFromCluster = !!(properties).expandedClusterPoint\n\n if (isFromCluster) {\n const { x, y } = projectPoint(properties.expandedClusterPoint, leafletMap)\n return {\n x: x + properties.dx,\n y: y + properties.dy,\n }\n } else {\n return projectPoint(point, leafletMap)\n }\n}\n\nexport function getPointDisplayOrder<D extends GenericDataRecord> (\n d: LeafletMapPoint<D>,\n pointStatus: StringAccessor<LeafletMapPointDatum<D> | LeafletMapClusterDatum<D>>,\n colorMap: LeafletMapPointStyles<D>\n): number {\n const status = getString(d.properties, pointStatus)\n const statusList = Object.keys(colorMap)\n return Object.keys(statusList).indexOf(status)\n}\n\nexport function toGeoJSONPoint<D extends GenericDataRecord> (d: D, i: number, pointLatitude: NumericAccessor<D>, pointLongitude: NumericAccessor<D>): PointFeature<D> {\n const lat = getNumber(d, pointLatitude) as number\n const lon = getNumber(d, pointLongitude) as number\n\n return {\n type: 'Feature',\n properties: {\n ...d,\n _index: i,\n },\n geometry: {\n type: 'Point',\n coordinates: [lon, lat],\n },\n }\n}\n\nexport function calculateClusterIndex<D extends GenericDataRecord> (data: D[], config: LeafletMapConfig<D>, maxClusterZoomLevel = 23): Supercluster<D> {\n const { colorMap, pointShape, pointLatitude, pointLongitude, clusteringDistance } = config\n return new Supercluster<D, Supercluster.AnyProps>({\n radius: clusteringDistance,\n maxZoom: maxClusterZoomLevel,\n map: (d): Supercluster.AnyProps => {\n const shape = getString(d, pointShape)\n\n const clusterPoint = { shape }\n for (const key of Object.keys(colorMap)) {\n clusterPoint[key] = d[key] || 0\n }\n\n return clusterPoint\n },\n reduce: (acc, clusterPoint): void => {\n acc.shape = acc.shape === clusterPoint.shape ? acc.shape : LeafletMapPointShape.Circle\n acc.value = (acc.value ?? 0) + (clusterPoint.value ?? 0)\n\n for (const key of Object.keys(colorMap)) {\n acc[key] += clusterPoint[key]\n }\n },\n }).load(data.map((d, i) => toGeoJSONPoint(d, i, pointLatitude, pointLongitude)))\n}\n\nexport function getNodePathData ({ x, y }: { x: number; y: number }, radius: number, shape: LeafletMapPointShape): string {\n switch (shape) {\n case LeafletMapPointShape.Triangle:\n return polygon(radius * 2, 3)\n case LeafletMapPointShape.Square:\n return polygon(radius * 2, 4)\n case LeafletMapPointShape.Circle:\n case LeafletMapPointShape.Ring:\n default:\n return circlePath(x, y, radius)\n }\n}\n\nexport function getDonutData<D extends GenericDataRecord> (\n d: LeafletMapClusterDatum<D> | LeafletMapPointDatum<D>,\n colorMap: LeafletMapPointStyles<D>\n): LeafletMapPieDatum[] {\n return Object.keys(colorMap).map(key => ({\n name: key,\n value: d[key] as number,\n color: colorMap[key].color,\n className: colorMap[key].className,\n }))\n}\n\nexport function geoJsonPointToScreenPoint<D extends GenericDataRecord> (\n geoPoint: ClusterFeature<LeafletMapClusterDatum<D>> | PointFeature<LeafletMapPointDatum<D>>,\n i: number,\n leafletMap: L.Map,\n config: LeafletMapConfig<D>\n): LeafletMapPoint<D> {\n const zoomLevel = leafletMap.getZoom()\n const isCluster = (geoPoint.properties as LeafletMapClusterDatum<D>).cluster\n const clusterIndex = (geoPoint.properties as LeafletMapClusterDatum<D>).clusterIndex\n const clusterPoints = isCluster ? clusterIndex.getLeaves((geoPoint.properties as LeafletMapClusterDatum<D>).cluster_id as number, Infinity).map(d => d.properties) : undefined\n const { x, y } = getPointPos(geoPoint, leafletMap)\n\n const id = isCluster ? `cluster-${geoPoint.id}` : (getString(geoPoint.properties as LeafletMapPointDatum<D>, config.pointId) ?? geoPoint.geometry.coordinates.join(''))\n const pointColor = getColor(geoPoint.properties, isCluster ? config.clusterColor : config.pointColor)\n const radius = getPointRadius(geoPoint, isCluster ? config.clusterRadius : config.pointRadius, zoomLevel)\n const shape = isCluster ? LeafletMapPointShape.Circle : getString(geoPoint.properties as LeafletMapPointDatum<D>, config.pointShape) as LeafletMapPointShape\n const isRing = shape === LeafletMapPointShape.Ring\n\n const donutData = getDonutData(geoPoint.properties, config.colorMap)\n const maxValue = max(donutData, d => d.value)\n const maxValueIndex = donutData.map(d => d.value).indexOf(maxValue)\n const biggestDatum = donutData[maxValueIndex ?? 0]\n\n const color = isCluster ? pointColor\n : (isRing ? null : (pointColor ?? biggestDatum?.color))\n const bbox = { x1: x - radius, y1: y - radius, x2: x + radius, y2: y + radius }\n const path = getNodePathData({ x: 0, y: 0 }, radius, shape)\n const _zIndex = 0\n\n const screenPoint: LeafletMapPoint<D> = {\n ...geoPoint,\n id,\n bbox,\n radius,\n donutData,\n path,\n color,\n isCluster,\n clusterIndex,\n clusterPoints,\n _zIndex,\n }\n\n return screenPoint\n}\n\nexport function shouldClusterExpand<D extends GenericDataRecord> (\n cluster: LeafletMapPoint<D>,\n zoomLevel: number,\n midLevel = 4,\n maxLevel = 8,\n maxClusterZoomLevel = 23\n): boolean {\n if (!cluster) return false\n\n const clusterExpansionZoomLevel = cluster.clusterIndex.getClusterExpansionZoom(cluster.properties.cluster_id as number)\n return zoomLevel >= maxLevel ||\n (zoomLevel >= midLevel && (cluster.properties.point_count < 20 || clusterExpansionZoomLevel >= maxClusterZoomLevel))\n}\n\nexport function findPointAndClusterByPointId<D extends GenericDataRecord> (\n points: LeafletMapPoint<D>[],\n id: string,\n pointId: StringAccessor<D>\n): {\n point: PointFeature<D> | undefined;\n cluster: LeafletMapPoint<D> | undefined;\n } {\n let point\n let cluster\n points.forEach(p => {\n if (p.isCluster) {\n const leaves = p.clusterIndex.getLeaves((p.properties as LeafletMapClusterDatum<D>).cluster_id as number, Infinity) ?? []\n const foundPoint = leaves.find(d => getString(d.properties, pointId) === id)\n if (foundPoint) {\n point = foundPoint\n cluster = p\n }\n }\n })\n return { point, cluster }\n}\n\nexport function getNodeRelativePosition<D extends GenericDataRecord> (d: LeafletMapPoint<D>, leafletMap: L.Map): { x: number; y: number } {\n const paneTransform = getHTMLTransform(leafletMap.getPane('mapPane'))\n const { x, y } = getPointPos(d, leafletMap)\n return { x: x + paneTransform[0], y: y + paneTransform[1] }\n}\n\nexport function getClusterRadius<D extends GenericDataRecord> (cluster: { points: PointFeature<PointExpandedClusterProperties<D>>[]; cluster: LeafletMapPoint<D> }): number {\n const { points } = cluster\n const minX = min<number>(points.map(d => d.properties.dx - d.properties.r))\n const maxX = max<number>(points.map(d => d.properties.dx + d.properties.r))\n const minY = min<number>(points.map(d => d.properties.dy - d.properties.r))\n const maxY = max<number>(points.map(d => d.properties.dy + d.properties.r))\n return Math.sqrt((maxX - minX) ** 2 + (maxY - minY) ** 2) * 0.5\n}\n\nexport function getClustersAndPoints<D extends GenericDataRecord> (\n clusterIndex: Supercluster<D>,\n leafletMap: L.Map,\n customBounds?: [number, number, number, number]\n): (ClusterFeature<LeafletMapClusterDatum<D>> | PointFeature<D>)[] {\n const leafletBounds = leafletMap.getBounds()\n const southWest = leafletBounds.getSouthWest()\n const northEast = leafletBounds.getNorthEast()\n const bounds = customBounds || [southWest.lng, southWest.lat, northEast.lng, northEast.lat]\n const zoom = Math.round(leafletMap.getZoom())\n const points = clusterIndex.getClusters(bounds, zoom) // as ClusterFeature<LeafletMapPointDatum<D>>[]\n\n for (const p of points) {\n const point = p as ClusterFeature<LeafletMapClusterDatum<D>>\n const isCluster = point.properties.cluster\n if (isCluster) {\n point.properties.clusterIndex = clusterIndex\n point.properties.clusterPoints = clusterIndex.getLeaves(point.properties.cluster_id, Infinity).map(d => d.properties)\n }\n }\n\n return points as (ClusterFeature<LeafletMapClusterDatum<D>> | PointFeature<D>)[]\n}\n"],"names":[],"mappings":";;;;;;;;AA4BM,SAAU,SAAS,CACvB,SAA+D,EAAA;AAE/D,IAAA,IAAI,GAAG,GAAG,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAA;AACxC,IAAA,SAAS,CAAC,OAAO,CAAC,MAAM,IAAG;QACzB,IAAI,CAAC,GAAG,EAAE;YACR,GAAG,GAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EAAQ,MAAM,CAAE,CAAA;AACpB,SAAA;AAAM,aAAA;AACL,YAAA,IAAI,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC,EAAE;AAAE,gBAAA,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC,EAAE,CAAA;AAC1C,YAAA,IAAI,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC,EAAE;AAAE,gBAAA,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC,EAAE,CAAA;AAC1C,YAAA,IAAI,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC,EAAE;AAAE,gBAAA,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC,EAAE,CAAA;AAC1C,YAAA,IAAI,GAAG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E,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,CAAA;AACtH,SAAA;AACF,KAAA;AAED,IAAA,OAAO,MAAyE,CAAA;AAClF;;;;"}
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../../src/components/leaflet-map/modules/utils.ts"],"sourcesContent":["import type L from 'leaflet'\nimport { min, max } from 'd3-array'\nimport Supercluster, { ClusterFeature, PointFeature } from 'supercluster'\n\n// Utils\nimport { clamp, getString, getNumber } from 'utils/data'\nimport { getColor } from 'utils/color'\nimport { polygon, circlePath } from 'utils/path'\nimport { getHTMLTransform } from 'utils/html'\n\n// Types\nimport { ColorAccessor, NumericAccessor, StringAccessor } from 'types/accessor'\nimport { GenericDataRecord } from 'types/data'\n\n// Local Types\nimport {\n LeafletMapPoint,\n LeafletMapPointShape,\n LeafletMapPieDatum,\n LeafletMapPointStyles,\n PointExpandedClusterProperties,\n LeafletMapPointDatum,\n LeafletMapClusterDatum,\n} from '../types'\n\n// Config\nimport { LeafletMapConfigInterface } from '../config'\n\nexport function bBoxMerge (\n bBoxArray: ({x1: number; x2: number; y1: number; y2: number})[]):\n { x: number; y: number; width: number; height: number } {\n let box = { x1: 0, x2: 0, y1: 0, y2: 0 }\n bBoxArray.forEach(coords => {\n if (!box) {\n box = { ...coords }\n } else {\n if (box.x1 > coords.x1) box.x1 = coords.x1\n if (box.y1 > coords.y1) box.y1 = coords.y1\n if (box.x2 < coords.x2) box.x2 = coords.x2\n if (box.y2 < coords.y2) box.y2 = coords.y2\n }\n })\n\n return {\n x: box.x1,\n y: box.y1,\n width: box.x2 - box.x1,\n height: box.y2 - box.y1,\n }\n}\n\nexport const getNextZoomLevelOnClusterClick = (level: number): number => clamp(1 + level * 1.5, level, 12)\n\nexport function projectPoint<D extends GenericDataRecord> (\n geoJSONPoint: LeafletMapPoint<D> | ClusterFeature<LeafletMapClusterDatum<D>> | PointFeature<LeafletMapPointDatum<D>>,\n leafletMap: L.Map\n): { x: number; y: number } {\n const lat = geoJSONPoint.geometry.coordinates[1]\n const lon = geoJSONPoint.geometry.coordinates[0]\n const projected = leafletMap.latLngToLayerPoint([lat, lon])\n return projected\n}\n\nexport function getPointRadius<D extends GenericDataRecord> (\n geoPoint: ClusterFeature<LeafletMapClusterDatum<D>> | PointFeature<LeafletMapPointDatum<D>> | PointFeature<PointExpandedClusterProperties<D>>,\n pointRadius: NumericAccessor<LeafletMapPointDatum<D>> | NumericAccessor<LeafletMapClusterDatum<D>>,\n zoomLevel: number\n): number {\n const isDynamic = !pointRadius\n const radius = isDynamic\n ? 1 + 2 * Math.pow(zoomLevel, 0.80)\n // Todo: Needs a better typings handling\n : getNumber((geoPoint.properties as LeafletMapPointDatum<D>), pointRadius as NumericAccessor<LeafletMapPointDatum<D>>)\n\n const isCluster = (geoPoint as ClusterFeature<D>).properties.cluster\n return (isCluster && isDynamic)\n ? clamp(Math.pow((geoPoint as ClusterFeature<D>).properties.point_count, 0.35) * radius, radius * 1.1, radius * 3)\n : radius\n}\n\nexport function getPointPos<D extends GenericDataRecord> (point: LeafletMapPoint<D> | ClusterFeature<LeafletMapClusterDatum<D>> | PointFeature<LeafletMapPointDatum<D>>, leafletMap: L.Map): { x: number; y: number } {\n const properties = point.properties as LeafletMapPointDatum<D>\n const isFromCluster = !!(properties).expandedClusterPoint\n\n if (isFromCluster) {\n const { x, y } = projectPoint(properties.expandedClusterPoint, leafletMap)\n return {\n x: x + properties.dx,\n y: y + properties.dy,\n }\n } else {\n return projectPoint(point, leafletMap)\n }\n}\n\nexport function getPointDisplayOrder<D extends GenericDataRecord> (\n d: LeafletMapPoint<D>,\n pointStatus: StringAccessor<LeafletMapPointDatum<D> | LeafletMapClusterDatum<D>>,\n colorMap: LeafletMapPointStyles<D>\n): number {\n const status = getString(d.properties, pointStatus)\n const statusList = Object.keys(colorMap)\n return Object.keys(statusList).indexOf(status)\n}\n\nexport function toGeoJSONPoint<D extends GenericDataRecord> (d: D, i: number, pointLatitude: NumericAccessor<D>, pointLongitude: NumericAccessor<D>): PointFeature<D> {\n const lat = getNumber(d, pointLatitude) as number\n const lon = getNumber(d, pointLongitude) as number\n\n return {\n type: 'Feature',\n properties: {\n ...d,\n _index: i,\n },\n geometry: {\n type: 'Point',\n coordinates: [lon, lat],\n },\n }\n}\n\nexport function calculateClusterIndex<D extends GenericDataRecord> (data: D[], config: LeafletMapConfigInterface<D>, maxClusterZoomLevel = 23): Supercluster<D> {\n const { colorMap, pointShape, pointLatitude, pointLongitude, clusteringDistance } = config\n return new Supercluster<D, Supercluster.AnyProps>({\n radius: clusteringDistance,\n maxZoom: maxClusterZoomLevel,\n map: (d): Supercluster.AnyProps => {\n const shape = getString(d, pointShape)\n\n const clusterPoint = { shape }\n for (const key of Object.keys(colorMap)) {\n clusterPoint[key] = d[key] || 0\n }\n\n return clusterPoint\n },\n reduce: (acc, clusterPoint): void => {\n acc.shape = acc.shape === clusterPoint.shape ? acc.shape : LeafletMapPointShape.Circle\n acc.value = (acc.value ?? 0) + (clusterPoint.value ?? 0)\n\n for (const key of Object.keys(colorMap)) {\n acc[key] += clusterPoint[key]\n }\n },\n }).load(data.map((d, i) => toGeoJSONPoint(d, i, pointLatitude, pointLongitude)))\n}\n\nexport function getNodePathData ({ x, y }: { x: number; y: number }, radius: number, shape: LeafletMapPointShape): string {\n switch (shape) {\n case LeafletMapPointShape.Triangle:\n return polygon(radius * 2, 3)\n case LeafletMapPointShape.Square:\n return polygon(radius * 2, 4)\n case LeafletMapPointShape.Circle:\n case LeafletMapPointShape.Ring:\n default:\n return circlePath(x, y, radius)\n }\n}\n\nexport function getDonutData<D extends GenericDataRecord> (\n d: LeafletMapClusterDatum<D> | LeafletMapPointDatum<D>,\n colorMap: LeafletMapPointStyles<D>\n): LeafletMapPieDatum[] {\n return Object.keys(colorMap).map(key => ({\n name: key,\n value: d[key] as number,\n color: colorMap[key].color,\n className: colorMap[key].className,\n }))\n}\n\nexport function geoJsonPointToScreenPoint<D extends GenericDataRecord> (\n geoPoint: ClusterFeature<LeafletMapClusterDatum<D>> | PointFeature<LeafletMapPointDatum<D>>,\n i: number,\n leafletMap: L.Map,\n config: LeafletMapConfigInterface<D>\n): LeafletMapPoint<D> {\n const zoomLevel = leafletMap.getZoom()\n const isCluster = (geoPoint.properties as LeafletMapClusterDatum<D>).cluster\n const clusterIndex = (geoPoint.properties as LeafletMapClusterDatum<D>).clusterIndex\n const clusterPoints = isCluster ? clusterIndex.getLeaves((geoPoint.properties as LeafletMapClusterDatum<D>).cluster_id as number, Infinity).map(d => d.properties) : undefined\n const { x, y } = getPointPos(geoPoint, leafletMap)\n\n const id = isCluster ? `cluster-${geoPoint.id}` : (getString(geoPoint.properties as LeafletMapPointDatum<D>, config.pointId) ?? geoPoint.geometry.coordinates.join(''))\n // Todo: Needs a better typings handling\n const pointColor = getColor(geoPoint.properties as LeafletMapPointDatum<D>, (isCluster ? config.clusterColor : config.pointColor) as ColorAccessor<LeafletMapPointDatum<D>>)\n const radius = getPointRadius(geoPoint, isCluster ? config.clusterRadius : config.pointRadius, zoomLevel)\n const shape = isCluster ? LeafletMapPointShape.Circle : getString(geoPoint.properties as LeafletMapPointDatum<D>, config.pointShape) as LeafletMapPointShape\n const isRing = shape === LeafletMapPointShape.Ring\n\n const donutData = getDonutData(geoPoint.properties, config.colorMap)\n const maxValue = max(donutData, d => d.value)\n const maxValueIndex = donutData.map(d => d.value).indexOf(maxValue)\n const biggestDatum = donutData[maxValueIndex ?? 0]\n\n const color = isCluster ? pointColor\n : (isRing ? null : (pointColor ?? biggestDatum?.color))\n const bbox = { x1: x - radius, y1: y - radius, x2: x + radius, y2: y + radius }\n const path = getNodePathData({ x: 0, y: 0 }, radius, shape)\n const _zIndex = 0\n\n const screenPoint: LeafletMapPoint<D> = {\n ...geoPoint,\n id,\n bbox,\n radius,\n donutData,\n path,\n color,\n isCluster,\n clusterIndex,\n clusterPoints,\n _zIndex,\n }\n\n return screenPoint\n}\n\nexport function shouldClusterExpand<D extends GenericDataRecord> (\n cluster: LeafletMapPoint<D>,\n zoomLevel: number,\n midLevel = 4,\n maxLevel = 8,\n maxClusterZoomLevel = 23\n): boolean {\n if (!cluster) return false\n\n const clusterExpansionZoomLevel = cluster.clusterIndex.getClusterExpansionZoom(cluster.properties.cluster_id as number)\n return zoomLevel >= maxLevel ||\n (zoomLevel >= midLevel && (cluster.properties.point_count < 20 || clusterExpansionZoomLevel >= maxClusterZoomLevel))\n}\n\nexport function findPointAndClusterByPointId<D extends GenericDataRecord> (\n points: LeafletMapPoint<D>[],\n id: string,\n pointId: StringAccessor<D>\n): {\n point: PointFeature<D> | undefined;\n cluster: LeafletMapPoint<D> | undefined;\n } {\n let point\n let cluster\n points.forEach(p => {\n if (p.isCluster) {\n const leaves = p.clusterIndex.getLeaves((p.properties as LeafletMapClusterDatum<D>).cluster_id as number, Infinity) ?? []\n const foundPoint = leaves.find(d => getString(d.properties, pointId) === id)\n if (foundPoint) {\n point = foundPoint\n cluster = p\n }\n }\n })\n return { point, cluster }\n}\n\nexport function getNodeRelativePosition<D extends GenericDataRecord> (d: LeafletMapPoint<D>, leafletMap: L.Map): { x: number; y: number } {\n const paneTransform = getHTMLTransform(leafletMap.getPane('mapPane'))\n const { x, y } = getPointPos(d, leafletMap)\n return { x: x + paneTransform[0], y: y + paneTransform[1] }\n}\n\nexport function getClusterRadius<D extends GenericDataRecord> (cluster: { points: PointFeature<PointExpandedClusterProperties<D>>[]; cluster: LeafletMapPoint<D> }): number {\n const { points } = cluster\n const minX = min<number>(points.map(d => d.properties.dx - d.properties.r))\n const maxX = max<number>(points.map(d => d.properties.dx + d.properties.r))\n const minY = min<number>(points.map(d => d.properties.dy - d.properties.r))\n const maxY = max<number>(points.map(d => d.properties.dy + d.properties.r))\n return Math.sqrt((maxX - minX) ** 2 + (maxY - minY) ** 2) * 0.5\n}\n\nexport function getClustersAndPoints<D extends GenericDataRecord> (\n clusterIndex: Supercluster<D>,\n leafletMap: L.Map,\n customBounds?: [number, number, number, number]\n): (ClusterFeature<LeafletMapClusterDatum<D>> | PointFeature<D>)[] {\n const leafletBounds = leafletMap.getBounds()\n const southWest = leafletBounds.getSouthWest()\n const northEast = leafletBounds.getNorthEast()\n const bounds = customBounds || [southWest.lng, southWest.lat, northEast.lng, northEast.lat]\n const zoom = Math.round(leafletMap.getZoom())\n const points = clusterIndex.getClusters(bounds, zoom) // as ClusterFeature<LeafletMapPointDatum<D>>[]\n\n for (const p of points) {\n const point = p as ClusterFeature<LeafletMapClusterDatum<D>>\n const isCluster = point.properties.cluster\n if (isCluster) {\n point.properties.clusterIndex = clusterIndex\n point.properties.clusterPoints = clusterIndex.getLeaves(point.properties.cluster_id, Infinity).map(d => d.properties)\n }\n }\n\n return points as (ClusterFeature<LeafletMapClusterDatum<D>> | PointFeature<D>)[]\n}\n"],"names":[],"mappings":";;;;;;;;AA4BM,SAAU,SAAS,CACvB,SAA+D,EAAA;AAE/D,IAAA,IAAI,GAAG,GAAG,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAA;AACxC,IAAA,SAAS,CAAC,OAAO,CAAC,MAAM,IAAG;QACzB,IAAI,CAAC,GAAG,EAAE;YACR,GAAG,GAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EAAQ,MAAM,CAAE,CAAA;AACpB,SAAA;AAAM,aAAA;AACL,YAAA,IAAI,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC,EAAE;AAAE,gBAAA,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC,EAAE,CAAA;AAC1C,YAAA,IAAI,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC,EAAE;AAAE,gBAAA,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC,EAAE,CAAA;AAC1C,YAAA,IAAI,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC,EAAE;AAAE,gBAAA,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC,EAAE,C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AC,KAAK,CAAC,UAAU,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,CAAA;AACtH,SAAA;AACF,KAAA;AAED,IAAA,OAAO,MAAyE,CAAA;AAClF;;;;"}
|
|
@@ -2,7 +2,7 @@ import type L from 'leaflet';
|
|
|
2
2
|
import type Maplibre from 'maplibre-gl';
|
|
3
3
|
import type { Map } from 'maplibre-gl';
|
|
4
4
|
import { GenericDataRecord } from "../../../types/data";
|
|
5
|
-
import {
|
|
6
|
-
export declare function getMaplibreGLLayer<Datum extends GenericDataRecord>(config:
|
|
5
|
+
import { LeafletMapConfigInterface } from '../config';
|
|
6
|
+
export declare function getMaplibreGLLayer<Datum extends GenericDataRecord>(config: LeafletMapConfigInterface<Datum>, leaflet: typeof L, maplibre: typeof Maplibre): L.Layer & {
|
|
7
7
|
getMaplibreMap(): Map;
|
|
8
8
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mapboxgl-layer.js","sources":["../../../../src/components/leaflet-map/renderer/mapboxgl-layer.ts"],"sourcesContent":["import type L from 'leaflet'\nimport type Maplibre from 'maplibre-gl'\nimport type { Map } from 'maplibre-gl'\n\nimport { injectGlobal } from '@emotion/css'\n\n// Utils\nimport { isObject } from 'utils/data'\n\n// Types\nimport { GenericDataRecord } from 'types/data'\n\n// Config\nimport {
|
|
1
|
+
{"version":3,"file":"mapboxgl-layer.js","sources":["../../../../src/components/leaflet-map/renderer/mapboxgl-layer.ts"],"sourcesContent":["import type L from 'leaflet'\nimport type Maplibre from 'maplibre-gl'\nimport type { Map } from 'maplibre-gl'\n\nimport { injectGlobal } from '@emotion/css'\n\n// Utils\nimport { isObject } from 'utils/data'\n\n// Types\nimport { GenericDataRecord } from 'types/data'\n\n// Config\nimport { LeafletMapConfigInterface } from '../config'\nimport { MapLibreStyleSpecs } from './map-style'\nimport { MaplibreGLLayer } from './leaflet-maplibre-gl'\n\n// Inject MapLibreGL global style\nimport mapLibreStyles from './maplibre-gl.css.js'\ninjectGlobal(mapLibreStyles)\n\nexport function getMaplibreGLLayer<Datum extends GenericDataRecord> (config: LeafletMapConfigInterface<Datum>, leaflet: typeof L, maplibre: typeof Maplibre): L.Layer & { getMaplibreMap(): Map } {\n const { accessToken, style } = config\n\n if (isObject(style) && !(style as MapLibreStyleSpecs).glyphs) {\n console.warn('Unovis | Leaflet Map: Glyphs URL is required in order to show the map. Set `mapboxglGlyphs` URL in the style settings')\n return\n }\n\n if (isObject(style) && !(style as MapLibreStyleSpecs).sources) {\n console.warn('Unovis | Leaflet Map: Sources settings are required in order to show map. Set the `sources` property in the style settings')\n return\n }\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const layer = MaplibreGLLayer(leaflet, maplibre, {\n style: style,\n accessToken: accessToken || 'not-needed',\n })\n\n return layer\n}\n"],"names":[],"mappings":";;;;;AAmBA,YAAY,CAAC,cAAc,CAAC,CAAA;SAEZ,kBAAkB,CAAmC,MAAwC,EAAE,OAAiB,EAAE,QAAyB,EAAA;AACzJ,IAAA,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,MAAM,CAAA;IAErC,IAAI,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAE,KAA4B,CAAC,MAAM,EAAE;AAC5D,QAAA,OAAO,CAAC,IAAI,CAAC,uHAAuH,CAAC,CAAA;QACrI,OAAM;AACP,KAAA;IAED,IAAI,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAE,KAA4B,CAAC,OAAO,EAAE;AAC7D,QAAA,OAAO,CAAC,IAAI,CAAC,4HAA4H,CAAC,CAAA;QAC1I,OAAM;AACP,KAAA;;;AAID,IAAA,MAAM,KAAK,GAAG,eAAe,CAAC,OAAO,EAAE,QAAQ,EAAE;AAC/C,QAAA,KAAK,EAAE,KAAK;QACZ,WAAW,EAAE,WAAW,IAAI,YAAY;AACzC,KAAA,CAAC,CAAA;AAEF,IAAA,OAAO,KAAK,CAAA;AACd;;;;"}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import { XYComponentConfigInterface
|
|
1
|
+
import { XYComponentConfigInterface } from "../../core/xy-component/config";
|
|
2
2
|
import { CurveType } from "../../types/curve";
|
|
3
|
-
import { GenericAccessor, StringAccessor } from "../../types/accessor";
|
|
3
|
+
import { ColorAccessor, GenericAccessor, StringAccessor } from "../../types/accessor";
|
|
4
4
|
export interface LineConfigInterface<Datum> extends XYComponentConfigInterface<Datum> {
|
|
5
|
+
/** Line color accessor function. The whole data array will be passed as the first argument. Default: `undefined` */
|
|
6
|
+
color?: ColorAccessor<Datum[]>;
|
|
5
7
|
/** Curve type from the CurveType enum. Default: `CurveType.MonotoneX` */
|
|
6
8
|
curveType?: CurveType;
|
|
7
9
|
/** Line width in pixels. Default: `2` */
|
|
8
10
|
lineWidth?: number;
|
|
9
11
|
/** Line dash array, see SVG's stroke-dasharray. Default: `undefined` */
|
|
10
|
-
lineDashArray?: GenericAccessor<number[], Datum>;
|
|
12
|
+
lineDashArray?: GenericAccessor<number[], Datum[]>;
|
|
11
13
|
/** When a data point has an `undefined`, `NaN`, or other no-data value, they'll be replaced with a value specified here.
|
|
12
14
|
* Setting this property to `undefined` will lead to having the line break when there's no data, and continue when
|
|
13
15
|
* the data appears again. If you set it to `null`, the values will be treated as numerical `0` values and the line
|
|
@@ -20,11 +22,4 @@ export interface LineConfigInterface<Datum> extends XYComponentConfigInterface<D
|
|
|
20
22
|
/** Optional link cursor. Default: `null` */
|
|
21
23
|
cursor?: StringAccessor<Datum[]>;
|
|
22
24
|
}
|
|
23
|
-
export declare
|
|
24
|
-
curveType: CurveType;
|
|
25
|
-
lineWidth: number;
|
|
26
|
-
lineDashArray: any;
|
|
27
|
-
fallbackValue: any;
|
|
28
|
-
highlightOnHover: boolean;
|
|
29
|
-
cursor: any;
|
|
30
|
-
}
|
|
25
|
+
export declare const LineDefaultConfig: LineConfigInterface<unknown>;
|
|
@@ -1,17 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { XYComponentDefaultConfig } from '../../core/xy-component/config.js';
|
|
2
2
|
import { CurveType } from '../../types/curve.js';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
constructor() {
|
|
6
|
-
super(...arguments);
|
|
7
|
-
this.curveType = CurveType.MonotoneX;
|
|
8
|
-
this.lineWidth = 2;
|
|
9
|
-
this.lineDashArray = undefined;
|
|
10
|
-
this.fallbackValue = undefined;
|
|
11
|
-
this.highlightOnHover = false;
|
|
12
|
-
this.cursor = null;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
4
|
+
const LineDefaultConfig = Object.assign(Object.assign({}, XYComponentDefaultConfig), { curveType: CurveType.MonotoneX, lineWidth: 2, lineDashArray: undefined, fallbackValue: undefined, highlightOnHover: false, cursor: null });
|
|
15
5
|
|
|
16
|
-
export {
|
|
6
|
+
export { LineDefaultConfig };
|
|
17
7
|
//# sourceMappingURL=config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sources":["../../../src/components/line/config.ts"],"sourcesContent":["import { XYComponentConfigInterface,
|
|
1
|
+
{"version":3,"file":"config.js","sources":["../../../src/components/line/config.ts"],"sourcesContent":["import { XYComponentConfigInterface, XYComponentDefaultConfig } from 'core/xy-component/config'\n\n// Types\nimport { CurveType } from 'types/curve'\nimport { ColorAccessor, GenericAccessor, StringAccessor } from 'types/accessor'\n\nexport interface LineConfigInterface<Datum> extends XYComponentConfigInterface<Datum> {\n /** Line color accessor function. The whole data array will be passed as the first argument. Default: `undefined` */\n color?: ColorAccessor<Datum[]>;\n /** Curve type from the CurveType enum. Default: `CurveType.MonotoneX` */\n curveType?: CurveType;\n /** Line width in pixels. Default: `2` */\n lineWidth?: number;\n /** Line dash array, see SVG's stroke-dasharray. Default: `undefined` */\n lineDashArray?: GenericAccessor<number[], Datum[]>;\n /** When a data point has an `undefined`, `NaN`, or other no-data value, they'll be replaced with a value specified here.\n * Setting this property to `undefined` will lead to having the line break when there's no data, and continue when\n * the data appears again. If you set it to `null`, the values will be treated as numerical `0` values and the line\n * won't break; however if the whole dataset consists of only `null`s, the line won't be displayed.\n * Default: `undefined`\n */\n fallbackValue?: number | undefined | null;\n /** Highlight line on hover. Default: `false` */\n highlightOnHover?: boolean;\n /** Optional link cursor. Default: `null` */\n cursor?: StringAccessor<Datum[]>;\n}\n\nexport const LineDefaultConfig: LineConfigInterface<unknown> = {\n ...XYComponentDefaultConfig,\n curveType: CurveType.MonotoneX,\n lineWidth: 2,\n lineDashArray: undefined,\n fallbackValue: undefined,\n highlightOnHover: false,\n cursor: null,\n}\n"],"names":[],"mappings":";;;AA4BO,MAAM,iBAAiB,GAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EACzB,wBAAwB,CAC3B,EAAA,EAAA,SAAS,EAAE,SAAS,CAAC,SAAS,EAC9B,SAAS,EAAE,CAAC,EACZ,aAAa,EAAE,SAAS,EACxB,aAAa,EAAE,SAAS,EACxB,gBAAgB,EAAE,KAAK,EACvB,MAAM,EAAE,IAAI;;;;"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { CurveFactoryLineOnly, Line as LineGenInterface } from 'd3-shape';
|
|
2
2
|
import { XYComponentCore } from "../../core/xy-component";
|
|
3
3
|
import { Spacing } from "../../types/spacing";
|
|
4
|
-
import {
|
|
4
|
+
import { LineConfigInterface } from './config';
|
|
5
5
|
import * as s from './style';
|
|
6
|
-
export declare class Line<Datum> extends XYComponentCore<Datum,
|
|
6
|
+
export declare class Line<Datum> extends XYComponentCore<Datum, LineConfigInterface<Datum>> {
|
|
7
7
|
static selectors: typeof s;
|
|
8
|
-
|
|
8
|
+
protected _defaultConfig: LineConfigInterface<Datum>;
|
|
9
|
+
config: LineConfigInterface<Datum>;
|
|
9
10
|
lineGen: LineGenInterface<{
|
|
10
11
|
x: number;
|
|
11
12
|
y: number;
|
package/components/line/index.js
CHANGED
|
@@ -7,14 +7,15 @@ import { smartTransition } from '../../utils/d3.js';
|
|
|
7
7
|
import { getColor } from '../../utils/color.js';
|
|
8
8
|
import { Curve, CurveType } from '../../types/curve.js';
|
|
9
9
|
import { Direction } from '../../types/direction.js';
|
|
10
|
-
import {
|
|
10
|
+
import { LineDefaultConfig } from './config.js';
|
|
11
11
|
import * as style from './style.js';
|
|
12
12
|
import { line as line$1, linePath, lineSelectionHelper, dim } from './style.js';
|
|
13
13
|
|
|
14
14
|
class Line extends XYComponentCore {
|
|
15
15
|
constructor(config) {
|
|
16
16
|
super();
|
|
17
|
-
this.
|
|
17
|
+
this._defaultConfig = LineDefaultConfig;
|
|
18
|
+
this.config = this._defaultConfig;
|
|
18
19
|
this.curve = Curve[CurveType.MonotoneX];
|
|
19
20
|
this.events = {
|
|
20
21
|
[Line.selectors.line]: {
|
|
@@ -23,7 +24,7 @@ class Line extends XYComponentCore {
|
|
|
23
24
|
},
|
|
24
25
|
};
|
|
25
26
|
if (config)
|
|
26
|
-
this.
|
|
27
|
+
this.setConfig(config);
|
|
27
28
|
}
|
|
28
29
|
get bleed() {
|
|
29
30
|
const { config: { lineWidth } } = this;
|
|
@@ -98,7 +99,7 @@ class Line extends XYComponentCore {
|
|
|
98
99
|
const linePath$1 = group.select(`.${linePath}`);
|
|
99
100
|
const lineSelectionHelper$1 = group.select(`.${lineSelectionHelper}`);
|
|
100
101
|
const isLineVisible = d.visible;
|
|
101
|
-
const dashArray = getValue(
|
|
102
|
+
const dashArray = getValue(data, config.lineDashArray, i);
|
|
102
103
|
const transition = smartTransition(linePath$1, duration)
|
|
103
104
|
.attr('stroke', getColor(data, config.color, i))
|
|
104
105
|
.attr('stroke-width', config.lineWidth)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/components/line/index.ts"],"sourcesContent":["import { select } from 'd3-selection'\nimport { Transition } from 'd3-transition'\nimport { CurveFactoryLineOnly, Line as LineGenInterface, line } from 'd3-shape'\nimport { interpolatePath } from 'd3-interpolate-path'\n\n// Core\nimport { XYComponentCore } from 'core/xy-component'\n\n// Utils\nimport { getNumber, getString, getValue, isArray, isNumber } from 'utils/data'\nimport { smartTransition } from 'utils/d3'\nimport { getColor } from 'utils/color'\n\n// Types\nimport { NumericAccessor } from 'types/accessor'\nimport { Spacing } from 'types/spacing'\nimport { Curve, CurveType } from 'types/curve'\nimport { Direction } from 'types/direction'\n\n// Local Types\nimport { LineData, LineDatum } from './types'\n\n// Config\nimport { LineConfig, LineConfigInterface } from './config'\n\n// Styles\nimport * as s from './style'\n\nexport class Line<Datum> extends XYComponentCore<Datum, LineConfig<Datum>, LineConfigInterface<Datum>> {\n static selectors = s\n config: LineConfig<Datum> = new LineConfig()\n lineGen: LineGenInterface<{ x: number; y: number; defined: boolean }>\n curve: CurveFactoryLineOnly = Curve[CurveType.MonotoneX]\n events = {\n [Line.selectors.line]: {\n mouseover: this._highlight.bind(this),\n mouseleave: this._resetHighlight.bind(this),\n },\n }\n\n constructor (config?: LineConfigInterface<Datum>) {\n super()\n if (config) this.config.init(config)\n }\n\n get bleed (): Spacing {\n const { config: { lineWidth } } = this\n const yDomain = this.yScale.domain() as [number, number]\n const yDirection = this.yScale.range()[0] > this.yScale.range()[1]\n ? Direction.North\n : Direction.South\n const isYDirectionSouth = yDirection === Direction.South\n\n const isLineThick = lineWidth > 3\n const isLineVeryThick = lineWidth >= 10\n return {\n top: !isLineVeryThick && (\n (!isYDirectionSouth && (yDomain[1] === 0)) || (isYDirectionSouth && (yDomain[0] === 0))\n ) ? 0 : lineWidth / 2,\n bottom: !isLineVeryThick && (\n (!isYDirectionSouth && (yDomain[0] === 0)) || (isYDirectionSouth && (yDomain[1] === 0))\n ) ? 0 : lineWidth / 2,\n left: isLineThick ? lineWidth / 2 : 0,\n right: isLineThick ? lineWidth / 2 : 0,\n }\n }\n\n _render (customDuration?: number): void {\n super._render(customDuration)\n const { config, datamodel: { data } } = this\n const duration = isNumber(customDuration) ? customDuration : config.duration\n\n this.curve = Curve[config.curveType]\n this.lineGen = line<{ x: number; y: number; defined: boolean }>()\n .x(d => d.x)\n .y(d => d.y)\n .defined(d => d.defined)\n .curve(this.curve)\n\n const yAccessors = (isArray(config.y) ? config.y : [config.y]) as NumericAccessor<Datum>[]\n const lineDataX = data.map((d, i) => this.xScale(getNumber(d, config.x, i)))\n const lineData: LineData[] = yAccessors.map(a => {\n const ld: LineDatum[] = data.map((d, i) => {\n const rawValue = getNumber(d, a, i)\n // If `rawValue` is not numerical or if it's not finite (`NaN`, `undefined`, ...), we replace it with `config.fallbackValue`\n const value = (isNumber(rawValue) || (rawValue === null)) && isFinite(rawValue) ? rawValue : config.fallbackValue\n return {\n x: lineDataX[i],\n y: this.yScale(value ?? 0),\n defined: isFinite(value),\n value,\n }\n })\n\n const defined = ld.reduce((def, d) => (d.defined || def), false)\n // If the line consists only of `null` values, we'll still render it but it'll be invisible.\n // Such trick allows us to have better animated transitions.\n const visible = defined && ld.some(d => d.value !== null)\n return {\n values: ld,\n defined,\n visible,\n }\n })\n\n const lines = this.g\n .selectAll<SVGGElement, LineData>(`.${s.line}`)\n .data(lineData)\n\n const linesEnter = lines.enter().append('g')\n .attr('class', s.line)\n\n linesEnter\n .append('path')\n .attr('class', s.linePath)\n .attr('stroke', (d, i) => getColor(data, config.color, i))\n .attr('stroke-opacity', 0)\n .attr('stroke-width', config.lineWidth)\n\n linesEnter\n .append('path')\n .attr('class', s.lineSelectionHelper)\n .attr('d', this._emptyPath())\n\n const linesMerged = linesEnter.merge(lines)\n linesMerged.style('cursor', (d, i) => getString(data, config.cursor, i))\n linesMerged.each((d, i, elements) => {\n const group = select(elements[i])\n const linePath = group.select<SVGPathElement>(`.${s.linePath}`)\n const lineSelectionHelper = group.select(`.${s.lineSelectionHelper}`)\n\n const isLineVisible = d.visible\n const dashArray = getValue<LineData, number[]>(d, config.lineDashArray, i)\n const transition = smartTransition(linePath, duration)\n .attr('stroke', getColor(data, config.color, i))\n .attr('stroke-width', config.lineWidth)\n .attr('stroke-opacity', isLineVisible ? 1 : 0)\n .style('stroke-dasharray', dashArray?.join(' ') ?? null) // We use `.style` because there's also a default CSS-variable for stroke-dasharray\n\n const hasUndefinedSegments = d.values.some(d => !d.defined)\n const svgPathD = this.lineGen(d.values)\n\n if (duration && !hasUndefinedSegments) {\n const previous = linePath.attr('d') || this._emptyPath()\n const next = svgPathD || this._emptyPath()\n const t = transition as Transition<SVGPathElement, LineData, SVGGElement, LineData>\n t.attrTween('d', () => interpolatePath(previous, next))\n } else if (d.visible) {\n transition.attr('d', svgPathD)\n }\n\n lineSelectionHelper\n .attr('d', svgPathD)\n .attr('visibility', isLineVisible ? null : 'hidden')\n })\n\n smartTransition(lines.exit(), duration)\n .style('opacity', 0)\n .remove()\n }\n\n private _emptyPath (): string {\n const xRange = this.xScale.range()\n const yRange = this.yScale.range()\n return `M${xRange[0]},${yRange[0]} L${xRange[1]},${yRange[0]}`\n }\n\n private _highlight (datum, i, els): void {\n const { config } = this\n\n if (config.highlightOnHover) {\n this.g\n .selectAll(`.${s.line}`)\n .classed(s.dim, d => d !== datum)\n }\n }\n\n private _resetHighlight (d, i, els): void {\n const { config } = this\n\n if (config.highlightOnHover) {\n this.g\n .selectAll(`.${s.line}`)\n .classed(s.dim, false)\n }\n }\n}\n"],"names":["s.line","s.linePath","s.lineSelectionHelper","linePath","lineSelectionHelper","s.dim","s"],"mappings":";;;;;;;;;;;;;AA4BM,MAAO,IAAY,SAAQ,eAAqE,CAAA;AAYpG,IAAA,WAAA,CAAa,MAAmC,EAAA;AAC9C,QAAA,KAAK,EAAE,CAAA;AAXT,QAAA,IAAA,CAAA,MAAM,GAAsB,IAAI,UAAU,EAAE,CAAA;AAE5C,QAAA,IAAA,CAAA,KAAK,GAAyB,KAAK,CAAC,SAAS,CAAC,SAAS,CAAC,CAAA;AACxD,QAAA,IAAA,CAAA,MAAM,GAAG;AACP,YAAA,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,GAAG;gBACrB,SAAS,EAAE,IAAI,CA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GAAK,EAAE,KAAK,CAAC,CAAA;AACzB,SAAA;KACF;;AA5JM,IAAS,CAAA,SAAA,GAAGC,KAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/components/line/index.ts"],"sourcesContent":["import { select } from 'd3-selection'\nimport { Transition } from 'd3-transition'\nimport { CurveFactoryLineOnly, Line as LineGenInterface, line } from 'd3-shape'\nimport { interpolatePath } from 'd3-interpolate-path'\n\n// Core\nimport { XYComponentCore } from 'core/xy-component'\n\n// Utils\nimport { getNumber, getString, getValue, isArray, isNumber } from 'utils/data'\nimport { smartTransition } from 'utils/d3'\nimport { getColor } from 'utils/color'\n\n// Types\nimport { NumericAccessor } from 'types/accessor'\nimport { Spacing } from 'types/spacing'\nimport { Curve, CurveType } from 'types/curve'\nimport { Direction } from 'types/direction'\n\n// Local Types\nimport { LineData, LineDatum } from './types'\n\n// Config\nimport { LineDefaultConfig, LineConfigInterface } from './config'\n\n// Styles\nimport * as s from './style'\n\nexport class Line<Datum> extends XYComponentCore<Datum, LineConfigInterface<Datum>> {\n static selectors = s\n protected _defaultConfig = LineDefaultConfig as LineConfigInterface<Datum>\n public config: LineConfigInterface<Datum> = this._defaultConfig\n lineGen: LineGenInterface<{ x: number; y: number; defined: boolean }>\n curve: CurveFactoryLineOnly = Curve[CurveType.MonotoneX]\n events = {\n [Line.selectors.line]: {\n mouseover: this._highlight.bind(this),\n mouseleave: this._resetHighlight.bind(this),\n },\n }\n\n constructor (config?: LineConfigInterface<Datum>) {\n super()\n if (config) this.setConfig(config)\n }\n\n get bleed (): Spacing {\n const { config: { lineWidth } } = this\n const yDomain = this.yScale.domain() as [number, number]\n const yDirection = this.yScale.range()[0] > this.yScale.range()[1]\n ? Direction.North\n : Direction.South\n const isYDirectionSouth = yDirection === Direction.South\n\n const isLineThick = lineWidth > 3\n const isLineVeryThick = lineWidth >= 10\n return {\n top: !isLineVeryThick && (\n (!isYDirectionSouth && (yDomain[1] === 0)) || (isYDirectionSouth && (yDomain[0] === 0))\n ) ? 0 : lineWidth / 2,\n bottom: !isLineVeryThick && (\n (!isYDirectionSouth && (yDomain[0] === 0)) || (isYDirectionSouth && (yDomain[1] === 0))\n ) ? 0 : lineWidth / 2,\n left: isLineThick ? lineWidth / 2 : 0,\n right: isLineThick ? lineWidth / 2 : 0,\n }\n }\n\n _render (customDuration?: number): void {\n super._render(customDuration)\n const { config, datamodel: { data } } = this\n const duration = isNumber(customDuration) ? customDuration : config.duration\n\n this.curve = Curve[config.curveType]\n this.lineGen = line<{ x: number; y: number; defined: boolean }>()\n .x(d => d.x)\n .y(d => d.y)\n .defined(d => d.defined)\n .curve(this.curve)\n\n const yAccessors = (isArray(config.y) ? config.y : [config.y]) as NumericAccessor<Datum>[]\n const lineDataX = data.map((d, i) => this.xScale(getNumber(d, config.x, i)))\n const lineData: LineData[] = yAccessors.map(a => {\n const ld: LineDatum[] = data.map((d, i) => {\n const rawValue = getNumber(d, a, i)\n // If `rawValue` is not numerical or if it's not finite (`NaN`, `undefined`, ...), we replace it with `config.fallbackValue`\n const value = (isNumber(rawValue) || (rawValue === null)) && isFinite(rawValue) ? rawValue : config.fallbackValue\n return {\n x: lineDataX[i],\n y: this.yScale(value ?? 0),\n defined: isFinite(value),\n value,\n }\n })\n\n const defined = ld.reduce((def, d) => (d.defined || def), false)\n // If the line consists only of `null` values, we'll still render it but it'll be invisible.\n // Such trick allows us to have better animated transitions.\n const visible = defined && ld.some(d => d.value !== null)\n return {\n values: ld,\n defined,\n visible,\n }\n })\n\n const lines = this.g\n .selectAll<SVGGElement, LineData>(`.${s.line}`)\n .data(lineData)\n\n const linesEnter = lines.enter().append('g')\n .attr('class', s.line)\n\n linesEnter\n .append('path')\n .attr('class', s.linePath)\n .attr('stroke', (d, i) => getColor(data, config.color, i))\n .attr('stroke-opacity', 0)\n .attr('stroke-width', config.lineWidth)\n\n linesEnter\n .append('path')\n .attr('class', s.lineSelectionHelper)\n .attr('d', this._emptyPath())\n\n const linesMerged = linesEnter.merge(lines)\n linesMerged.style('cursor', (d, i) => getString(data, config.cursor, i))\n linesMerged.each((d, i, elements) => {\n const group = select(elements[i])\n const linePath = group.select<SVGPathElement>(`.${s.linePath}`)\n const lineSelectionHelper = group.select(`.${s.lineSelectionHelper}`)\n\n const isLineVisible = d.visible\n const dashArray = getValue<Datum[], number[]>(data, config.lineDashArray, i)\n const transition = smartTransition(linePath, duration)\n .attr('stroke', getColor(data, config.color, i))\n .attr('stroke-width', config.lineWidth)\n .attr('stroke-opacity', isLineVisible ? 1 : 0)\n .style('stroke-dasharray', dashArray?.join(' ') ?? null) // We use `.style` because there's also a default CSS-variable for stroke-dasharray\n\n const hasUndefinedSegments = d.values.some(d => !d.defined)\n const svgPathD = this.lineGen(d.values)\n\n if (duration && !hasUndefinedSegments) {\n const previous = linePath.attr('d') || this._emptyPath()\n const next = svgPathD || this._emptyPath()\n const t = transition as Transition<SVGPathElement, LineData, SVGGElement, LineData>\n t.attrTween('d', () => interpolatePath(previous, next))\n } else if (d.visible) {\n transition.attr('d', svgPathD)\n }\n\n lineSelectionHelper\n .attr('d', svgPathD)\n .attr('visibility', isLineVisible ? null : 'hidden')\n })\n\n smartTransition(lines.exit(), duration)\n .style('opacity', 0)\n .remove()\n }\n\n private _emptyPath (): string {\n const xRange = this.xScale.range()\n const yRange = this.yScale.range()\n return `M${xRange[0]},${yRange[0]} L${xRange[1]},${yRange[0]}`\n }\n\n private _highlight (datum, i, els): void {\n const { config } = this\n\n if (config.highlightOnHover) {\n this.g\n .selectAll(`.${s.line}`)\n .classed(s.dim, d => d !== datum)\n }\n }\n\n private _resetHighlight (d, i, els): void {\n const { config } = this\n\n if (config.highlightOnHover) {\n this.g\n .selectAll(`.${s.line}`)\n .classed(s.dim, false)\n }\n }\n}\n"],"names":["s.line","s.linePath","s.lineSelectionHelper","linePath","lineSelectionHelper","s.dim","s"],"mappings":";;;;;;;;;;;;;AA4BM,MAAO,IAAY,SAAQ,eAAkD,CAAA;AAajF,IAAA,WAAA,CAA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,EAAE,CAAC,IAAI,CAAC,KAAK,KAAK,CAAC,CAAA;AACpC,SAAA;KACF;AAEO,IAAA,eAAe,CAAE,CAAC,EAAE,CAAC,EAAE,GAAG,EAAA;AAChC,QAAA,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAA;QAEvB,IAAI,MAAM,CAAC,gBAAgB,EAAE;AAC3B,YAAA,IAAI,CAAC,CAAC;AACH,iBAAA,SAAS,CAAC,CAAI,CAAA,EAAAL,MAAM,EAAE,CAAC;AACvB,iBAAA,OAAO,CAACK,GAAK,EAAE,KAAK,CAAC,CAAA;AACzB,SAAA;KACF;;AA7JM,IAAS,CAAA,SAAA,GAAGC,KAAC;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ComponentConfigInterface
|
|
1
|
+
import { ComponentConfigInterface } from "../../core/component/config";
|
|
2
2
|
import { ColorAccessor, GenericAccessor, NumericAccessor, StringAccessor } from "../../types/accessor";
|
|
3
3
|
import { NestedDonutDirection, NestedDonutLayerSettings, NestedDonutSegment } from './types';
|
|
4
4
|
export interface NestedDonutConfigInterface<Datum> extends ComponentConfigInterface {
|
|
@@ -46,23 +46,4 @@ export interface NestedDonutConfigInterface<Datum> extends ComponentConfigInterf
|
|
|
46
46
|
*/
|
|
47
47
|
showEmptySegments?: boolean;
|
|
48
48
|
}
|
|
49
|
-
export declare
|
|
50
|
-
angleRange: [number, number];
|
|
51
|
-
centralLabel: any;
|
|
52
|
-
centralSubLabel: any;
|
|
53
|
-
centralSubLabelWrap: boolean;
|
|
54
|
-
cornerRadius: number;
|
|
55
|
-
direction: NestedDonutDirection;
|
|
56
|
-
emptySegmentAngle: number;
|
|
57
|
-
hideOverflowingSegmentLabels: boolean;
|
|
58
|
-
layers: StringAccessor<Datum>[];
|
|
59
|
-
layerPadding: number;
|
|
60
|
-
layerSettings: any;
|
|
61
|
-
segmentColor: any;
|
|
62
|
-
segmentLabel: any;
|
|
63
|
-
segmentLabelColor: any;
|
|
64
|
-
showBackground: boolean;
|
|
65
|
-
showEmptySegments: boolean;
|
|
66
|
-
sort: any;
|
|
67
|
-
value: any;
|
|
68
|
-
}
|
|
49
|
+
export declare const NestedDonutDefaultConfig: NestedDonutConfigInterface<unknown>;
|
|
@@ -1,29 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ComponentDefaultConfig } from '../../core/component/config.js';
|
|
2
2
|
import { NestedDonutDirection } from './types.js';
|
|
3
3
|
|
|
4
4
|
// Core
|
|
5
|
-
|
|
6
|
-
constructor() {
|
|
7
|
-
super(...arguments);
|
|
8
|
-
this.angleRange = [0, 2 * Math.PI];
|
|
9
|
-
this.centralLabel = undefined;
|
|
10
|
-
this.centralSubLabel = undefined;
|
|
11
|
-
this.centralSubLabelWrap = true;
|
|
12
|
-
this.cornerRadius = 0;
|
|
13
|
-
this.direction = NestedDonutDirection.Inwards;
|
|
14
|
-
this.emptySegmentAngle = Math.PI / 180;
|
|
15
|
-
this.hideOverflowingSegmentLabels = true;
|
|
16
|
-
this.layerPadding = 0;
|
|
17
|
-
this.layerSettings = undefined;
|
|
18
|
-
this.segmentColor = undefined;
|
|
19
|
-
this.segmentLabel = undefined;
|
|
20
|
-
this.segmentLabelColor = undefined;
|
|
21
|
-
this.showBackground = false;
|
|
22
|
-
this.showEmptySegments = false;
|
|
23
|
-
this.sort = undefined;
|
|
24
|
-
this.value = undefined;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
5
|
+
const NestedDonutDefaultConfig = Object.assign(Object.assign({}, ComponentDefaultConfig), { angleRange: [0, 2 * Math.PI], centralLabel: undefined, centralSubLabel: undefined, centralSubLabelWrap: true, cornerRadius: 0, direction: NestedDonutDirection.Inwards, emptySegmentAngle: Math.PI / 180, hideOverflowingSegmentLabels: true, layers: [], layerPadding: 0, layerSettings: undefined, segmentColor: undefined, segmentLabel: undefined, segmentLabelColor: undefined, showBackground: false, showEmptySegments: false, sort: undefined, value: undefined });
|
|
27
6
|
|
|
28
|
-
export {
|
|
7
|
+
export { NestedDonutDefaultConfig };
|
|
29
8
|
//# sourceMappingURL=config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sources":["../../../src/components/nested-donut/config.ts"],"sourcesContent":["// Core\nimport { ComponentConfigInterface,
|
|
1
|
+
{"version":3,"file":"config.js","sources":["../../../src/components/nested-donut/config.ts"],"sourcesContent":["// Core\nimport { ComponentConfigInterface, ComponentDefaultConfig } from 'core/component/config'\n\n// Types\nimport { ColorAccessor, GenericAccessor, NumericAccessor, StringAccessor } from 'types/accessor'\nimport { NestedDonutDirection, NestedDonutLayerSettings, NestedDonutSegment } from './types'\n\nexport interface NestedDonutConfigInterface<Datum> extends ComponentConfigInterface {\n /** Diagram angle range. Default: `[0, 2 * Math.PI]` */\n angleRange?: [number, number];\n /** Direction of hierarchy flow from root to leaf.\n * `NestedDonutDirection.Inwards` starts from the outer most radius and works towards center\n * `NestedDonutDirection.Outwards` starts from the inner most radius the consecutive layers outward.\n * Default: `NestedDonutDirection.Inwards`\n */\n direction?: NestedDonutDirection | string;\n /* Numeric accessor for segment size value. Default: `undefined`. */\n value?: NumericAccessor<Datum>;\n\n /** Central label text. Default: `undefined` */\n centralLabel?: string;\n /** Central sub-label accessor function or text. Default: `undefined` */\n centralSubLabel?: string;\n /** Enables wrapping for the sub-label. Default: `true` */\n centralSubLabelWrap?: boolean;\n /**\n * Show donut background. The color is configurable via\n * the `--vis-nested-donut-background-color` and `--vis-dark-nested-donut-background-color` CSS variables.\n * Default: `false`\n */\n showBackground?: boolean;\n /** Sort function for segments. Default `undefined` */\n sort?: (a: NestedDonutSegment<Datum>, b: NestedDonutSegment<Datum>) => number;\n\n // Layers\n /** Array of accessor functions to defined the nested groups */\n layers: StringAccessor<Datum>[];\n /* Layer settings */\n layerSettings?: GenericAccessor<NestedDonutLayerSettings, number>;\n /* Space between layers */\n layerPadding?: number;\n\n // Segments\n /** Corner Radius. Default: `0` */\n cornerRadius?: number;\n /** Angular size for empty segments in radians. Default: `Math.PI / 180` */\n emptySegmentAngle?: number;\n /** Hide segment labels when they don't fit. Default: `true` */\n hideOverflowingSegmentLabels?: boolean;\n /** Color accessor function for segments. Default: `undefined` */\n segmentColor?: ColorAccessor<NestedDonutSegment<Datum>>;\n /** Segment label accessor function. Default `undefined` */\n segmentLabel?: StringAccessor<NestedDonutSegment<Datum>>;\n /** Color accessor function for segment labels */\n segmentLabelColor?: ColorAccessor<NestedDonutSegment<Datum>>;\n /** When true, the component will display empty segments (the ones that have `0` values) as tiny slices.\n * Default: `false`\n */\n showEmptySegments?: boolean;\n}\n\nexport const NestedDonutDefaultConfig: NestedDonutConfigInterface<unknown> = {\n ...ComponentDefaultConfig,\n angleRange: [0, 2 * Math.PI],\n centralLabel: undefined,\n centralSubLabel: undefined,\n centralSubLabelWrap: true,\n cornerRadius: 0,\n direction: NestedDonutDirection.Inwards,\n emptySegmentAngle: Math.PI / 180,\n hideOverflowingSegmentLabels: true,\n layers: [],\n layerPadding: 0,\n layerSettings: undefined,\n segmentColor: undefined,\n segmentLabel: undefined,\n segmentLabelColor: undefined,\n showBackground: false,\n showEmptySegments: false,\n sort: undefined,\n value: undefined,\n}\n"],"names":[],"mappings":";;;AAAA;MA6Da,wBAAwB,GAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EAChC,sBAAsB,CACzB,EAAA,EAAA,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC,EAC5B,YAAY,EAAE,SAAS,EACvB,eAAe,EAAE,SAAS,EAC1B,mBAAmB,EAAE,IAAI,EACzB,YAAY,EAAE,CAAC,EACf,SAAS,EAAE,oBAAoB,CAAC,OAAO,EACvC,iBAAiB,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,EAChC,4BAA4B,EAAE,IAAI,EAClC,MAAM,EAAE,EAAE,EACV,YAAY,EAAE,CAAC,EACf,aAAa,EAAE,SAAS,EACxB,YAAY,EAAE,SAAS,EACvB,YAAY,EAAE,SAAS,EACvB,iBAAiB,EAAE,SAAS,EAC5B,cAAc,EAAE,KAAK,EACrB,iBAAiB,EAAE,KAAK,EACxB,IAAI,EAAE,SAAS,EACf,KAAK,EAAE,SAAS;;;;"}
|
|
@@ -3,9 +3,9 @@ import { ScaleLinear } from 'd3-scale';
|
|
|
3
3
|
import { ComponentCore } from "../../core/component";
|
|
4
4
|
import { SeriesDataModel } from "../../data-models/series";
|
|
5
5
|
import { NestedDonutSegment } from './types';
|
|
6
|
-
import {
|
|
6
|
+
import { NestedDonutConfigInterface } from './config';
|
|
7
7
|
import * as s from './style';
|
|
8
|
-
export declare class NestedDonut<Datum> extends ComponentCore<Datum[],
|
|
8
|
+
export declare class NestedDonut<Datum> extends ComponentCore<Datum[], NestedDonutConfigInterface<Datum>> {
|
|
9
9
|
static selectors: typeof s;
|
|
10
10
|
static cssVariables: {
|
|
11
11
|
nestedDonutFontFamily: "--vis-nested-donut-font-family";
|
|
@@ -25,7 +25,8 @@ export declare class NestedDonut<Datum> extends ComponentCore<Datum[], NestedDon
|
|
|
25
25
|
darkNestedDonutCentralLabelTextColor: "--vis-dark-nested-donut-central-label-text-color";
|
|
26
26
|
darkNestedDonutCentralSublabelTextColor: "--vis-dark-nested-donut-central-sublabel-text-color";
|
|
27
27
|
};
|
|
28
|
-
|
|
28
|
+
protected _defaultConfig: NestedDonutConfigInterface<Datum>;
|
|
29
|
+
config: NestedDonutConfigInterface<Datum>;
|
|
29
30
|
datamodel: SeriesDataModel<Datum>;
|
|
30
31
|
arcBackground: Selection<SVGGElement, unknown, SVGGElement, unknown>;
|
|
31
32
|
arcGroup: Selection<SVGGElement, unknown, SVGGElement, unknown>;
|
|
@@ -5,14 +5,14 @@ import { group } from 'd3-array';
|
|
|
5
5
|
import { ComponentCore } from '../../core/component/index.js';
|
|
6
6
|
import { SeriesDataModel } from '../../data-models/series.js';
|
|
7
7
|
import { VerticalAlign } from '../../types/text.js';
|
|
8
|
-
import {
|
|
8
|
+
import { getColor } from '../../utils/color.js';
|
|
9
9
|
import { smartTransition } from '../../utils/d3.js';
|
|
10
10
|
import { isNumber, getString, getNumber, isNumberWithinRange, merge, getValue } from '../../utils/data.js';
|
|
11
11
|
import { getPixelValue } from '../../utils/misc.js';
|
|
12
12
|
import { cssvar } from '../../utils/style.js';
|
|
13
13
|
import { wrapSVGText } from '../../utils/text.js';
|
|
14
14
|
import { NestedDonutSegmentLabelAlignment, NestedDonutDirection } from './types.js';
|
|
15
|
-
import {
|
|
15
|
+
import { NestedDonutDefaultConfig } from './config.js';
|
|
16
16
|
import { createArc, updateArc, removeArc } from './modules/arc.js';
|
|
17
17
|
import { createLabel, updateLabel, removeLabel } from './modules/label.js';
|
|
18
18
|
import * as style from './style.js';
|
|
@@ -21,13 +21,14 @@ import { segmentsGroup, centralLabel, centralSubLabel, background, segment, segm
|
|
|
21
21
|
class NestedDonut extends ComponentCore {
|
|
22
22
|
constructor(config) {
|
|
23
23
|
super();
|
|
24
|
-
this.
|
|
24
|
+
this._defaultConfig = NestedDonutDefaultConfig;
|
|
25
|
+
this.config = this._defaultConfig;
|
|
25
26
|
this.datamodel = new SeriesDataModel();
|
|
26
27
|
this.arcGen = arc();
|
|
27
28
|
this.colorScale = scaleLinear();
|
|
28
29
|
this.events = {};
|
|
29
30
|
if (config)
|
|
30
|
-
this.
|
|
31
|
+
this.setConfig(config);
|
|
31
32
|
this.arcBackground = this.g.append('g');
|
|
32
33
|
this.arcGroup = this.g.append('g')
|
|
33
34
|
.attr('class', segmentsGroup);
|
|
@@ -145,26 +146,28 @@ class NestedDonut extends ComponentCore {
|
|
|
145
146
|
})
|
|
146
147
|
.eachAfter(node => { var _a; return (_a = node.children) === null || _a === void 0 ? void 0 : _a.forEach(ch => node.data.values.push(...ch.data.values)); })
|
|
147
148
|
.eachBefore(node => {
|
|
148
|
-
var _a, _b, _c;
|
|
149
|
+
var _a, _b, _c, _d;
|
|
149
150
|
if (!node.children || node.depth === rootNode.height - 1)
|
|
150
151
|
return;
|
|
151
|
-
const colors = this.colorScale
|
|
152
|
-
.domain([-1, node.children.length])
|
|
153
|
-
.range([getHexValue((_a = node._state) === null || _a === void 0 ? void 0 : _a.fill, this.element), '#fff']);
|
|
154
152
|
const positions = pie()
|
|
155
|
-
.startAngle(node.parent ? node.x0 : (
|
|
156
|
-
.endAngle(node.parent ? node.x1 : (
|
|
153
|
+
.startAngle(node.parent ? node.x0 : (_a = config.angleRange) === null || _a === void 0 ? void 0 : _a[0])
|
|
154
|
+
.endAngle(node.parent ? node.x1 : (_b = config.angleRange) === null || _b === void 0 ? void 0 : _b[1])
|
|
157
155
|
.value(d => config.showEmptySegments && d.value === 0
|
|
158
156
|
? config.emptySegmentAngle
|
|
159
157
|
: (d.x1 - d.x0))
|
|
160
158
|
.sort(config.sort)(node.children);
|
|
159
|
+
const opacity = scaleLinear()
|
|
160
|
+
.domain([-1, node.children.length])
|
|
161
|
+
.range([(_d = (_c = node._state) === null || _c === void 0 ? void 0 : _c.fillOpacity) !== null && _d !== void 0 ? _d : 1, 0]);
|
|
161
162
|
node.children.forEach((child, i) => {
|
|
162
|
-
var _a;
|
|
163
163
|
child._index = i;
|
|
164
164
|
child.x0 = positions[i].startAngle;
|
|
165
165
|
child.x1 = positions[i].endAngle;
|
|
166
|
+
// Default to parent's fill if segmentColor accessor is not provided
|
|
167
|
+
const color = getColor(child, config.segmentColor, positions[i].index, child.depth !== 1);
|
|
166
168
|
child._state = {
|
|
167
|
-
fill:
|
|
169
|
+
fill: color !== null && color !== void 0 ? color : node._state.fill,
|
|
170
|
+
fillOpacity: color === null ? opacity(positions[i].index) : null,
|
|
168
171
|
};
|
|
169
172
|
});
|
|
170
173
|
});
|