All files / stories customization.js

0% Statements 0/33
0% Branches 0/2
0% Functions 0/11
0% Lines 0/33
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142                                                                                                                                                                                                                                                                                           
/**
* Copyright 2018, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
 
import React from 'react';
import { storiesOf } from '@storybook/react';
import { MSAViewer } from '../lib';
import { select, text, withKnobs } from '@storybook/addon-knobs';
import {
  zipObject,
} from 'lodash-es';
 
const sequences = [
  {
    name: "seq.1",
    sequence: "MEEPQSDPSIEP-PLSQETFSDLWKLLPENNVLSPLPS-QA-VDDLMLSPDDLAQWLTED"
  },
  {
    name: "seq.2",
    sequence: "MEEPQSDLSIEL-PLSQETFSDLWKLLPPNNVLSTLPS-SDSIEE-LFLSENVAGWLEDP"
  },
  {
    name: "seq.3",
    sequence: "MEEPQSDLSIEL-PLSQETFSDLWKLLPPNNVLSTLPS-SDSIEE-LFLSENVAGWLEDP"
  },
];
 
// Storybook 4 selects only accepts key/value objects
function createObject(options) {
  return zipObject(options, options);
}
 
storiesOf('Customization', module)
  .addDecorator(withKnobs)
  .add('Colorschemes', function(){
    // see https://github.com/wilzbach/msa-colorschemes for now
    const colorschemes = [
      "buried_index", "clustal", "clustal2",
      "cinema", "helix_propensity", "hydro", "lesk", "mae", "nucleotide",
      "purine_pyrimidine", "strand_propensity", "taylor", "turn_propensity",
      "zappo",
    ];
    const options = {
      colorScheme: select("Colorscheme", createObject(colorschemes), "zappo"),
      sequences,
    };
    return (
      <MSAViewer {...options} />
    )
  })
  .add('Custom ColorScheme', function(){
    // see https://github.com/wilzbach/msa-colorschemes for now
    const myColorMap = {
      "M": "blue",
      "E": "red",
      "T": "green",
    }
    class MyColorScheme  {
      getColor(element) {
        return element in myColorMap ? myColorMap[element] : "grey";
      }
    }
    const myColorScheme = new MyColorScheme();
    const options = {
      colorScheme: myColorScheme,
      sequences,
    };
    return (
      <MSAViewer {...options} />
    )
  })
 .add('Custom Labels', function(){
    const fontSizes = ["6px", "8px", "10px", "12px", "14px", "16px", "18px", "20px"];
    const fontSize = select("Font size", createObject(fontSizes), "14px");
    const options = {
      sequences,
      labelComponent: ({sequence}) => {
        return (
          <div style={{height: 20, fontWeight: 'bold', fontSize}}>
            My: {sequence.name}
          </div>
        );
      }
    };
    return (
      <MSAViewer {...options} />
    )
  })
 .add('Custom Markers', function(){
    const fontSizes = ["6px", "8px", "10px", "12px", "14px", "16px", "18px"];
    const fontSize = select("Font size", createObject(fontSizes), "10px");
    const options = {
      sequences,
      markerComponent: ({index}) => {
        return (
          <div style={{
            width: 20,
            display: "inline-block",
            textAlign: "center",
            fontSize: fontSize,
            fontWeight: 'bold'}}>
            {index}
          </div>
        );
      }
    };
    return (
      <MSAViewer {...options} />
    )
  })
 .add('Custom styling', function(){
    const options = {
      sequences,
      labelStyle: {
        outline: text("Label style (outline)", "1px solid black"),
      },
      markerStyle: {
        outline: text("Marker style (outline)", "1px solid black"),
      },
      sequenceTextColor: text("Sequence color", "blue"),
     };
    return (
      <MSAViewer {...options} />
    )
  })
 .add('Custom scollbars', function(){
    const options = {
      sequences,
      sequenceScrollBarPositionX: select("ScrollBarPositionX", createObject(["top", "bottom"]), "top"),
      sequenceScrollBarPositionY: select("ScrollBarPositionY", createObject(["left", "right"]), "left"),
      sequenceOverflow: select("Overflow", createObject(["scroll", "auto", "hidden"]), "scroll"),
     };
    return (
      <MSAViewer {...options} />
    )
  })
 ;