Skip to content

Commit

Permalink
style: rename graph to graphics
Browse files Browse the repository at this point in the history
  • Loading branch information
F-star committed Jul 8, 2024
1 parent 85cc775 commit 0782d2a
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 62 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export class ClipboardManager {
try {
pastedData = JSON.parse(dataStr);
} catch (e) {
// TODO: create text graph from pastedData
// TODO: create text graphics from pastedData
return;
}

Expand All @@ -236,7 +236,7 @@ export class ClipboardManager {
pastedData.data
)
) {
// TODO: create text graph from pastedData
// TODO: create text graphics from pastedData
return;
}

Expand Down
20 changes: 10 additions & 10 deletions packages/core/src/control_handle_manager/control_handle_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export class ControlHandleManager {
handle.cy = point.y;
}

// update n/s/w/e handle graph size
// update n/s/w/e handle graphics size
const n = this.transformHandles.get('n')!;
const s = this.transformHandles.get('s')!;
const w = this.transformHandles.get('w')!;
Expand Down Expand Up @@ -208,37 +208,37 @@ export class ControlHandleManager {
const ctx = this.editor.ctx;
const rotate = rect ? getTransformAngle(rect.transform) : 0;
handles.forEach((handle) => {
const graph = handle.graphics;
if (graph.type === GraphicsType.Path) {
const graphics = handle.graphics;
if (graphics.type === GraphicsType.Path) {
// TODO:
} else {
const { x, y } = this.editor.sceneCoordsToViewport(
handle.cx,
handle.cy,
);
graph.updateAttrs({
graphics.updateAttrs({
transform: [
1,
0,
0,
1,
x - graph.attrs.width / 2,
y - graph.attrs.height / 2,
x - graphics.attrs.width / 2,
y - graphics.attrs.height / 2,
],
});
}
if (rect && handle.isTransformHandle) {
graph.setRotate(rotate);
graphics.setRotate(rotate);
}
if (handle.rotation !== undefined) {
graph.setRotate(handle.rotation);
graphics.setRotate(handle.rotation);
}

if (!graph.isVisible()) {
if (!graphics.isVisible()) {
return;
}
ctx.save();
graph.draw(ctx);
graphics.draw(ctx);
ctx.restore();
});
}
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/ref_line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ export class RefLine {
});
}

for (const graph of refGraphicsSet) {
if (selectIdSet.has(graph.attrs.id)) {
for (const graphics of refGraphicsSet) {
if (selectIdSet.has(graphics.attrs.id)) {
continue;
}

const bbox = bboxToBboxWithMid(graph.getBbox());
const bbox = bboxToBboxWithMid(graphics.getBbox());
if (!isBoxIntersect(viewportBbox, bbox)) {
continue;
}
Expand Down Expand Up @@ -107,7 +107,7 @@ export class RefLine {
* top 和 bottom 要绘制水平参考线,不要绘制垂直参照线
* left 和 right 要绘制垂直参照线,不要绘制水平参照线
*/
const bboxVerts = graph.getWorldBboxVerts();
const bboxVerts = graphics.getWorldBboxVerts();

if (setting.get('snapToGrid')) {
const gridSnapSpacingX = setting.get('gridSnapX');
Expand Down
14 changes: 7 additions & 7 deletions packages/core/src/scene/scene_graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ export class SceneGraph {
}

addItems(graphicsArr: SuikaGraphics[]) {
for (const graph of graphicsArr) {
this.editor.doc.addGraphics(graph);
for (const graphics of graphicsArr) {
this.editor.doc.addGraphics(graphics);
}
}

Expand Down Expand Up @@ -116,7 +116,7 @@ export class SceneGraph {
this.grid.draw();
}

/** draw hover graph outline and its control handle */
/** draw hover graphics outline and its control handle */
if (this.highlightLayersOnHover && setting.get('highlightLayersOnHover')) {
const hlItem = selectedElements.getHighlightedItem();
if (hlItem && !selectedElements.hasItem(hlItem)) {
Expand Down Expand Up @@ -195,7 +195,7 @@ export class SceneGraph {
});

private drawGraphsOutline(
graphs: SuikaGraphics[],
graphicsArr: SuikaGraphics[],
strokeWidth: number,
stroke: string,
) {
Expand All @@ -212,9 +212,9 @@ export class SceneGraph {
ctx.translate(dx, dy);

strokeWidth /= zoom;
for (const graph of graphs) {
for (const graphics of graphicsArr) {
ctx.save();
graph.drawOutline(ctx, stroke, strokeWidth);
graphics.drawOutline(ctx, stroke, strokeWidth);
ctx.restore();
}
ctx.restore();
Expand Down Expand Up @@ -254,7 +254,7 @@ export class SceneGraph {
const type = attrs.type;
const Ctor = graphCtorMap[type!];
if (!Ctor) {
console.error(`Unsupported graph type "${attrs.type}", ignore it`);
console.error(`Unsupported graphics type "${attrs.type}", ignore it`);
continue;
}
children.push(new Ctor(attrs as any, { doc: this.editor.doc }));
Expand Down
18 changes: 9 additions & 9 deletions packages/core/src/selected_elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,26 +169,26 @@ export class SelectedElements {
this.setItems(parent.getChildren().filter((item) => !item.isLock()));
}

setHoverItem(graph: SuikaGraphics | null) {
setHoverItem(graphics: SuikaGraphics | null) {
const prevHoverItem = this.hoverItem;
this.hoverItem = graph;
this.setHighlightedItem(graph);
if (prevHoverItem !== graph) {
this.eventEmitter.emit('hoverItemChange', graph, this.hoverItem);
this.hoverItem = graphics;
this.setHighlightedItem(graphics);
if (prevHoverItem !== graphics) {
this.eventEmitter.emit('hoverItemChange', graphics, this.hoverItem);
}
}

getHoverItem(): SuikaGraphics | null {
return this.hoverItem;
}

setHighlightedItem(graph: SuikaGraphics | null) {
setHighlightedItem(graphics: SuikaGraphics | null) {
const prevHighlightItem = this.highlightedItem;
this.highlightedItem = graph;
if (prevHighlightItem !== graph) {
this.highlightedItem = graphics;
if (prevHighlightItem !== graphics) {
this.eventEmitter.emit(
'highlightedItemChange',
graph,
graphics,
this.highlightedItem,
);
}
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/service/mutate_graphs_and_record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,15 @@ export const MutateGraphsAndRecord = {
},

/**
* show graphs when at least one graph is hidden
* show graphs when at least one graphics is hidden
* and
* hide graphs when all graphs are shown
*/
toggleVisible(editor: SuikaEditor, graphicsArr: SuikaGraphics[]) {
if (graphicsArr.length === 0) {
return;
}
// if at least one graph is hidden, show all graphs; otherwise, hide all graphs
// if at least one graphics is hidden, show all graphs; otherwise, hide all graphs
const newVal = graphicsArr.some((item) => !item.isVisible());

const transaction = new Transaction(editor);
Expand All @@ -242,7 +242,7 @@ export const MutateGraphsAndRecord = {
return;
}

// if at least one graph is unlocked, lock all graphs; otherwise, unlock all graphs
// if at least one graphics is unlocked, lock all graphs; otherwise, unlock all graphs
const newLock = graphicsArr.some((item) => !item.isLock());
const prevAttrs = graphicsArr.map((el) => ({ lock: el.attrs.lock }));
graphicsArr.forEach((el) => {
Expand All @@ -260,7 +260,7 @@ export const MutateGraphsAndRecord = {
);
},

/** set name of graph */
/** set name of graphics */
setGraphName(
editor: SuikaEditor,
graphics: SuikaGraphics,
Expand All @@ -272,7 +272,7 @@ export const MutateGraphsAndRecord = {
});
editor.commandManager.pushCommand(
new SetGraphsAttrsCmd(
'update name of graph',
'update name of graphics',
[graphics],
{ objectName },
prevAttrs,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class Setting {
256,
],

drawGraphDefaultWidth: 100, // drawing graph default width if no drag
drawGraphDefaultWidth: 100, // drawing graphics default width if no drag
drawGraphDefaultHeight: 100, // default height

/**** ruler ****/
Expand Down
10 changes: 6 additions & 4 deletions packages/core/src/to_svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import { boxToRect, mergeBoxes } from '@suika/geo';

import { type SuikaGraphics } from './graphs';

export const toSVG = (graphs: SuikaGraphics[]) => {
export const toSVG = (graphicsArr: SuikaGraphics[]) => {
// FIXME: to sort
const mergedBbox = mergeBoxes(graphs.map((el) => el.getBboxWithStroke()));
const mergedBbox = mergeBoxes(
graphicsArr.map((el) => el.getBboxWithStroke()),
);
const mergedRect = boxToRect(mergedBbox);
const offset = {
x: -mergedBbox.minX,
Expand All @@ -15,8 +17,8 @@ export const toSVG = (graphs: SuikaGraphics[]) => {
const svgTail = `</svg>`;

let content = '';
for (const graph of graphs) {
content += graph.toSVGSegment(offset);
for (const graphics of graphicsArr) {
content += graphics.toSVGSegment(offset);
}

return svgHead + content + svgTail;
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/tools/tool_draw_graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export abstract class DrawGraphTool implements ITool {
/** lastPoint with snap when dragging */
private lastMousePoint!: IPoint;
/**
* use to calculate the offset, to change the graph's start point
* use to calculate the offset, to change the graphics's start point
*/
private startPointWhenSpaceDown: IPoint | null = null;
private lastDragPointWhenSpaceDown: IPoint | null = null;
Expand Down Expand Up @@ -119,8 +119,8 @@ export abstract class DrawGraphTool implements ITool {
this.updateRect();
}
/**
* create graph, and give the original rect (width may be negative)
* noMove: if true, the graph will not move when drag
* create graphics, and give the original rect (width may be negative)
* noMove: if true, the graphics will not move when drag
*/
protected abstract createGraph(
rect: IRect,
Expand All @@ -137,7 +137,7 @@ export abstract class DrawGraphTool implements ITool {
}

/**
* update graph, and give the original rect (width may be negative)
* update graphics, and give the original rect (width may be negative)
*/
protected updateGraph(rect: IRect) {
rect = normalizeRect(rect);
Expand Down Expand Up @@ -194,9 +194,9 @@ export abstract class DrawGraphTool implements ITool {
height, // height may be negative
};

// whether to set the starting point as the center of the graph
// whether to set the starting point as the center of the graphics
const isStartPtAsCenter = this.editor.hostEventManager.isAltPressing;
// whether to keep the graph square
// whether to keep the graphics square
const keepSquare = this.editor.hostEventManager.isShiftPressing;

let cx = 0;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/tools/tool_select/tool_select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class SelectTool implements ITool {
private readonly strategySelectRotation: SelectRotationTool;
private readonly strategySelectResize: SelectResizeTool;

/** the graph should be removed from selected if not moved */
/** the graphics should be removed from selected if not moved */
private graphShouldRemovedFromSelectedIfNotMoved: SuikaGraphics | null = null;

constructor(private editor: SuikaEditor) {
Expand Down
2 changes: 1 addition & 1 deletion packages/geo/src/geo/geo_resize_line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { distance } from './geo_point';

/**
* Get the new position of the line when resizing
* we consider the graph with 0 height as a line
* we consider the graphics with 0 height as a line
*
* TODO: reuse, this is something same code in tool_draw_graph.ts
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/suika/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@suika/suika",
"version": "0.0.1",
"description": "a graph editor.",
"description": "a graphics editor.",
"private": true,
"type": "module",
"scripts": {
Expand Down
22 changes: 11 additions & 11 deletions packages/suika/src/components/LayerPanel/LayerPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,38 +46,38 @@ export const LayerPanel: FC = () => {

const setEditorHlId = (id: string) => {
if (editor) {
const graph = editor.doc.getGraphicsById(id) ?? null;
const graphics = editor.doc.getGraphicsById(id) ?? null;

editor.selectedElements.setHighlightedItem(graph);
editor.selectedElements.setHighlightedItem(graphics);
editor.render();
}
};

const setName = (id: string, newName: string) => {
if (editor) {
const graph = editor.doc.getGraphicsById(id);
if (graph && graph.attrs.objectName !== newName) {
MutateGraphsAndRecord.setGraphName(editor, graph, newName);
const graphics = editor.doc.getGraphicsById(id);
if (graphics && graphics.attrs.objectName !== newName) {
MutateGraphsAndRecord.setGraphName(editor, graphics, newName);
editor.render();
}
}
};

const toggleVisible = (id: string) => {
if (editor) {
const graph = editor.doc.getGraphicsById(id);
if (graph) {
MutateGraphsAndRecord.toggleVisible(editor, [graph]);
const graphics = editor.doc.getGraphicsById(id);
if (graphics) {
MutateGraphsAndRecord.toggleVisible(editor, [graphics]);
editor.render();
}
}
};

const toggleLock = (id: string) => {
if (editor) {
const graph = editor.doc.getGraphicsById(id);
if (graph) {
MutateGraphsAndRecord.toggleLock(editor, [graph]);
const graphics = editor.doc.getGraphicsById(id);
if (graphics) {
MutateGraphsAndRecord.toggleLock(editor, [graphics]);
editor.render();
}
}
Expand Down

0 comments on commit 0782d2a

Please sign in to comment.