Skip to content

Commit

Permalink
Replace seed option with roughjs_config option (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoonieaj authored Jun 18, 2024
1 parent 399a80e commit 4b0decb
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 49 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
- Removed the `isClass` and `stack_frame` attributes and embedded them as the types `.class` and `.frame`.
- Renamed the input for blank objects from `BLANK` to `.blank`.
- Created new type `.blank-frame` to denote blank stack frames.
- Replaced `seed` configuration option with general configuration option `roughjs_config`.

### ✨ Enhancements

Expand Down
1 change: 0 additions & 1 deletion demo/src/MemoryModelsUserInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { ExpandMore } from "@mui/icons-material";
interface configDataPropTypes {
useAutomation: boolean;
overallDrawConfig: {
seed: Number;
[key: string]: any;
};
}
Expand Down
2 changes: 1 addition & 1 deletion demo/src/__tests__/MemoryModelsUserInput.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe("MemoryModelsUserInput", () => {
const configDataMock = {
useAutomation: true,
overallDrawConfig: {
seed: 0,
roughjs_config: { options: { seed: 0 } },
},
};
const setConfigDataMock = jest.fn();
Expand Down
2 changes: 1 addition & 1 deletion memory-viz/src/automate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function drawAutomated(objects: DrawnEntity[], width, configuration) {
const m = new MemoryModel({
width: width,
height: final_height,
seed: configuration.seed,
roughjs_config: configuration.roughjs_config,
});

m.drawAll(StackFrames);
Expand Down
10 changes: 5 additions & 5 deletions memory-viz/src/memory_model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class MemoryModel {
list_index_sep: number; // Vertical offset for list index labels
font_size: number; // Font size, in px
browser: boolean; // Whether this library is being used in a browser context
seed: number; // Seed for RoughJS generated shape(s). 0 if wanting randomness, between 1 and 2^31 otherwise.
roughjs_config: object; // Configuration object used to pass in options to rough.js

constructor(options?: any) {
options = options || {};
Expand All @@ -75,8 +75,8 @@ export class MemoryModel {

this.svg.setAttribute("width", options.width || 800);
this.svg.setAttribute("height", options.height || 800);
this.seed = options.seed || 0;
this.rough_svg = rough.svg(this.svg, { options: { seed: this.seed } });
this.roughjs_config = options.roughjs_config;
this.rough_svg = rough.svg(this.svg, this.roughjs_config);

// The user must not directly use this constructor; their only interaction should be with 'user_functions.draw'.
for (const key in config) {
Expand Down Expand Up @@ -707,7 +707,7 @@ export class MemoryModel {
if (style === undefined) {
style = this.rect_style;
}
style = { ...style, seed: this.seed };
style = { ...style, config: this.roughjs_config };

this.svg.appendChild(
this.rough_svg.rectangle(x, y, width, height, style)
Expand Down Expand Up @@ -810,7 +810,7 @@ export class MemoryModel {
obj.style = styleSoFar;
}

obj.style = populateStyleObject(obj, this.seed);
obj.style = populateStyleObject(obj, this.roughjs_config);

const frame_types = [".frame", ".blank-frame"];
if (frame_types.includes(obj.type) || obj.type === ".class") {
Expand Down
10 changes: 5 additions & 5 deletions memory-viz/src/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ const primitives: Array<string> = [
* well as many more.
* @param {DrawnEntity} object : the object that represents a Python object the user wants drawn. The style object
* corresponding to 'object' will be extracted be doing object.style.
* @param {Number} seed : a numeric seed. If valued between 1 and 2^31, RoughJS will generate the exact same shape(s)
* when provided with the same seed. If valued at 0, RoughJS will generate random shape(s).
* @returns {Style}
* @param {object} roughjs_config : a configuration object used to pass in options to rough.js
* @returns {Style}
*/
function populateStyleObject(object: DrawnEntity, seed: Number) {
function populateStyleObject(object: DrawnEntity, roughjs_config: object) {
let style_so_far = common_style;

let object_type;
Expand All @@ -102,7 +102,7 @@ function populateStyleObject(object: DrawnEntity, seed: Number) {
// Note that, the later will take precedence over styleSoFar.
style_so_far = merge(style_so_far, object.style || {});

return { ...style_so_far, seed: seed };
return { ...style_so_far, config: roughjs_config };
}

// Constants employed to establish presets for styles.
Expand Down
8 changes: 8 additions & 0 deletions memory-viz/src/tests/__snapshots__/draw.spec.tsx.snap

Large diffs are not rendered by default.

Loading

0 comments on commit 4b0decb

Please sign in to comment.