我正在使用 rollup,并希望 babel 将单个node_modules包转译为 ES5(更准确地说:与 IE11 一起使用)。
通过以下设置,它会转译一些代码 \xe2\x80\x94 类 \xe2\x86\x92 函数,例如 \xe2\x80\x94 但它不会转译const为var\'s:
import resolve from \'@rollup/plugin-node-resolve\';\nimport commonjs from \'@rollup/plugin-commonjs\';\nimport babel from \'@rollup/plugin-babel\';\n\nexport default {\n input: \'src/index.js\',\n output: {\n file: \'dist/bundle.js\',\n format: \'umd\',\n },\n plugins: [\n resolve(),\n commonjs(),\n babel({\n babelHelpers: \'bundled\', \n exclude: \'node_modules\\/(?!(roughjs)\\/).*\', // \xe2\x86\x90 Here I try to ES5 transpile roughjs which lives in `node_modules/roughjs/bundled/rough.esm.js`\n }),\n ],\n};\nRun Code Online (Sandbox Code Playgroud)\n{\n "presets": [["@babel/env", { "modules": false }]]\n}\n …Run Code Online (Sandbox Code Playgroud) 如何在 r 中使用预定义的比例(如viridis from library("viridis")?
问题不是如何在ggplot 中使用它,而是如何构建一个函数,我可以将指定值域内的任意值输入到并从中检索相应的颜色字符串(rgb、hex 或任何其他输出格式)。
colorRamp并且colorRampPalette似乎只在给定颜色空间内的 2 种颜色之间进行插值。但是,例如,我将如何使用viridis解决这个问题?
编辑:
感谢@sconfluentus 的回答,我编写了以下函数来执行我想要的操作(没有安全检查):
library("viridis")
number_vector <- c(0.772, 1.235, 5.78, 8.890, 10.543, 14.702)
map_viridis <- function(vec, num) {
vector_expanded <-round(vec, 1) * 10 # expand to allow for decimal precision
vector_exp_range <- max(vector_expanded) - min(vector_expanded)
colour_vector <- viridis(vector_exp_range + 1) # get vector of colour values for all possible decimals between min and max value
value_to_colour <- colour_vector[num * 10 - …Run Code Online (Sandbox Code Playgroud) 我正在使用 D3 和 Canvas 可视化飞行路径。简而言之,我有每个航班的出发地和目的地以及机场坐标的数据。理想的最终状态是有一个单独的圆圈代表沿着从出发地到目的地的每条飞行路径移动的飞机。当前的状态是每个圆都沿着路径可视化,但是沿线删除前一个圆却不起作用,因为clearRect几乎不断地被调用。
当前状态:
理想状态(使用 SVG 实现):
从概念上讲,每个航班的 SVG 路径是使用 D3 的自定义插值在内存中生成的,path.getTotalLength()并path.getPointAtLength()沿着路径移动圆。
插值器返回任意给定过渡时间沿路径的点。一个简单的绘图函数获取这些点并绘制圆。
可视化开始于:
od_pairs.forEach(function(el, i) {
fly(el[0], el[1]); // for example: fly('LHR', 'JFK')
});
Run Code Online (Sandbox Code Playgroud)
该fly()函数在内存中创建 SVG 路径,并在内存中创建圆(“平面”)的 D3 选择。
function fly(origin, destination) {
var pathElement = document.createElementNS(d3.namespaces.svg, 'path');
var routeInMemory = d3.select(pathElement)
.datum({
type: 'LineString',
coordinates: [airportMap[origin], airportMap[destination]]
})
.attr('d', path);
var plane = custom.append('plane');
transition(plane, routeInMemory.node());
}
Run Code Online (Sandbox Code Playgroud)
平面通过delta()函数中的自定义插值器沿着路径进行转换:
function transition(plane, route) {
var l …Run Code Online (Sandbox Code Playgroud)