Comparing version 0.2.0 to 0.3.0
{ | ||
"name": "mapd3", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "A fast chart library for the fastest DB", | ||
@@ -5,0 +5,0 @@ "main": "dist/mapd3.js", |
import {dispatch} from "d3-dispatch" | ||
import {exclusiveToggle} from "./interactors" | ||
import {exclusiveToggle, toggleOnOff} from "./interactors" | ||
@@ -14,4 +14,5 @@ export default function Binning (_chart) { | ||
}, | ||
width: 800, | ||
height: 500 | ||
toggle: ["auto"], | ||
exclusiveToggle: ["1y", "1q", "1mo", "1w"], | ||
label: "BIN:" | ||
} | ||
@@ -21,5 +22,3 @@ | ||
chart: _chart, | ||
svg: null, | ||
chartWidth: null, | ||
chartHeight: null | ||
svg: null | ||
} | ||
@@ -31,4 +30,2 @@ | ||
const data = ["auto", "1y", "1q", "1mo", "1w"] | ||
// events | ||
@@ -46,5 +43,2 @@ const dispatcher = dispatch("change") | ||
cache.chartWidth = config.width - config.margin.left - config.margin.right | ||
cache.chartHeight = config.height - config.margin.top - config.margin.bottom | ||
if (!cache.svg) { | ||
@@ -54,2 +48,7 @@ cache.svg = chartCache.svg.append("g") | ||
.append("text") | ||
cache.svg.append("tspan") | ||
.text(config.label) | ||
.attr("y", "1em") | ||
.attr("class", "item") | ||
} | ||
@@ -59,14 +58,31 @@ | ||
const texts = cache.svg.selectAll(".item") | ||
.data(["BIN:"].concat(data)) | ||
texts.enter().append("tspan").classed("item", true) | ||
.attr("dx", "0.5em") | ||
.attr("dominant-baseline", "hanging") | ||
.on("click.dispatch", (d) => { | ||
dispatcher.call("change", this, d) | ||
const items = cache.svg.selectAll(".toggleOnOff") | ||
.data(config.toggle) | ||
items.enter().append("tspan") | ||
.attr("class", (d) => `item ${d} toggleOnOff`) | ||
.attr("dx", "0.8em") | ||
.attr("y", "1em") | ||
.on("click.select", toggleOnOff(".binning-group .item.toggleOnOff")) | ||
.on("click.dispatch", function click (d) { | ||
const isSelected = this.classList.contains("selected") | ||
dispatcher.call("change", this, d, {isSelected}) | ||
}) | ||
.on("click.select", exclusiveToggle(".binning-group tspan.item")) | ||
.merge(texts) | ||
.merge(items) | ||
.text((d) => d) | ||
texts.exit().remove() | ||
items.exit().remove() | ||
const itemsExclusive = cache.svg.selectAll(".toggleExclusive") | ||
.data(config.exclusiveToggle) | ||
itemsExclusive.enter().append("tspan") | ||
.attr("class", (d) => `item ${d} toggleExclusive`) | ||
.attr("dx", "0.8em") | ||
.attr("y", "1em") | ||
.on("click.select", exclusiveToggle(".binning-group .item.toggleExclusive")) | ||
.on("click.dispatch", function click (d) { | ||
const isSelected = this.classList.contains("selected") | ||
dispatcher.call("change", this, d, {isSelected}) | ||
}) | ||
.merge(itemsExclusive) | ||
.text((d) => d) | ||
itemsExclusive.exit().remove() | ||
} | ||
@@ -73,0 +89,0 @@ |
@@ -12,6 +12,11 @@ import {select} from "d3-selection" | ||
export function exclusiveToggle (selector) { | ||
const toggleOffIsEnabled = false | ||
const toggleMultipleIsEnabled = false | ||
export function toggleOnOff (selector) { | ||
return exclusiveToggle(selector, { | ||
toggleOffIsEnabled: true, | ||
toggleMultipleIsEnabled: false | ||
}) | ||
} | ||
export function exclusiveToggle (selector, options = {toggleOffIsEnabled: false, toggleMultipleIsEnabled: false}) { | ||
return function toggle () { | ||
@@ -30,5 +35,5 @@ /* eslint-disable consistent-this */ | ||
if (hasJustBeenClicked) { | ||
shouldBeSelected = toggleOffIsEnabled ? !isSelected : true | ||
shouldBeSelected = options.toggleOffIsEnabled ? !isSelected : true | ||
} else { | ||
shouldBeSelected = toggleMultipleIsEnabled ? isSelected : false | ||
shouldBeSelected = options.toggleMultipleIsEnabled ? isSelected : false | ||
} | ||
@@ -35,0 +40,0 @@ |
@@ -259,3 +259,2 @@ import {extent, sum, bisector} from "d3-array" | ||
.unknown(config.defaultColor) | ||
console.log(111, cache.colorScale.range(), cache.colorScale.domain(), ids, config.colorSchema) | ||
} | ||
@@ -262,0 +261,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1032459
55
4678