Skip to content
This repository has been archived by the owner on Oct 26, 2021. It is now read-only.

Added an alphabetical operators presentation and a switch to select one #34

Open
wants to merge 1 commit into
base: master
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ DONE Fix marble hover and dragging styles for Firefox
DONE Fix affordance animation stuck for combineLatest
>>> v1.4.0

DONE Added an alphabetical operators presentation and a switch to select one

TODO Fix visual semantics of concat diagram
>>>

Expand Down
26,934 changes: 26,918 additions & 16 deletions dist/js/app.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@cycle/core": "1.0.x",
"@cycle/dom": "3.1.x",
"immutable": "^3.7.2",
"lodash": "4.6.1",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only sortBy is imported from the lib.

"rxtween": "0.3.3"
},
"devDependencies": {
Expand Down
9 changes: 2 additions & 7 deletions src/components/operators-menu-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@ import {Rx} from '@cycle/core';
import {h} from '@cycle/dom';
import Colors from 'rxmarbles/styles/colors';
import Dimens from 'rxmarbles/styles/dimens';
import {mergeStyles} from 'rxmarbles/styles/utils';
import {mergeStyles, makeIsHighlighted$} from 'rxmarbles/styles/utils';
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracted the makeIsHighlighted method. (Also used for the switch.)


function operatorsMenuLink({DOM, props}) {
let startHighlight$ = DOM.get('.link', 'mouseenter').map(() => 1);
let stopHighlight$ = DOM.get('.link', 'mouseleave').map(() => 1);
let href$ = props.get('href');
let content$ = props.get('content').startWith('');
let isHighlighted$ = Rx.Observable.merge(
startHighlight$.map(() => true),
stopHighlight$.map(() => false)
).startWith(false);
let isHighlighted$ = makeIsHighlighted$(DOM, '.link');
let highlightingArrow = h('span', {
style: {
display: 'inline-block',
Expand Down
85 changes: 47 additions & 38 deletions src/components/operators-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,7 @@ import {h} from '@cycle/dom';
import Colors from 'rxmarbles/styles/colors';
import Dimens from 'rxmarbles/styles/dimens';
import Examples from 'rxmarbles/data/examples';
import {mergeStyles} from 'rxmarbles/styles/utils';

/**
* Returns a hashmap of category headers to lists of examples in that category.
*/
function organizeExamplesByCategory(examples) {
let categoryMap = {};
for (let key in examples) {
if (!examples.hasOwnProperty(key)) continue;
let value = examples[key];
value.key = key;
if (categoryMap.hasOwnProperty(value.category)) {
categoryMap[value.category].push(value);
} else {
categoryMap[value.category] = [value];
}
}
return categoryMap;
}
import {mergeStyles, makeIsHighlighted$} from 'rxmarbles/styles/utils';

const operatorsMenuCategoryStyle = {
textTransform: 'uppercase',
Expand Down Expand Up @@ -64,7 +46,7 @@ function renderExampleCategory(categoryName, isFirstCategory) {
);
}

function renderMenuContent(categoryMap) {
function renderMenuByCategory(categoryMap) {
let listItems = [];
let isFirstCategory = true;
for (let categoryName in categoryMap) {
Expand All @@ -78,26 +60,53 @@ function renderMenuContent(categoryMap) {
return listItems;
}

function operatorsMenuComponent() {
let categoryMap$ = Rx.Observable.just(organizeExamplesByCategory(Examples));
function renderSwitchItem(key, label, isActive, isHighlighted) {
return h('div.switch.' + key, {
style: {
cursor: 'pointer',
float: 'left',
'padding-right': '10px',
'box-sizing': 'border-box',
'text-align': 'left',
color: isHighlighted ? Colors.greyDark : Colors.grey,
'text-decoration': 'underline'
}}, label);
}

return {
DOM: categoryMap$.map(categoryMap =>
h('div',
function renderMenu(byCategory, byCategoryIsHighlighted, byAlphabetIsHighlighted) {
let menuItemsByCategory = renderMenuByCategory(Examples.byCategory);
let menuItemsByAlphabet = renderExampleItems(Examples.byAlphabet);
return h('div', {}, [
h('div',
{style: {
paddingRight: '36px',
boxSizing: 'border-box',
// 100px is the estimated header page row height
height: 'calc(100vh - 100px)'}},
[h('div', {},
[ renderSwitchItem('byAlphabet', 'by Name', !byCategory, byAlphabetIsHighlighted),
renderSwitchItem('byCategory', 'by Category', byCategory, byCategoryIsHighlighted)]),
h('div', {style: {clear: 'both'}}),
h('ul',
{style: {
paddingRight: '36px',
boxSizing: 'border-box',
// 100px is the estimated header page row height
height: 'calc(100vh - 100px)'}},
[h('ul',
{style: {
margin: '0',
padding: '0',
listStyleType: 'none',
overflowY: 'scroll',
height: '100%'}},
renderMenuContent(categoryMap))])
)
margin: '0',
'margin-top': Dimens.spaceSmall,
padding: '0',
listStyleType: 'none',
overflowY: 'scroll',
height: '100%'}}, byCategory ? menuItemsByCategory : menuItemsByAlphabet)])
]);
}

function operatorsMenuComponent({DOM, props}) {

let switchMouseDown$ = DOM.get('.switch', 'mousedown');
let showItemsByCategory$ = switchMouseDown$.map((ev) => ev.currentTarget.className.indexOf('byCategory') >= 0).startWith(true);
let byCategoryIsHighlighted$ = makeIsHighlighted$(DOM, '.byCategory');
let byAlphabetIsHighlighted$ = makeIsHighlighted$(DOM, '.byAlphabet');

return {
DOM: Rx.Observable.combineLatest(showItemsByCategory$, byCategoryIsHighlighted$, byAlphabetIsHighlighted$, renderMenu)
};
}

Expand Down
36 changes: 35 additions & 1 deletion src/data/examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var filterExamples = require('rxmarbles/data/filter-examples');
var mathExamples = require('rxmarbles/data/math-examples');
var booleanExamples = require('rxmarbles/data/boolean-examples');
var conditionalExamples = require('rxmarbles/data/conditional-examples');
var sortBy = require('lodash/sortBy');

function merge() {
var args = (1 <= arguments.length) ? Array.prototype.slice.call(arguments) : [];
Expand All @@ -29,11 +30,44 @@ function applyCategory(examples, categoryName) {
return examples;
};

module.exports = merge(
/**
* Returns a hashmap of category headers to lists of examples in that category.
*/
function organizeExamplesByCategory(examples) {
let categoryMap = {};
for (let key in examples) {
if (!examples.hasOwnProperty(key)) continue;
let value = examples[key];
value.key = key;
if (categoryMap.hasOwnProperty(value.category)) {
categoryMap[value.category].push(value);
} else {
categoryMap[value.category] = [value];
}
}
return categoryMap;
}

function organizeExamplesByAlphabet(examples) {
let array = [];
for (let key in examples) {
if (!examples.hasOwnProperty(key)) continue;
let value = examples[key];
array.push(value);
}
return sortBy(array, 'key');
}

let examples = merge(
applyCategory(transformExamples, "Transforming Operators"),
applyCategory(combineExamples, "Combining Operators"),
applyCategory(filterExamples, "Filtering Operators"),
applyCategory(mathExamples, "Mathematical Operators"),
applyCategory(booleanExamples, "Boolean Operators"),
applyCategory(conditionalExamples, "Conditional Operators")
);

examples.byCategory = organizeExamplesByCategory(examples);
examples.byAlphabet = organizeExamplesByAlphabet(examples);

module.exports = examples;
12 changes: 12 additions & 0 deletions src/styles/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Immutable from 'immutable';
import {h, svg} from '@cycle/dom';
import {Rx} from '@cycle/core';

let isTruthy = x => !!x;

Expand Down Expand Up @@ -31,6 +32,16 @@ function renderSvgDropshadow() {
]);
}

function makeIsHighlighted$(DOM, cssSelector) {
let startHighlight$ = DOM.get(cssSelector, 'mouseenter').map(() => 1);
let stopHighlight$ = DOM.get(cssSelector, 'mouseleave').map(() => 1);

return Rx.Observable.merge(
startHighlight$.map(() => true),
stopHighlight$.map(() => false)
).startWith(false);
}

const marbleElevation1Style = {
filter: 'url(#' + DROPSHADOW_FILTER_ID + ')'
};
Expand Down Expand Up @@ -80,6 +91,7 @@ const textUnselectable = {

export default {
mergeStyles,
makeIsHighlighted$,
elevation1Style,
elevation2Style,
elevation2Before,
Expand Down