brushHighlight.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. "use strict";
  2. var __rest = (this && this.__rest) || function (s, e) {
  3. var t = {};
  4. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  5. t[p] = s[p];
  6. if (s != null && typeof Object.getOwnPropertySymbols === "function")
  7. for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  8. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
  9. t[p[i]] = s[p[i]];
  10. }
  11. return t;
  12. };
  13. Object.defineProperty(exports, "__esModule", { value: true });
  14. exports.BrushHighlight = exports.brushHighlight = exports.brush = void 0;
  15. const g_1 = require("@antv/g");
  16. const helper_1 = require("../utils/helper");
  17. const scale_1 = require("../utils/scale");
  18. const createElement_1 = require("../utils/createElement");
  19. const selection_1 = require("../utils/selection");
  20. const utils_1 = require("./utils");
  21. function intersect(bbox1, bbox2) {
  22. const [minX1, minY1, maxX1, maxY1] = bbox1;
  23. const [minX2, minY2, maxX2, maxY2] = bbox2;
  24. return !(minX2 > maxX1 || maxX2 < minX1 || minY2 > maxY1 || maxY2 < minY1);
  25. }
  26. function normalizeBounds(x, y, x1, y1, extent) {
  27. const [minX, minY, maxX, maxY] = extent;
  28. return [
  29. Math.max(minX, Math.min(x, x1)),
  30. Math.max(minY, Math.min(y, y1)),
  31. Math.min(maxX, Math.max(x, x1)),
  32. Math.min(maxY, Math.max(y, y1)),
  33. ];
  34. }
  35. function bboxOf(root) {
  36. const { width, height } = root.getBBox();
  37. return [0, 0, width, height];
  38. }
  39. function applyStyle(selection, style) {
  40. for (const [key, value] of Object.entries(style)) {
  41. selection.style(key, value);
  42. }
  43. }
  44. const ResizableMask = (0, createElement_1.createElement)((g) => {
  45. const _a = g.attributes, { x, y, width, height, class: className, renders = {}, handleSize: size = 10, document } = _a, style = __rest(_a, ["x", "y", "width", "height", "class", "renders", "handleSize", "document"]);
  46. if (!document ||
  47. width === undefined ||
  48. height === undefined ||
  49. x === undefined ||
  50. y === undefined)
  51. return;
  52. const half = size / 2;
  53. const renderRect = (g, options, document) => {
  54. if (!g.handle) {
  55. g.handle = document.createElement('rect');
  56. g.append(g.handle);
  57. }
  58. const { handle } = g;
  59. handle.attr(options);
  60. return handle;
  61. };
  62. const _b = (0, helper_1.subObject)((0, helper_1.omitPrefixObject)(style, 'handleNW', 'handleNE'), 'handleN'), { render: handleNRender = renderRect } = _b, handleNStyle = __rest(_b, ["render"]);
  63. const _c = (0, helper_1.subObject)(style, 'handleE'), { render: handleERender = renderRect } = _c, handleEStyle = __rest(_c, ["render"]);
  64. const _d = (0, helper_1.subObject)((0, helper_1.omitPrefixObject)(style, 'handleSE', 'handleSW'), 'handleS'), { render: handleSRender = renderRect } = _d, handleSStyle = __rest(_d, ["render"]);
  65. const _e = (0, helper_1.subObject)(style, 'handleW'), { render: handleWRender = renderRect } = _e, handleWStyle = __rest(_e, ["render"]);
  66. const _f = (0, helper_1.subObject)(style, 'handleNW'), { render: handleNWRender = renderRect } = _f, handleNWStyle = __rest(_f, ["render"]);
  67. const _g = (0, helper_1.subObject)(style, 'handleNE'), { render: handleNERender = renderRect } = _g, handleNEStyle = __rest(_g, ["render"]);
  68. const _h = (0, helper_1.subObject)(style, 'handleSE'), { render: handleSERender = renderRect } = _h, handleSEStyle = __rest(_h, ["render"]);
  69. const _j = (0, helper_1.subObject)(style, 'handleSW'), { render: handleSWRender = renderRect } = _j, handleSWStyle = __rest(_j, ["render"]);
  70. const renderHandle = (g, renderNode) => {
  71. const { id } = g;
  72. const _a = g.attributes, { x, y } = _a, style = __rest(_a, ["x", "y"]);
  73. const handle = renderNode(g, Object.assign({ x: 0, y: 0 }, style), document);
  74. handle.id = id;
  75. handle.style.draggable = true;
  76. };
  77. const appendHandle = (handleRender) => {
  78. return () => {
  79. const Node = (0, createElement_1.createElement)((g) => renderHandle(g, handleRender));
  80. return new Node({});
  81. };
  82. };
  83. const container = (0, selection_1.select)(g)
  84. .attr('className', className)
  85. .style('x', x)
  86. .style('y', y)
  87. .style('draggable', true);
  88. container
  89. .maybeAppend('selection', 'rect')
  90. .style('draggable', true)
  91. .style('fill', 'transparent')
  92. .call(applyStyle, Object.assign({ width, height }, (0, helper_1.omitPrefixObject)(style, 'handle')));
  93. container
  94. .maybeAppend('handle-n', appendHandle(handleNRender))
  95. .style('x', half)
  96. .style('y', -half)
  97. .style('width', width - size)
  98. .style('height', size)
  99. .style('fill', 'transparent')
  100. .call(applyStyle, handleNStyle);
  101. container
  102. .maybeAppend('handle-e', appendHandle(handleERender))
  103. .style('x', width - half)
  104. .style('y', half)
  105. .style('width', size)
  106. .style('height', height - size)
  107. .style('fill', 'transparent')
  108. .call(applyStyle, handleEStyle);
  109. container
  110. .maybeAppend('handle-s', appendHandle(handleSRender))
  111. .style('x', half)
  112. .style('y', height - half)
  113. .style('width', width - size)
  114. .style('height', size)
  115. .style('fill', 'transparent')
  116. .call(applyStyle, handleSStyle);
  117. container
  118. .maybeAppend('handle-w', appendHandle(handleWRender))
  119. .style('x', -half)
  120. .style('y', half)
  121. .style('width', size)
  122. .style('height', height - size)
  123. .style('fill', 'transparent')
  124. .call(applyStyle, handleWStyle);
  125. container
  126. .maybeAppend('handle-nw', appendHandle(handleNWRender))
  127. .style('x', -half)
  128. .style('y', -half)
  129. .style('width', size)
  130. .style('height', size)
  131. .style('fill', 'transparent')
  132. .call(applyStyle, handleNWStyle);
  133. container
  134. .maybeAppend('handle-ne', appendHandle(handleNERender))
  135. .style('x', width - half)
  136. .style('y', -half)
  137. .style('width', size)
  138. .style('height', size)
  139. .style('fill', 'transparent')
  140. .call(applyStyle, handleNEStyle);
  141. container
  142. .maybeAppend('handle-se', appendHandle(handleSERender))
  143. .style('x', width - half)
  144. .style('y', height - half)
  145. .style('width', size)
  146. .style('height', size)
  147. .style('fill', 'transparent')
  148. .call(applyStyle, handleSEStyle);
  149. container
  150. .maybeAppend('handle-sw', appendHandle(handleSWRender))
  151. .style('x', -half)
  152. .style('y', height - half)
  153. .style('width', size)
  154. .style('height', size)
  155. .style('fill', 'transparent')
  156. .call(applyStyle, handleSWStyle);
  157. });
  158. function brush(root, _a) {
  159. var { brushed = () => { }, brushended = () => { }, brushcreated = () => { }, extent = bboxOf(root), brushRegion = (x, y, x1, y1, extent) => [x, y, x1, y1], reverse = false, fill = '#777', fillOpacity = '0.3', stroke = '#fff', selectedHandles = [
  160. 'handle-n',
  161. 'handle-e',
  162. 'handle-s',
  163. 'handle-w',
  164. 'handle-nw',
  165. 'handle-ne',
  166. 'handle-se',
  167. 'handle-sw',
  168. ] } = _a, style = __rest(_a, ["brushed", "brushended", "brushcreated", "extent", "brushRegion", "reverse", "fill", "fillOpacity", "stroke", "selectedHandles"]);
  169. let start = null; // Start point of mask.
  170. let end = null; // End point of mask.
  171. let moveStart = null; // Start point of moving mask.
  172. let mask = null; // Mask instance.
  173. let background = null;
  174. let creating = false;
  175. const [originX, originY, width, height] = extent;
  176. (0, utils_1.setCursor)(root, 'crosshair');
  177. root.style.draggable = true; // Make it response to drag event.
  178. // Remove old mask and init new mask.
  179. const initMask = (x, y) => {
  180. if (mask)
  181. mask.remove();
  182. if (background)
  183. background.remove();
  184. start = [x, y];
  185. if (reverse)
  186. return initReverseMask();
  187. initNormalMask();
  188. };
  189. const initReverseMask = () => {
  190. background = new g_1.Path({
  191. style: Object.assign(Object.assign({}, style), { fill,
  192. fillOpacity,
  193. stroke, pointerEvents: 'none' }),
  194. });
  195. mask = new ResizableMask({
  196. // @ts-ignore
  197. style: {
  198. x: 0,
  199. y: 0,
  200. width: 0,
  201. height: 0,
  202. draggable: true,
  203. document: root.ownerDocument,
  204. },
  205. className: 'mask',
  206. });
  207. root.appendChild(background);
  208. root.appendChild(mask);
  209. };
  210. const initNormalMask = () => {
  211. mask = new ResizableMask({
  212. // @ts-ignore
  213. style: Object.assign(Object.assign({ document: root.ownerDocument, x: 0, y: 0 }, style), { fill,
  214. fillOpacity,
  215. stroke, draggable: true }),
  216. className: 'mask',
  217. });
  218. root.appendChild(mask);
  219. };
  220. // Remove mask and reset states.
  221. const removeMask = (emit = true) => {
  222. if (mask)
  223. mask.remove();
  224. if (background)
  225. background.remove();
  226. start = null;
  227. end = null;
  228. moveStart = null;
  229. creating = false;
  230. mask = null;
  231. background = null;
  232. brushended(emit);
  233. };
  234. // Update mask and invoke brushended callback.
  235. const updateMask = (start, end, emit = true) => {
  236. const [x, y, x1, y1] = normalizeBounds(start[0], start[1], end[0], end[1], extent);
  237. const [fx, fy, fx1, fy1] = brushRegion(x, y, x1, y1, extent);
  238. if (reverse)
  239. updateReverseMask(fx, fy, fx1, fy1);
  240. else
  241. updateNormalMask(fx, fy, fx1, fy1);
  242. brushed(fx, fy, fx1, fy1, emit);
  243. return [fx, fy, fx1, fy1];
  244. };
  245. const updateNormalMask = (x, y, x1, y1) => {
  246. mask.style.x = x;
  247. mask.style.y = y;
  248. mask.style.width = x1 - x;
  249. mask.style.height = y1 - y;
  250. };
  251. const updateReverseMask = (x, y, x1, y1) => {
  252. background.style.d = `
  253. M${originX},${originY}L${width},${originY}L${width},${height}L${originX},${height}Z
  254. M${x},${y}L${x},${y1}L${x1},${y1}L${x1},${y}Z
  255. `;
  256. mask.style.x = x;
  257. mask.style.y = y;
  258. mask.style.width = x1 - x;
  259. mask.style.height = y1 - y;
  260. };
  261. // Move and update mask.
  262. const moveMask = (current) => {
  263. const clip = (dt, start, end, min, max) => {
  264. if (dt + start < min)
  265. return min - start;
  266. if (dt + end > max)
  267. return max - end;
  268. return dt;
  269. };
  270. const dx = current[0] - moveStart[0];
  271. const dy = current[1] - moveStart[1];
  272. const dx1 = clip(dx, start[0], end[0], originX, width);
  273. const dy1 = clip(dy, start[1], end[1], originY, height);
  274. const currentStart = [start[0] + dx1, start[1] + dy1];
  275. const currentEnd = [end[0] + dx1, end[1] + dy1];
  276. updateMask(currentStart, currentEnd);
  277. };
  278. const handles = {
  279. 'handle-n': { vector: [0, 1, 0, 0], cursor: 'ns-resize' },
  280. 'handle-e': { vector: [0, 0, 1, 0], cursor: 'ew-resize' },
  281. 'handle-s': { vector: [0, 0, 0, 1], cursor: 'ns-resize' },
  282. 'handle-w': { vector: [1, 0, 0, 0], cursor: 'ew-resize' },
  283. 'handle-nw': { vector: [1, 1, 0, 0], cursor: 'nwse-resize' },
  284. 'handle-ne': { vector: [0, 1, 1, 0], cursor: 'nesw-resize' },
  285. 'handle-se': { vector: [0, 0, 1, 1], cursor: 'nwse-resize' },
  286. 'handle-sw': { vector: [1, 0, 0, 1], cursor: 'nesw-resize' },
  287. };
  288. const isMask = (target) => {
  289. return isSelection(target) || isHandle(target);
  290. };
  291. const isHandle = (target) => {
  292. const { id } = target;
  293. if (selectedHandles.indexOf(id) === -1)
  294. return false;
  295. return new Set(Object.keys(handles)).has(id);
  296. };
  297. const isSelection = (target) => {
  298. return target === mask.getElementById('selection');
  299. };
  300. // If target is plot area, create mask.
  301. // If target is mask, about to update position.
  302. const dragstart = (event) => {
  303. const { target } = event;
  304. const [offsetX, offsetY] = (0, utils_1.brushMousePosition)(root, event);
  305. if (!mask || !isMask(target)) {
  306. initMask(offsetX, offsetY);
  307. creating = true;
  308. return;
  309. }
  310. if (isMask(target)) {
  311. moveStart = [offsetX, offsetY];
  312. }
  313. };
  314. const drag = (event) => {
  315. const { target } = event;
  316. const mouse = (0, utils_1.brushMousePosition)(root, event);
  317. if (!start)
  318. return;
  319. // If target is plot area, resize mask.
  320. if (!moveStart)
  321. return updateMask(start, mouse);
  322. // If target is selection area, move mask.
  323. if (isSelection(target))
  324. return moveMask(mouse);
  325. // If target is handle area, resize mask.
  326. const [dx, dy] = [mouse[0] - moveStart[0], mouse[1] - moveStart[1]];
  327. const { id } = target;
  328. if (handles[id]) {
  329. const [sx, sy, ex, ey] = handles[id].vector;
  330. return updateMask([start[0] + dx * sx, start[1] + dy * sy], [end[0] + dx * ex, end[1] + dy * ey]);
  331. }
  332. };
  333. // If target is plot area, finish creating.
  334. // If target is mask, finish moving mask.
  335. const dragend = (event) => {
  336. if (moveStart) {
  337. moveStart = null;
  338. // Update start and end;
  339. const { x, y, width, height } = mask.style;
  340. start = [x, y];
  341. end = [x + width, y + height];
  342. return;
  343. }
  344. end = (0, utils_1.brushMousePosition)(root, event);
  345. const [fx, fy, fx1, fy1] = updateMask(start, end);
  346. creating = false;
  347. brushcreated(fx, fy, fx1, fy1, event);
  348. };
  349. // Hide mask.
  350. const click = (event) => {
  351. const { target } = event;
  352. if (mask && !isMask(target))
  353. removeMask();
  354. };
  355. // Update cursor depends on hovered element.
  356. const pointermove = (event) => {
  357. const { target } = event;
  358. if (!mask || !isMask(target) || creating)
  359. (0, utils_1.setCursor)(root, 'crosshair');
  360. else if (isSelection(target))
  361. (0, utils_1.setCursor)(root, 'move');
  362. else if (isHandle(target))
  363. (0, utils_1.setCursor)(root, handles[target.id].cursor);
  364. };
  365. const pointerleave = () => {
  366. (0, utils_1.setCursor)(root, 'default');
  367. };
  368. root.addEventListener('dragstart', dragstart);
  369. root.addEventListener('drag', drag);
  370. root.addEventListener('dragend', dragend);
  371. root.addEventListener('click', click);
  372. root.addEventListener('pointermove', pointermove);
  373. root.addEventListener('pointerleave', pointerleave);
  374. return {
  375. mask,
  376. move(x, y, x1, y1, emit = true) {
  377. if (!mask)
  378. initMask(x, y);
  379. start = [x, y];
  380. end = [x1, y1];
  381. updateMask([x, y], [x1, y1], emit);
  382. },
  383. remove() {
  384. if (mask)
  385. removeMask(false);
  386. },
  387. destroy() {
  388. // Do not emit brush:end event.
  389. if (mask)
  390. removeMask(false);
  391. (0, utils_1.setCursor)(root, 'default');
  392. root.removeEventListener('dragstart', dragstart);
  393. root.removeEventListener('drag', drag);
  394. root.removeEventListener('dragend', dragend);
  395. root.removeEventListener('click', click);
  396. root.removeEventListener('pointermove', pointermove);
  397. root.removeEventListener('pointerleave', pointerleave);
  398. },
  399. };
  400. }
  401. exports.brush = brush;
  402. function selectSiblingViews(target, viewInstances, brushKey) {
  403. return viewInstances.filter((d) => {
  404. if (d === target)
  405. return false;
  406. const { interaction = {} } = d.options;
  407. return Object.values(interaction).find((d) => d.brushKey === brushKey);
  408. });
  409. }
  410. function selectSiblingContainers(target, viewInstances, brushKey) {
  411. return selectSiblingViews(target, viewInstances, brushKey).map((d) => (0, utils_1.selectPlotArea)(d.container));
  412. }
  413. function selectSiblingOptions(target, viewInstances, brushKey) {
  414. return selectSiblingViews(target, viewInstances, brushKey).map((d) => d.options);
  415. }
  416. /**
  417. * @todo Brush over view for series view.
  418. * @todo Test perf.
  419. */
  420. function brushHighlight(root, _a) {
  421. var { elements: elementof, selectedHandles, siblings: siblingsof = (root) => [], datum, brushRegion, extent: optionalExtent, reverse, scale, coordinate, series = false, key = (d) => d, bboxOf = (root) => {
  422. const { x, y, width, height } = root.style;
  423. return { x, y, width, height };
  424. }, state = {}, emitter } = _a, rest = __rest(_a, ["elements", "selectedHandles", "siblings", "datum", "brushRegion", "extent", "reverse", "scale", "coordinate", "series", "key", "bboxOf", "state", "emitter"]);
  425. const elements = elementof(root);
  426. const siblings = siblingsof(root);
  427. const siblingElements = siblings.flatMap(elementof);
  428. const valueof = (0, utils_1.createValueof)(elements, datum);
  429. const brushStyle = (0, helper_1.subObject)(rest, 'mask');
  430. const { setState, removeState } = (0, utils_1.useState)(state, valueof);
  431. const clonedElement = new Map();
  432. const { width: rootWidth, height: rootHeight, x: ordinalX = 0, y: ordinalY = 0, } = bboxOf(root);
  433. const extent = optionalExtent
  434. ? optionalExtent
  435. : [0, 0, rootWidth, rootHeight];
  436. const brushended = () => {
  437. for (const element of [...elements, ...siblingElements]) {
  438. removeState(element, 'active', 'inactive');
  439. }
  440. };
  441. const brushed = (x, y, x1, y1) => {
  442. var _a;
  443. // Hide brush for the sibling view.
  444. for (const sibling of siblings)
  445. (_a = sibling.brush) === null || _a === void 0 ? void 0 : _a.remove();
  446. // Store the key of the active element.
  447. const keys = new Set();
  448. // Highlight and store selected elements.
  449. for (const element of elements) {
  450. const { min, max } = element.getLocalBounds();
  451. const [ex, ey] = min;
  452. const [ex1, ey1] = max;
  453. if (!intersect([ex, ey, ex1, ey1], [x, y, x1, y1])) {
  454. setState(element, 'inactive');
  455. }
  456. else {
  457. setState(element, 'active');
  458. keys.add(key(element));
  459. }
  460. }
  461. // Highlight elements with same key in sibling view.
  462. for (const element of siblingElements) {
  463. if (keys.has(key(element)))
  464. setState(element, 'active');
  465. else
  466. setState(element, 'inactive');
  467. }
  468. };
  469. const seriesBrushend = () => {
  470. for (const element of elements)
  471. removeState(element, 'inactive');
  472. for (const cloned of clonedElement.values())
  473. cloned.remove();
  474. clonedElement.clear();
  475. };
  476. const seriesBrushed = (x, y, x1, y1) => {
  477. const clone = (element) => {
  478. const cloned = element.cloneNode();
  479. cloned.__data__ = element.__data__;
  480. element.parentNode.appendChild(cloned);
  481. clonedElement.set(element, cloned);
  482. return cloned;
  483. };
  484. for (const element of elements) {
  485. const cloned = clonedElement.get(element) || clone(element);
  486. cloned.style.clipPath = new g_1.Rect({
  487. style: {
  488. x: x + ordinalX,
  489. y: y + ordinalY,
  490. width: x1 - x,
  491. height: y1 - y,
  492. },
  493. });
  494. setState(element, 'inactive');
  495. setState(cloned, 'active');
  496. }
  497. };
  498. const brushHandler = brush(root, Object.assign(Object.assign({}, brushStyle), { extent,
  499. brushRegion,
  500. reverse,
  501. selectedHandles, brushended: (emit) => {
  502. const handler = series ? seriesBrushend : brushended;
  503. if (emit) {
  504. emitter.emit('brush:remove', { nativeEvent: true });
  505. }
  506. handler();
  507. }, brushed: (x, y, x1, y1, emit) => {
  508. const selection = (0, scale_1.selectionOf)(x, y, x1, y1, scale, coordinate);
  509. if (emit) {
  510. emitter.emit('brush:highlight', {
  511. nativeEvent: true,
  512. data: { selection },
  513. });
  514. }
  515. const handler = series ? seriesBrushed : brushed;
  516. handler(x, y, x1, y1);
  517. } }));
  518. // Move brush and highlight data.
  519. const onHighlight = ({ nativeEvent, data }) => {
  520. if (nativeEvent)
  521. return;
  522. const { selection } = data;
  523. const [x, y, x1, y1] = (0, scale_1.pixelsOf)(selection, scale, coordinate);
  524. brushHandler.move(x, y, x1, y1, false);
  525. };
  526. emitter.on('brush:highlight', onHighlight);
  527. // Remove brush and reset data.
  528. const onRemove = () => brushHandler.remove();
  529. emitter.on('brush:remove', onRemove);
  530. // Remove event handlers.
  531. const preBrushDestroy = brushHandler.destroy.bind(brushHandler);
  532. brushHandler.destroy = () => {
  533. emitter.off('brush:highlight', onHighlight);
  534. emitter.off('brush:remove', onRemove);
  535. preBrushDestroy();
  536. };
  537. return brushHandler;
  538. }
  539. exports.brushHighlight = brushHighlight;
  540. function BrushHighlight(_a) {
  541. var { facet, brushKey } = _a, rest = __rest(_a, ["facet", "brushKey"]);
  542. return (target, viewInstances, emitter) => {
  543. const { container, view, options } = target;
  544. const plotArea = (0, utils_1.selectPlotArea)(container);
  545. const defaultOptions = {
  546. maskFill: '#777',
  547. maskFillOpacity: '0.3',
  548. maskStroke: '#fff',
  549. reverse: false,
  550. };
  551. const defaultStates = ['active', ['inactive', { opacity: 0.5 }]];
  552. const { scale, coordinate } = view;
  553. if (facet) {
  554. const bbox = plotArea.getBounds();
  555. const x = bbox.min[0];
  556. const y = bbox.min[1];
  557. const x1 = bbox.max[0];
  558. const y1 = bbox.max[1];
  559. return brushHighlight(plotArea.parentNode.parentNode, Object.assign(Object.assign({ elements: () => (0, utils_1.selectFacetG2Elements)(target, viewInstances), datum: (0, utils_1.createDatumof)((0, utils_1.selectFacetViews)(target, viewInstances).map((d) => d.view)), brushRegion: (x, y, x1, y1) => [x, y, x1, y1], extent: [x, y, x1, y1], state: (0, utils_1.mergeState)((0, utils_1.selectFacetViews)(target, viewInstances).map((d) => d.options), defaultStates), emitter,
  560. scale,
  561. coordinate, selectedHandles: undefined }, defaultOptions), rest));
  562. }
  563. const brush = brushHighlight(plotArea, Object.assign(Object.assign({ elements: utils_1.selectG2Elements, key: (element) => element.__data__.key, siblings: () => selectSiblingContainers(target, viewInstances, brushKey), datum: (0, utils_1.createDatumof)([
  564. view,
  565. ...selectSiblingViews(target, viewInstances, brushKey).map((d) => d.view),
  566. ]), brushRegion: (x, y, x1, y1) => [x, y, x1, y1], extent: undefined, state: (0, utils_1.mergeState)([options, ...selectSiblingOptions(target, viewInstances, brushKey)], defaultStates), emitter,
  567. scale,
  568. coordinate, selectedHandles: undefined }, defaultOptions), rest));
  569. // Bind brush to the view it belongs to.
  570. //@ts-ignore
  571. plotArea.brush = brush;
  572. return () => brush.destroy();
  573. };
  574. }
  575. exports.BrushHighlight = BrushHighlight;
  576. //# sourceMappingURL=brushHighlight.js.map