Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support both selection and text select #515

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import type { ILineUpOptions, ITaggleOptions } from './config';

export * from './builder';
export * from './config';
export { default as AEventDispatcher, IEventContext, IEventHandler, IEventListener } from './internal/AEventDispatcher';
export { default as AEventDispatcher } from './internal/AEventDispatcher';
export type { IEventContext, IEventHandler, IEventListener } from './internal/AEventDispatcher';
export type { ISequence, IForEachAble } from './internal/interable';
export type { ILookUpArray } from './internal/math';
export * from './internal/mathInterfaces';
Expand Down
9 changes: 2 additions & 7 deletions src/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,8 @@ export * from './IArrayColumn';

export { toCategories } from './internalCategorical';

export {
ScaleMappingFunction,
ScriptMappingFunction,
mappingFunctions,
IScriptMappingFunctionType,
IScriptMappingFunctionContext,
} from './MappingFunction';
export { ScaleMappingFunction, ScriptMappingFunction, mappingFunctions } from './MappingFunction';
export type { IScriptMappingFunctionType, IScriptMappingFunctionContext } from './MappingFunction';
export { DEFAULT_CATEGORICAL_COLOR_FUNCTION, ReplacementColorMappingFunction } from './CategoricalColorMappingFunction';
export {
CustomColorMappingFunction,
Expand Down
3 changes: 2 additions & 1 deletion src/provider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export * from './LocalDataProvider';
export * from './RemoteDataProvider';
export { deriveColors, deriveColumnDescriptions, exportRanking, exportTable } from './utils';
export * from './interfaces';
export { tasksAll, IRenderTaskExecutor } from './tasks';
export { tasksAll } from './tasks';
export type { IRenderTaskExecutor } from './tasks';
export type { CompareLookup } from './sort';
export type { ITopNGetter, IGroupMeta } from './internal';
36 changes: 26 additions & 10 deletions src/ui/SelectionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export declare function selectRange(from: number, to: number, additional: boolea
export default class SelectionManager extends AEventDispatcher {
static readonly EVENT_SELECT_RANGE = 'selectRange';
private static readonly MIN_DISTANCE = 10;
private static readonly MAX_X_DISTANCE = 30;

private readonly hr: HTMLHRElement;

Expand All @@ -51,21 +52,28 @@ export default class SelectionManager extends AEventDispatcher {
this.body.removeEventListener('mouseup', mouseUp);
this.body.removeEventListener('mouseleave', mouseUp);

if (!this.start) {
this.body.classList.remove(cssClass('selection-active'));
this.hr.classList.remove(cssClass('selection-active'));
const start = this.start;
this.start = null;

if (!start) {
return;
}

const valid = Math.abs(start.x - evt.clientX) < SelectionManager.MAX_X_DISTANCE;
if (!valid) {
return;
}

const row = engineCssClass('tr');
const startNode = this.start.node.classList.contains(row)
? this.start.node
: this.start.node.closest<HTMLElement>(`.${row}`);

const startNode = start.node.classList.contains(row) ? start.node : start.node.closest<HTMLElement>(`.${row}`);

// somehow on firefox the mouseUp will be triggered on the original node
// thus search the node explicitly
const end = this.body.ownerDocument!.elementFromPoint(evt.clientX, evt.clientY) as HTMLElement;
const endNode = end.classList.contains(row) ? end : end.closest<HTMLElement>(`.${row}`);
this.start = null;

this.body.classList.remove(cssClass('selection-active'));
this.hr.classList.remove(cssClass('selection-active'));

this.select(evt.ctrlKey, startNode, endNode);
};
Expand All @@ -74,9 +82,12 @@ export default class SelectionManager extends AEventDispatcher {
'mousedown',
(evt) => {
const r = root.getBoundingClientRect();
const inSelectionColumn = (evt.target as HTMLElement).closest(`.${cssClass('renderer-selection')}`);
if (!inSelectionColumn) {
return;
}
this.start = { x: evt.clientX, y: evt.clientY, xShift: r.left, yShift: r.top, node: evt.target as HTMLElement };

this.body.classList.add(cssClass('selection-active'));
body.addEventListener('mousemove', mouseMove, {
passive: true,
});
Expand Down Expand Up @@ -122,10 +133,15 @@ export default class SelectionManager extends AEventDispatcher {

private showHint(end: MouseEvent) {
const start = this.start!;
const sx = start.x;
const sy = start.y;
const ex = end.clientX;
const ey = end.clientY;

const visible = Math.abs(sy - ey) > SelectionManager.MIN_DISTANCE;
const visible =
Math.abs(sy - ey) > SelectionManager.MIN_DISTANCE && Math.abs(sx - ex) < SelectionManager.MAX_X_DISTANCE;

this.body.classList.toggle(cssClass('selection-active'), visible);
this.hr.classList.toggle(cssClass('selection-active'), visible);
this.hr.style.transform = `translate(${start.x - start.xShift}px,${sy - start.yShift}px)scale(1,${Math.abs(
ey - sy
Expand Down
6 changes: 4 additions & 2 deletions src/ui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ export { default as LineUp } from './LineUp';
export * from './LineUp';
export { default as ALineUp } from './ALineUp';
export * from './panel';
export { default as SlopeGraph, ISlopeGraphOptions } from './SlopeGraph';
export { default as SlopeGraph } from './SlopeGraph';
export type { ISlopeGraphOptions } from './SlopeGraph';
export * from './taggle';
export { default as SelectionIndicator } from './SelectionIndicator';
export { default as RenderColumn, IRenderers } from './RenderColumn';
export { default as RenderColumn } from './RenderColumn';
export type { IRenderers } from './RenderColumn';
3 changes: 2 additions & 1 deletion src/ui/taggle/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './rules';
export { default, default as Taggle } from './Taggle';
export * from './Taggle';
export { default as TaggleRenderer, ITaggleRendererOptions } from './TaggleRenderer';
export { default as TaggleRenderer } from './TaggleRenderer';
export type { ITaggleRendererOptions } from './TaggleRenderer';