Skip to content

Commit

Permalink
fixed bug with displaying strand and domain names where the React com…
Browse files Browse the repository at this point in the history
…ponents were not being passed the helix svg positions causing a crash
  • Loading branch information
dave-doty committed Jan 18, 2022
1 parent 93fa987 commit a5a54a7
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/src/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ import 'actions/actions.dart' as actions;
App app;

const SCADNANO_PROD = String.fromEnvironment('SCADNANO_PROD');
const USE_REDUX_DEV_TOOLS = SCADNANO_PROD != 'true';
// const USE_REDUX_DEV_TOOLS = false;
// const USE_REDUX_DEV_TOOLS = SCADNANO_PROD != 'true';
const USE_REDUX_DEV_TOOLS = false;

const RUN_TEST_CODE_INSTEAD_OF_APP = false;
//const RUN_TEST_CODE_INSTEAD_OF_APP = true;
Expand Down
18 changes: 15 additions & 3 deletions lib/src/view/design_main_strand.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ class DesignMainStrandComponent extends UiComponent2<DesignMainStrandProps>
classname += ' ' + constants.css_selector_scaffold;
}

// only store enough of helix svg positions for helices this strand has
Map<int, Point<num>> helix_idx_to_svg_position_y_map_on_strand_unbuilt = {};
for (var domain in props.strand.domains) {
helix_idx_to_svg_position_y_map_on_strand_unbuilt[domain.helix] =
props.helix_idx_to_svg_position_map[domain.helix];
}
BuiltMap<int, Point<num>> helix_idx_to_svg_position_y_map_on_strand =
helix_idx_to_svg_position_y_map_on_strand_unbuilt.build();

return (Dom.g()
..id = props.strand.id
..onPointerDown = handle_click_down
Expand All @@ -119,7 +128,7 @@ class DesignMainStrandComponent extends UiComponent2<DesignMainStrandProps>
..drawing_potential_crossover = props.drawing_potential_crossover
..moving_dna_ends = props.moving_dna_ends
..geometry = props.geometry
..helix_idx_to_svg_position_map = props.helix_idx_to_svg_position_map
..helix_idx_to_svg_position_map = helix_idx_to_svg_position_y_map_on_strand
..only_display_selected_helices = props.only_display_selected_helices)(),
_insertions(),
_deletions(),
Expand All @@ -134,6 +143,7 @@ class DesignMainStrandComponent extends UiComponent2<DesignMainStrandProps>
..only_display_selected_helices = props.only_display_selected_helices
..show_domain_names = props.show_domain_names
..show_strand_names = props.show_strand_names
..helix_idx_to_svg_position_y_map = helix_idx_to_svg_position_y_map_on_strand
..domain_name_font_size = props.domain_name_font_size
..strand_name_font_size = props.strand_name_font_size
..key = 'domain-names')(),
Expand All @@ -148,7 +158,8 @@ class DesignMainStrandComponent extends UiComponent2<DesignMainStrandProps>
..selected_modifications_in_strand = props.selected_modifications_in_strand
..font_size = props.modification_font_size
..display_connector = props.modification_display_connector
..helix_idx_to_svg_position_y_map = props.helix_idx_to_svg_position_map.map((i, p) => MapEntry(i, p.y))
..helix_idx_to_svg_position_y_map =
props.helix_idx_to_svg_position_map.map((i, p) => MapEntry(i, p.y))
..key = 'modifications')(),
]);
}
Expand All @@ -160,7 +171,8 @@ class DesignMainStrandComponent extends UiComponent2<DesignMainStrandProps>
// select/deselect
props.strand.handle_selection_mouse_down(event);
// set up drag detection for moving DNA ends
var address = util.find_closest_address(event, props.helices.values, props.groups, props.geometry, props.helix_idx_to_svg_position_map);
var address = util.find_closest_address(
event, props.helices.values, props.groups, props.geometry, props.helix_idx_to_svg_position_map);
HelixGroup group = app.state.design.group_of_strand(props.strand);
var helices_view_order_inverse = group.helices_view_order_inverse;
app.dispatch(actions.StrandsMoveStartSelectedStrands(
Expand Down
9 changes: 9 additions & 0 deletions lib/src/view/design_main_strand_and_domain_names.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:math';

import 'package:built_collection/built_collection.dart';
import 'package:over_react/over_react.dart';

Expand Down Expand Up @@ -36,6 +38,8 @@ mixin DesignMainStrandAndDomainNamesPropsMixin on UiProps {
bool show_strand_names;
int domain_name_font_size;
int strand_name_font_size;

BuiltMap<int, Point<num>> helix_idx_to_svg_position_y_map;
}

class DesignMainStrandAndDomainNamesProps = UiProps
Expand Down Expand Up @@ -85,6 +89,8 @@ class DesignMainStrandAndDomainNamesComponent extends UiComponent2<DesignMainStr
bool draw_domain = should_draw_domain(
domain_5p.helix, props.side_selected_helix_idxs, props.only_display_selected_helices);

var helix_svg_position = props.helix_idx_to_svg_position_y_map[domain_5p.helix];

// don't bother if 5' domain is not visible; if we give more sophisticated options for where to place
// the strand name later, this should be changed
if (draw_domain && props.strand.name != null) {
Expand All @@ -96,6 +102,7 @@ class DesignMainStrandAndDomainNamesComponent extends UiComponent2<DesignMainStr
..geometry = props.geometry
..font_size = props.strand_name_font_size
..transform = transform_of_helix(domain_5p.helix)
..helix_svg_position_y = helix_svg_position.y
..show_dna = props.show_dna
..show_domain_names = props.show_domain_names
..className = constants.css_selector_strand_name
Expand All @@ -114,12 +121,14 @@ class DesignMainStrandAndDomainNamesComponent extends UiComponent2<DesignMainStr
domain.helix, props.side_selected_helix_idxs, props.only_display_selected_helices);
if (draw_domain && domain.name != null) {
Helix helix = props.helices[substrand.helix];
var helix_svg_position = props.helix_idx_to_svg_position_y_map[substrand.helix];
names.add((DesignMainStrandDomainName()
..domain = substrand
..helix = helix
..geometry = props.geometry
..font_size = props.domain_name_font_size
..transform = transform_of_helix(domain.helix)
..svg_position_y = helix_svg_position.y
..show_dna = props.show_dna
..className = constants.css_selector_domain_name
..key = "domain-name-$i")());
Expand Down
6 changes: 4 additions & 2 deletions lib/src/view/design_main_strand_strand_name.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ class DesignMainStrandStrandNameComponent extends UiComponent2<DesignMainStrandS
with PureComponent {
@override
render() {
Point<num> start_svg = props.helix.svg_base_pos(props.domain.start, props.domain.forward, props.helix_svg_position_y);
Point<num> end_svg = props.helix.svg_base_pos(props.domain.end - 1, props.domain.forward, props.helix_svg_position_y);
Point<num> start_svg =
props.helix.svg_base_pos(props.domain.start, props.domain.forward, props.helix_svg_position_y);
Point<num> end_svg =
props.helix.svg_base_pos(props.domain.end - 1, props.domain.forward, props.helix_svg_position_y);
Point<num> mid_svg = (start_svg + end_svg) * 0.5;

String baseline = props.domain.forward ? 'baseline' : 'hanging';
Expand Down

0 comments on commit a5a54a7

Please sign in to comment.